Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(881)

Unified Diff: git_footers.py

Issue 1758943002: Add Gerrit's Change-Id handling to git_footers. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/git_footers_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_footers.py
diff --git a/git_footers.py b/git_footers.py
index 3e3ea827ba5cb771802478bcb7121d203cd4f284..1d4d4dd84099e5dcc95e78eb0870c10af3c437ae 100755
--- a/git_footers.py
+++ b/git_footers.py
@@ -62,6 +62,44 @@ def get_footer_svn_id(branch=None):
return svn_id
+def get_footer_change_id(message):
+ """Returns a list of Gerrit's ChangeId from given commit message."""
+ return parse_footers(message).get(normalize_name('Change-Id'), [])
+
+
+def add_footer_change_id(message, change_id):
+ """Returns message with Change-ID footer in it.
+
+ Assumes that Change-Id is not yet in footers, which is then
+ inserted after any of these footers: Bug|Issue|Test|Feature.
+ """
+ assert 0 == len(get_footer_change_id(message))
+ change_id_line = 'Change-Id: %s' % change_id
+ # This code does the same as parse_footers, but keeps track of line
+ # numbers so that ChangeId is inserted in the right place.
+ lines = message.splitlines()
+ footer_lines = []
+ for line in reversed(lines):
+ if line == '' or line.isspace():
+ break
+ footer_lines.append(line)
+ # footers order is from end to start of the message.
+ footers = map(parse_footer, footer_lines)
+ if not all(footers):
+ lines.append('')
+ lines.append(change_id_line)
+ else:
+ after = set(map(normalize_name, ['Bug', 'Issue', 'Test', 'Feature']))
+ for i, (key, _) in enumerate(footers):
+ if normalize_name(key) in after:
+ insert_at = len(lines) - i
+ break
+ else:
+ insert_at = len(lines) - len(footers)
+ lines.insert(insert_at, change_id_line)
+ return '\n'.join(lines)
+
+
def get_unique(footers, key):
key = normalize_name(key)
values = footers[key]
« no previous file with comments | « no previous file | tests/git_footers_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698