utils: checkstyle.py: Move diff parsing to Commit class
To avoid duplicating diff parsing in commit checkers, move it to the Commit class. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
fc91951250
commit
ba3278a749
1 changed files with 7 additions and 6 deletions
|
@ -236,9 +236,10 @@ class Commit:
|
||||||
return self.__title
|
return self.__title
|
||||||
|
|
||||||
def get_diff(self, top_level, filename):
|
def get_diff(self, top_level, filename):
|
||||||
return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),
|
diff = subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),
|
||||||
'--', '%s/%s' % (top_level, filename)],
|
'--', '%s/%s' % (top_level, filename)],
|
||||||
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||||
|
return parse_diff(diff.splitlines(True))
|
||||||
|
|
||||||
def get_file(self, filename):
|
def get_file(self, filename):
|
||||||
return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],
|
return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)],
|
||||||
|
@ -256,9 +257,10 @@ class StagedChanges(Commit):
|
||||||
self.__files = [CommitFile(f) for f in ret.splitlines()]
|
self.__files = [CommitFile(f) for f in ret.splitlines()]
|
||||||
|
|
||||||
def get_diff(self, top_level, filename):
|
def get_diff(self, top_level, filename):
|
||||||
return subprocess.run(['git', 'diff', '--staged', '--',
|
diff = subprocess.run(['git', 'diff', '--staged', '--',
|
||||||
'%s/%s' % (top_level, filename)],
|
'%s/%s' % (top_level, filename)],
|
||||||
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||||
|
return parse_diff(diff.splitlines(True))
|
||||||
|
|
||||||
|
|
||||||
class Amendment(StagedChanges):
|
class Amendment(StagedChanges):
|
||||||
|
@ -276,9 +278,10 @@ class Amendment(StagedChanges):
|
||||||
self.__files = [CommitFile(f) for f in ret.splitlines()]
|
self.__files = [CommitFile(f) for f in ret.splitlines()]
|
||||||
|
|
||||||
def get_diff(self, top_level, filename):
|
def get_diff(self, top_level, filename):
|
||||||
return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',
|
diff = subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',
|
||||||
'%s/%s' % (top_level, filename)],
|
'%s/%s' % (top_level, filename)],
|
||||||
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||||
|
return parse_diff(diff.splitlines(True))
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -657,9 +660,7 @@ class StripTrailingSpaceFormatter(Formatter):
|
||||||
|
|
||||||
def check_file(top_level, commit, filename):
|
def check_file(top_level, commit, filename):
|
||||||
# Extract the line numbers touched by the commit.
|
# Extract the line numbers touched by the commit.
|
||||||
diff = commit.get_diff(top_level, filename)
|
commit_diff = commit.get_diff(top_level, filename)
|
||||||
diff = diff.splitlines(True)
|
|
||||||
commit_diff = parse_diff(diff)
|
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
for hunk in commit_diff:
|
for hunk in commit_diff:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue