OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 import difflib | 10 import difflib |
11 from distutils.version import LooseVersion | 11 from distutils.version import LooseVersion |
12 import json | 12 import json |
13 import logging | 13 import logging |
14 import optparse | 14 import optparse |
15 import os | 15 import os |
16 import re | 16 import re |
17 import stat | 17 import stat |
18 import sys | 18 import sys |
19 import textwrap | 19 import textwrap |
20 import urllib2 | 20 import urllib2 |
21 import urlparse | 21 import urlparse |
22 import glob | |
22 | 23 |
23 try: | 24 try: |
24 import readline # pylint: disable=F0401,W0611 | 25 import readline # pylint: disable=F0401,W0611 |
25 except ImportError: | 26 except ImportError: |
26 pass | 27 pass |
27 | 28 |
28 | 29 |
29 from third_party import colorama | 30 from third_party import colorama |
30 from third_party import upload | 31 from third_party import upload |
31 import breakpad # pylint: disable=W0611 | 32 import breakpad # pylint: disable=W0611 |
32 import fix_encoding | 33 import fix_encoding |
33 import gclient_utils | 34 import gclient_utils |
34 import presubmit_support | 35 import presubmit_support |
35 import rietveld | 36 import rietveld |
36 import scm | 37 import scm |
37 import subprocess2 | 38 import subprocess2 |
38 import watchlists | 39 import watchlists |
40 import owners_finder | |
39 | 41 |
40 | 42 |
41 DEFAULT_SERVER = 'https://codereview.appspot.com' | 43 DEFAULT_SERVER = 'https://codereview.appspot.com' |
42 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' | 44 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' |
43 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' | 45 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' |
44 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' | 46 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
45 CHANGE_ID = 'Change-Id:' | 47 CHANGE_ID = 'Change-Id:' |
46 | 48 |
47 # Shortcut since it quickly becomes redundant. | 49 # Shortcut since it quickly becomes redundant. |
48 Fore = colorama.Fore | 50 Fore = colorama.Fore |
(...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1992 _, args = parser.parse_args(args) | 1994 _, args = parser.parse_args(args) |
1993 if args: | 1995 if args: |
1994 parser.error('Unrecognized args: %s' % ' '.join(args)) | 1996 parser.error('Unrecognized args: %s' % ' '.join(args)) |
1995 cl = Changelist() | 1997 cl = Changelist() |
1996 # Ensure there actually is an issue to close. | 1998 # Ensure there actually is an issue to close. |
1997 cl.GetDescription() | 1999 cl.GetDescription() |
1998 cl.CloseIssue() | 2000 cl.CloseIssue() |
1999 return 0 | 2001 return 0 |
2000 | 2002 |
2001 | 2003 |
2004 def CMDowners(parser, args): | |
2005 """interactively find the owners for reviewing""" | |
2006 group = optparse.OptionGroup(parser, 'Find owners options') | |
2007 group.add_option( | |
2008 '--no-color', | |
2009 action='store_true', | |
2010 help='Use this option to disable color output') | |
2011 parser.add_option_group(group) | |
Dirk Pranke
2013/07/27 00:06:03
I probably wouldn't use an OptionGroup for this, j
Bei Zhang
2013/07/30 05:59:17
Done.
| |
2012 options, args = parser.parse_args(args) | |
2013 | |
2014 if args: | |
2015 if len(args) > 1: | |
2016 parser.error('Unknown args') | |
2017 cl = Changelist() | |
2018 base_branch = args[0] | |
2019 else: | |
2020 cl = Changelist() | |
2021 # Default to diffing against the common ancestor of the upstream branch. | |
2022 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() | |
2023 | |
2024 change = cl.GetChange(base_branch, None) | |
2025 return owners_finder.OwnersFinder( | |
2026 [f.LocalPath() for f in | |
2027 cl.GetChange(base_branch, None).AffectedFiles()], | |
2028 change.RepositoryRoot(), | |
2029 fopen=file, os_path=os.path, glob=glob.glob, | |
2030 disable_color=options.no_color).run() | |
2031 | |
2032 | |
2002 def CMDformat(parser, args): | 2033 def CMDformat(parser, args): |
2003 """run clang-format on the diff""" | 2034 """run clang-format on the diff""" |
2004 CLANG_EXTS = ['.cc', '.cpp', '.h'] | 2035 CLANG_EXTS = ['.cc', '.cpp', '.h'] |
2005 parser.add_option('--full', action='store_true', default=False) | 2036 parser.add_option('--full', action='store_true', default=False) |
2006 opts, args = parser.parse_args(args) | 2037 opts, args = parser.parse_args(args) |
2007 if args: | 2038 if args: |
2008 parser.error('Unrecognized args: %s' % ' '.join(args)) | 2039 parser.error('Unrecognized args: %s' % ' '.join(args)) |
2009 | 2040 |
2010 # Generate diff for the current branch's changes. | 2041 # Generate diff for the current branch's changes. |
2011 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] | 2042 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2177 GenUsage(parser, 'help') | 2208 GenUsage(parser, 'help') |
2178 return CMDhelp(parser, argv) | 2209 return CMDhelp(parser, argv) |
2179 | 2210 |
2180 | 2211 |
2181 if __name__ == '__main__': | 2212 if __name__ == '__main__': |
2182 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2213 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2183 # unit testing. | 2214 # unit testing. |
2184 fix_encoding.fix_encoding() | 2215 fix_encoding.fix_encoding() |
2185 colorama.init() | 2216 colorama.init() |
2186 sys.exit(main(sys.argv[1:])) | 2217 sys.exit(main(sys.argv[1:])) |
OLD | NEW |