utils: checkstyle.py: Add author property to Commit class
Extend the Commit class with an author property, retrieved from the commit. It will be used to extend checkers. While at it, drop the unneeded .strip() call when retrieving the title for amendment commits. The call got carried over from code that initially needed it to strip the new line character, but that need disappeard with usage of .splitlines(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
ff0613a6e5
commit
fd130ef21b
1 changed files with 13 additions and 6 deletions
|
@ -212,11 +212,12 @@ class CommitFile:
|
||||||
class Commit:
|
class Commit:
|
||||||
def __init__(self, commit):
|
def __init__(self, commit):
|
||||||
self.commit = commit
|
self.commit = commit
|
||||||
|
self._author = None
|
||||||
self._trailers = []
|
self._trailers = []
|
||||||
self._parse()
|
self._parse()
|
||||||
|
|
||||||
def _parse_trailers(self, lines):
|
def _parse_trailers(self, lines):
|
||||||
for index in range(1, len(lines)):
|
for index in range(2, len(lines)):
|
||||||
line = lines[index]
|
line = lines[index]
|
||||||
if not line:
|
if not line:
|
||||||
break
|
break
|
||||||
|
@ -227,12 +228,13 @@ class Commit:
|
||||||
|
|
||||||
def _parse(self):
|
def _parse(self):
|
||||||
# Get the commit title and list of files.
|
# Get the commit title and list of files.
|
||||||
ret = subprocess.run(['git', 'show', '--format=%s%n%(trailers:only,unfold)', '--name-status',
|
ret = subprocess.run(['git', 'show', '--format=%an <%ae>%n%s%n%(trailers:only,unfold)',
|
||||||
self.commit],
|
'--name-status', self.commit],
|
||||||
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||||
lines = ret.splitlines()
|
lines = ret.splitlines()
|
||||||
|
|
||||||
self._title = lines[0]
|
self._author = lines[0]
|
||||||
|
self._title = lines[1]
|
||||||
|
|
||||||
index = self._parse_trailers(lines)
|
index = self._parse_trailers(lines)
|
||||||
self._files = [CommitFile(f) for f in lines[index:] if f]
|
self._files = [CommitFile(f) for f in lines[index:] if f]
|
||||||
|
@ -240,6 +242,10 @@ class Commit:
|
||||||
def files(self, filter='AMR'):
|
def files(self, filter='AMR'):
|
||||||
return [f.filename for f in self._files if f.status in filter]
|
return [f.filename for f in self._files if f.status in filter]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def author(self):
|
||||||
|
return self._author
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
return self._title
|
return self._title
|
||||||
|
@ -282,12 +288,13 @@ class Amendment(Commit):
|
||||||
|
|
||||||
def _parse(self):
|
def _parse(self):
|
||||||
# Create a title using HEAD commit and parse the trailers.
|
# Create a title using HEAD commit and parse the trailers.
|
||||||
ret = subprocess.run(['git', 'show', '--format=%H %s%n%(trailers:only,unfold)',
|
ret = subprocess.run(['git', 'show', '--format=%an <%ae>%n%H %s%n%(trailers:only,unfold)',
|
||||||
'--no-patch'],
|
'--no-patch'],
|
||||||
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||||
lines = ret.splitlines()
|
lines = ret.splitlines()
|
||||||
|
|
||||||
self._title = 'Amendment of ' + lines[0].strip()
|
self._author = lines[0]
|
||||||
|
self._title = 'Amendment of ' + lines[1]
|
||||||
|
|
||||||
self._parse_trailers(lines)
|
self._parse_trailers(lines)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue