Fix utils/changelog for merge commits without subject

There is curently a merge commit without a subject, which leads into a
traceback in the changelog script.

The merge information provides the commit hash, which is now used to get
the subject later on using the generated commits hash.
This commit is contained in:
Thomas Woerner
2020-11-09 12:41:01 +01:00
parent c62f003ebf
commit 2dbbcce517

View File

@@ -67,24 +67,40 @@ authors = {}
lines = process.stdout.decode("utf-8").split("\n") lines = process.stdout.decode("utf-8").split("\n")
class Ref:
def __init__(self, commit):
self.commit = commit
def store(commits, prs, authors, commit, author, msg):
def store(commits, prs, authors, commit, author, merge, msg):
if commit is not None: if commit is not None:
if msg[0].startswith("Merge pull request #"): if msg[0].startswith("Merge pull request #"):
pr = int(msg[0].split()[3][1:]) pr = int(msg[0].split()[3][1:])
prs[pr] = msg[1].strip() if len(msg) > 1:
prs[pr] = msg[1].strip()
else:
prs[pr] = Ref(merge)
else: else:
commits[commit] = msg[0].strip() commits[commit] = msg[0].strip()
authors.setdefault(author, []).append(commit) authors.setdefault(author, []).append(commit)
def get_commit(commits, commit):
_commits = [value for key, value in commits.items()
if key.startswith(merge)]
if len(_commits) == 1:
return _commits[0]
return commit
commit = None commit = None
author = None author = None
merge = None
msg = None msg = None
for line in lines: for line in lines:
line = line.rstrip() line = line.rstrip()
if line.startswith("commit "): if line.startswith("commit "):
store(commits, prs, authors, commit, author, msg) store(commits, prs, authors, commit, author, merge, msg)
author = None author = None
msg = [] msg = []
commit = line[7:] commit = line[7:]
@@ -95,13 +111,15 @@ for line in lines:
key, value = line.split(":", 1) key, value = line.split(":", 1)
if key == "Author": if key == "Author":
author = value.split("<")[0].strip() author = value.split("<")[0].strip()
# Ignore Merge, Date, .. elif key == "Merge":
merge = value.split()[1].strip()
# Ignore Date, ..
except ValueError: except ValueError:
pass pass
# Add final commit # Add final commit
if commit: if commit:
store(commits, prs, authors, commit, author, msg) store(commits, prs, authors, commit, author, merge, msg)
s = "Changes since %s" % version s = "Changes since %s" % version
print("%s" % s) print("%s" % s)
@@ -110,7 +128,11 @@ print()
prs_sorted = sorted(prs.keys(), reverse=True) prs_sorted = sorted(prs.keys(), reverse=True)
for pr in prs_sorted: for pr in prs_sorted:
print(" - %s (#%d)" % (prs[pr], pr)) if isinstance(prs[pr], Ref):
msg = get_commit(commits, prs[pr].commit)
else:
msg = prs[pr]
print(" - %s (#%d)" % (msg, pr))
print() print()
s = "Detailed changelog since %s by author" % version s = "Detailed changelog since %s by author" % version