build: improve patch filename remembering (#23070)

This commit is contained in:
Jeremy Apthorp 2020-04-13 09:46:15 -07:00 committed by GitHub
parent 5154e8ff75
commit 905504852e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,11 +8,13 @@ def read_patch(patch_dir, patch_filename):
"""Read a patch from |patch_dir/filename| and amend the commit message with """Read a patch from |patch_dir/filename| and amend the commit message with
metadata about the patch file it came from.""" metadata about the patch file it came from."""
ret = [] ret = []
added_filename_line = False
patch_path = os.path.join(patch_dir, patch_filename) patch_path = os.path.join(patch_dir, patch_filename)
with codecs.open(patch_path, encoding='utf-8') as f: with codecs.open(patch_path, encoding='utf-8') as f:
for l in f.readlines(): for l in f.readlines():
if l.startswith('diff -'): if not added_filename_line and (l.startswith('diff -') or l.startswith('---')):
ret.append('Patch-Filename: {}\n'.format(patch_filename)) ret.append('Patch-Filename: {}\n'.format(patch_filename))
added_filename_line = True
ret.append(l) ret.append(l)
return ''.join(ret) return ''.join(ret)