Преглед изворни кода

Add new tool, git find-releases

Finds the release(s) for a given change.

Relies on using "git cherry-pick -x" per
http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-drover.html
so that the merge commit message contains the original commit.

Example:

d:\src\cr3\src>git show -s 53cc88da9a258bc4a34c4bff50025ee044c2e64d
commit 53cc88da9a258bc4a34c4bff50025ee044c2e64d
Author: grt <grt@chromium.org>
Date:   Tue Jun 2 10:33:09 2015 -0700

    Beacons for tracking default browser status.

    BUG=488247
    R=gab@chromium.org,wfh@chromium.org

    Review URL: https://codereview.chromium.org/1146843003

    Cr-Commit-Position: refs/heads/master@{#332423}


"Now, where did that ship?"


d:\src\cr3\src>git find-releases 53cc88da9a258bc4a34c4bff50025ee044c2e64d
commit 53cc88da9a258bc4a34c4bff50025ee044c2e64d was:
  initially in 45.0.2421.0
  merged to 43.0.2357.126 (as 8a5ccc0e0ad6b2237b2fcfffcb0ab24fe97bc77b)
  merged to 44.0.2403.39 (as d5d165943a88e51a64fd9e2fbcc781e4aaee270f)

Review URL: https://codereview.chromium.org/1332473003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@296604 0039d316-1c4b-4281-b951-d872f2087c98
scottmg@chromium.org пре 10 година
родитељ
комит
f4ddadcf25
2 измењених фајлова са 66 додато и 0 уклоњено
  1. 6 0
      git-find-releases
  2. 60 0
      git_find_releases.py

+ 6 - 0
git-find-releases

@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+. $(type -P python_git_runner.sh)

+ 60 - 0
git_find_releases.py

@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Usage: %prog <commit>*
+
+Given a commit, finds the release where it first appeared (e.g. 47.0.2500.0) as
+well as attempting to determine the branches to which it was merged.
+
+Note that it uses the "cherry picked from" annotation to find merges, so it will
+only work on merges that followed the "use cherry-pick -x" instructions.
+"""
+
+import optparse
+import re
+import sys
+
+import git_common as git
+
+
+def GetNameForCommit(sha1):
+  return re.sub(r'~.*$', '', git.run('name-rev', '--tags', '--name-only', sha1))
+
+
+def GetMergesForCommit(sha1):
+  return [c.split()[0] for c in
+          git.run('log', '--oneline', '-F', '--all', '--no-abbrev', '--grep',
+                  'cherry picked from commit %s' % sha1).splitlines()]
+
+
+def main():
+  parser = optparse.OptionParser(usage=sys.modules[__name__].__doc__)
+  _, args = parser.parse_args()
+
+  if len(args) == 0:
+    parser.error('Need at least one commit.')
+
+  for arg in args:
+    commit_name = GetNameForCommit(arg)
+    if not commit_name:
+      print '%s not found' % arg
+      return 1
+    print 'commit %s was:' % arg
+    print '  initially in ' + commit_name
+    merges = GetMergesForCommit(arg)
+    for merge in merges:
+      print '  merged to ' + GetNameForCommit(merge) + ' (as ' + merge + ')'
+    if not merges:
+      print 'No merges found. If this seems wrong, be sure that you did:'
+      print '  git fetch origin && gclient sync --with_branch_heads'
+
+  return 0
+
+
+if __name__ == '__main__':
+  try:
+    sys.exit(main())
+  except KeyboardInterrupt:
+    sys.stderr.write('interrupted\n')
+    sys.exit(1)