An interactive tool to help find owners covering current change list.


BUG=77248

Review URL: https://chromiumcodereview.appspot.com/12712002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@224264 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cl.py b/git_cl.py
index 43c9d36..289640a 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -8,6 +8,7 @@
 """A git-command for integrating reviews on Rietveld."""
 
 from distutils.version import LooseVersion
+import glob
 import json
 import logging
 import optparse
@@ -38,6 +39,7 @@
 import subcommand
 import subprocess2
 import watchlists
+import owners_finder
 
 __version__ = '1.0'
 
@@ -2126,6 +2128,35 @@
   return 0
 
 
+def CMDowners(parser, args):
+  """interactively find the owners for reviewing"""
+  parser.add_option(
+      '--no-color',
+      action='store_true',
+      help='Use this option to disable color output')
+  options, args = parser.parse_args(args)
+
+  author = RunGit(['config', 'user.email']).strip() or None
+
+  cl = Changelist()
+
+  if args:
+    if len(args) > 1:
+      parser.error('Unknown args')
+    base_branch = args[0]
+  else:
+    # Default to diffing against the common ancestor of the upstream branch.
+    base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip()
+
+  change = cl.GetChange(base_branch, None)
+  return owners_finder.OwnersFinder(
+      [f.LocalPath() for f in
+          cl.GetChange(base_branch, None).AffectedFiles()],
+      change.RepositoryRoot(), author,
+      fopen=file, os_path=os.path, glob=glob.glob,
+      disable_color=options.no_color).run()
+
+
 def CMDformat(parser, args):
   """Runs clang-format on the diff."""
   CLANG_EXTS = ['.cc', '.cpp', '.h']