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

Unified Diff: git_cl.py

Issue 1757133002: git cl: add python implementation of Change-Id generation. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@G050
Patch Set: fix-tests 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_cl_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index ef974d50f33f07faf2a5e7cb1049cc5813649d4c..2025835b6a21915b733293ad33804deb67ca0602 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2148,6 +2148,36 @@ def AddChangeIdToCommitMessage(options, args):
print >> sys.stderr, 'ERROR: Gerrit commit-msg hook not available.'
+def GenerateGerritChangeId(message):
+ """Returns Ixxxxxx...xxx change id.
+
+ Works the same way as
+ https://gerrit-review.googlesource.com/tools/hooks/commit-msg
+ but can be called on demand on all platforms.
+
+ The basic idea is to generate git hash of a state of the tree, original commit
+ message, author/committer info and timestamps.
+ """
+ lines = []
+ tree_hash = RunGitSilent(['write-tree'])
+ lines.append('tree %s' % tree_hash.strip())
+ code, parent = RunGitWithCode(['rev-parse', 'HEAD~0'], suppress_stderr=False)
+ if code == 0:
+ lines.append('parent %s' % parent.strip())
+ author = RunGitSilent(['var', 'GIT_AUTHOR_IDENT'])
+ lines.append('author %s' % author.strip())
+ committer = RunGitSilent(['var', 'GIT_COMMITTER_IDENT'])
+ lines.append('committer %s' % committer.strip())
+ lines.append('')
+ # Note: Gerrit's commit-hook actually cleans message of some lines and
+ # whitespace. This code is not doing this, but it clearly won't decrease
+ # entropy.
+ lines.append(message)
+ change_hash = RunCommand(['git', 'hash-object', '-t', 'commit', '--stdin'],
+ stdin='\n'.join(lines))
+ return 'I%s' % change_hash.strip()
+
+
def GerritUpload(options, args, cl, change):
"""upload the current branch to gerrit."""
# We assume the remote called "origin" is the one we want.
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698