aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-12-18 12:01:18 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-18 17:21:42 +0000
commitd2ded55168d86e95710ea6b923829745b005e531 (patch)
tree00f04445847cb652d7e6a3946a727364a91deab3 /experimental
parenta2192a76b55e465a8a97badd473a24d7daeac7a2 (diff)
experimental/tools/gerrit-change-id-to-number
Change-Id: I10a46d2d9c8a710f6816f697e48366366078e4f0 Reviewed-on: https://skia-review.googlesource.com/86640 Reviewed-by: Hal Canary <halcanary@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/documentation/gerrit.md14
-rwxr-xr-xexperimental/tools/gerrit-change-id-to-number42
2 files changed, 56 insertions, 0 deletions
diff --git a/experimental/documentation/gerrit.md b/experimental/documentation/gerrit.md
index 1f41391311..24cf0b6b7e 100644
--- a/experimental/documentation/gerrit.md
+++ b/experimental/documentation/gerrit.md
@@ -94,6 +94,16 @@ Updating a Change
The title of this patch set will be "this is the patch set comment message".
+Using `git cl try`
+------------------
+
+On your current branch, after uploading to gerrit:
+
+ git cl issue $(experimental/tools/gerrit-change-id-to-number @)
+
+Now `git cl try` and `bin/try` will work correctly.
+
+
Scripting
---------
@@ -105,6 +115,10 @@ The following alias amends the head without editing the commit message:
git config alias.amend-head 'commit --all --amend --reuse-message=@'
+Set the CL issue numnber:
+
+ git config alias.setcl '!git-cl issue $(experimental/tools/gerrit-change-id-to-number @)'
+
The following shell script will squash all commits on the current branch,
assuming that the branch has an upstream topic branch.
diff --git a/experimental/tools/gerrit-change-id-to-number b/experimental/tools/gerrit-change-id-to-number
new file mode 100755
index 0000000000..ddc9045edb
--- /dev/null
+++ b/experimental/tools/gerrit-change-id-to-number
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+# Copyright 2017 Google Inc.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import httplib
+import json
+import re
+import subprocess
+import sys
+
+def retrieve_changeid(commit_or_branch):
+ b = subprocess.check_output(['git', 'log', '-1', '--format=%B', commit_or_branch])
+ r = re.compile(r'^Change-Id: (.*)$')
+ for l in b.split('\n'):
+ m = r.match(l)
+ if m:
+ return m.group(1)
+ return None
+
+def gerrit_change_id_to_number(cid):
+ conn = httplib.HTTPSConnection('skia-review.googlesource.com')
+ conn.request('GET', '/changes/?q=change:%s' % cid)
+ r = conn.getresponse()
+ assert(r.status == 200)
+ x = r.read()
+ i = 0
+ while i < len(x) and x[i] != '[':
+ i += 1
+ print json.loads(x[i:])[0]['_number']
+
+if __name__ == '__main__':
+ try:
+ if len(sys.argv) == 2 and len(sys.argv[1]) == 41 and sys.argv[1][0] == 'I':
+ gerrit_change_id_to_number(sys.argv[1])
+ else:
+ changeid = retrieve_changeid(sys.argv[1] if len(sys.argv) == 2 else 'HEAD')
+ if changeid is None:
+ exit(2)
+ gerrit_change_id_to_number(changeid)
+ except:
+ exit(1)