From 700cfb166e902d176bc9884ee8cc1027c78d3aa0 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Sun, 4 Jun 2023 10:26:03 +0200 Subject: [PATCH] fix-header: improve aliases matching --- scripts/tools/fix-header.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/scripts/tools/fix-header.py b/scripts/tools/fix-header.py index 7b8e12ebc..bd640d8f2 100755 --- a/scripts/tools/fix-header.py +++ b/scripts/tools/fix-header.py @@ -64,21 +64,31 @@ def ranges(i): def extract_authors_from_gitlog(path): 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 + aliased = set() if result.returncode == 0: - pattern = re.compile(r'^(\d+) (.*)$') + pattern = re.compile(r'^(?P\d+)¤(?P[^¤]*)¤(?P.*)$') for line in result.stdout.decode('utf-8').split("\n"): - match = pattern.search(line) - if match: - year = int(match.group(1)) - author = match.group(2) - author = ALIASES.get(author, author) + matched = pattern.search(line) + if matched: + year = int(matched.group('year')) + author = matched.group('name') + 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 year not in authors[author]: authors[author].append(year) else: authors[author] = [year] + for a in aliased: + logging.debug(f"Alias found: {a}") + return authors