From 13dc6342822bd4158f8dc4ed30bb2f88af2de356 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 26 Mar 2020 22:46:47 +0100 Subject: [PATCH] Simplify the matching of the last line Signed-off-by: Gilles Peskine --- scripts/assemble_changelog.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index ebb056e4a..6eeea6124 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -261,12 +261,14 @@ class EntryFileSortKey: Return None if the file was never checked into git. """ hashes = subprocess.check_output(['git', 'log', '--format=%H', '--', filename]) - if not hashes: - # The file was never checked in. + m = re.search(b'(.+)$', hashes) + if not m: + # The git output is empty. This means that the file was + # never checked in. return None - hashes = hashes.rstrip(b'\n') - last_hash = hashes[hashes.rfind(b'\n')+1:] - return last_hash + # The last commit in the log is the oldest one, which is when the + # file was created. + return m.group(0) @staticmethod def list_merges(some_hash, target, *options):