fromupstream: replace findall() to search()
- findall() generates a list which is relatively expensive.
- 1 CL expects to consist only 1 'Change-Id'.
=> Uses search() to find the first match.
BUG=None
TEST=fromupstream.py -r -d pw://11123203
Change-Id: Ie6d845448f4911ea84d2b03b9f31076596f369a3
Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1780427
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/contrib/fromupstream.py b/contrib/fromupstream.py
index 7c570de..76d95e3 100755
--- a/contrib/fromupstream.py
+++ b/contrib/fromupstream.py
@@ -176,9 +176,14 @@
old_commit_message = subprocess.check_output(
['git', 'show', '-s', '--format=%B', 'HEAD']
).strip('\n')
- changeid = re.findall('Change-Id: (.*)$', old_commit_message, re.MULTILINE)
- if changeid:
- args['changeid'] = changeid[0]
+
+ # It is possible that multiple Change-Ids are in the commit message
+ # (due to cherry picking). We only want to pull out the first one.
+ changeid_match = re.search('^Change-Id: (.*)$',
+ old_commit_message, re.MULTILINE)
+ if changeid_match:
+ args['changeid'] = changeid_match.group(1)
+
if args['bug'] == parser.get_default('bug') and \
re.findall('BUG=(.*)$', old_commit_message, re.MULTILINE):
args['bug'] = '\nBUG='.join(re.findall('BUG=(.*)$',