mirror of
https://github.com/fergalmoran/picard.git
synced 2025-12-26 11:18:20 +00:00
fix-header: improve aliases matching
This commit is contained in:
@@ -64,21 +64,31 @@ def ranges(i):
|
|||||||
|
|
||||||
def extract_authors_from_gitlog(path):
|
def extract_authors_from_gitlog(path):
|
||||||
authors = {}
|
authors = {}
|
||||||
cmd = ['git', 'log', r'--pretty=format:%ad %aN', r'--date=format:%Y', r'--', path]
|
cmd = ['git', 'log', r'--pretty=format:%ad¤%aN¤%aE', r'--date=format:%Y', r'--', path]
|
||||||
result = subprocess.run(cmd, stdout=subprocess.PIPE, timeout=30) # nosec: B603
|
result = subprocess.run(cmd, stdout=subprocess.PIPE, timeout=30) # nosec: B603
|
||||||
|
aliased = set()
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
pattern = re.compile(r'^(\d+) (.*)$')
|
pattern = re.compile(r'^(?P<year>\d+)¤(?P<name>[^¤]*)¤(?P<email>.*)$')
|
||||||
for line in result.stdout.decode('utf-8').split("\n"):
|
for line in result.stdout.decode('utf-8').split("\n"):
|
||||||
match = pattern.search(line)
|
matched = pattern.search(line)
|
||||||
if match:
|
if matched:
|
||||||
year = int(match.group(1))
|
year = int(matched.group('year'))
|
||||||
author = match.group(2)
|
author = matched.group('name')
|
||||||
author = ALIASES.get(author, author)
|
email = matched.group('email')
|
||||||
|
for c in (f"{author} <{email}>", email, author):
|
||||||
|
if c in ALIASES:
|
||||||
|
alias = ALIASES[c]
|
||||||
|
aliased.add(f"{author} <{email}> -> {alias}")
|
||||||
|
author = alias
|
||||||
|
break
|
||||||
if author in authors:
|
if author in authors:
|
||||||
if year not in authors[author]:
|
if year not in authors[author]:
|
||||||
authors[author].append(year)
|
authors[author].append(year)
|
||||||
else:
|
else:
|
||||||
authors[author] = [year]
|
authors[author] = [year]
|
||||||
|
for a in aliased:
|
||||||
|
logging.debug(f"Alias found: {a}")
|
||||||
|
|
||||||
return authors
|
return authors
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user