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 glob | |
12 import json | 13 import json |
13 import logging | 14 import logging |
14 import optparse | 15 import optparse |
15 import os | 16 import os |
16 import Queue | 17 import Queue |
17 import re | 18 import re |
18 import stat | 19 import stat |
19 import sys | 20 import sys |
20 import textwrap | 21 import textwrap |
21 import threading | 22 import threading |
22 import urllib2 | 23 import urllib2 |
23 import urlparse | 24 import urlparse |
24 | 25 |
25 try: | 26 try: |
26 import readline # pylint: disable=F0401,W0611 | 27 import readline # pylint: disable=F0401,W0611 |
27 except ImportError: | 28 except ImportError: |
28 pass | 29 pass |
29 | 30 |
30 | 31 |
31 from third_party import colorama | 32 from third_party import colorama |
32 from third_party import upload | 33 from third_party import upload |
33 import breakpad # pylint: disable=W0611 | 34 import breakpad # pylint: disable=W0611 |
34 import fix_encoding | 35 import fix_encoding |
35 import gclient_utils | 36 import gclient_utils |
36 import presubmit_support | 37 import presubmit_support |
37 import rietveld | 38 import rietveld |
38 import scm | 39 import scm |
39 import subprocess2 | 40 import subprocess2 |
40 import watchlists | 41 import watchlists |
42 import owners_finder | |
41 | 43 |
42 | 44 |
43 DEFAULT_SERVER = 'https://codereview.appspot.com' | 45 DEFAULT_SERVER = 'https://codereview.appspot.com' |
44 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' | 46 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' |
45 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' | 47 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' |
46 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' | 48 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
47 CHANGE_ID = 'Change-Id:' | 49 CHANGE_ID = 'Change-Id:' |
48 | 50 |
49 # Shortcut since it quickly becomes redundant. | 51 # Shortcut since it quickly becomes redundant. |
50 Fore = colorama.Fore | 52 Fore = colorama.Fore |
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2078 _, args = parser.parse_args(args) | 2080 _, args = parser.parse_args(args) |
2079 if args: | 2081 if args: |
2080 parser.error('Unrecognized args: %s' % ' '.join(args)) | 2082 parser.error('Unrecognized args: %s' % ' '.join(args)) |
2081 cl = Changelist() | 2083 cl = Changelist() |
2082 # Ensure there actually is an issue to close. | 2084 # Ensure there actually is an issue to close. |
2083 cl.GetDescription() | 2085 cl.GetDescription() |
2084 cl.CloseIssue() | 2086 cl.CloseIssue() |
2085 return 0 | 2087 return 0 |
2086 | 2088 |
2087 | 2089 |
2090 def CMDowners(parser, args): | |
2091 """interactively find the owners for reviewing""" | |
2092 parser.add_option( | |
2093 '--no-color', | |
2094 action='store_true', | |
2095 help='Use this option to disable color output') | |
2096 options, args = parser.parse_args(args) | |
2097 | |
2098 author = RunGit(['config', 'user.email']).strip() or None | |
2099 | |
2100 if args: | |
2101 if len(args) > 1: | |
2102 parser.error('Unknown args') | |
2103 cl = Changelist() | |
M-A Ruel
2013/09/16 20:33:13
Move it above line 2100, so you can remove this on
Bei Zhang
2013/09/19 23:21:43
Done.
| |
2104 base_branch = args[0] | |
2105 else: | |
2106 cl = Changelist() | |
2107 # Default to diffing against the common ancestor of the upstream branch. | |
2108 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() | |
2109 | |
2110 change = cl.GetChange(base_branch, None) | |
2111 return owners_finder.OwnersFinder( | |
2112 [f.LocalPath() for f in | |
2113 cl.GetChange(base_branch, None).AffectedFiles()], | |
2114 change.RepositoryRoot(), author, | |
2115 fopen=file, os_path=os.path, glob=glob.glob, | |
2116 disable_color=options.no_color).run() | |
2117 | |
2118 | |
2088 def CMDformat(parser, args): | 2119 def CMDformat(parser, args): |
2089 """Runs clang-format on the diff.""" | 2120 """Runs clang-format on the diff.""" |
2090 CLANG_EXTS = ['.cc', '.cpp', '.h'] | 2121 CLANG_EXTS = ['.cc', '.cpp', '.h'] |
2091 parser.add_option('--full', action='store_true', default=False) | 2122 parser.add_option('--full', action='store_true', default=False) |
2092 opts, args = parser.parse_args(args) | 2123 opts, args = parser.parse_args(args) |
2093 if args: | 2124 if args: |
2094 parser.error('Unrecognized args: %s' % ' '.join(args)) | 2125 parser.error('Unrecognized args: %s' % ' '.join(args)) |
2095 | 2126 |
2096 # Generate diff for the current branch's changes. | 2127 # Generate diff for the current branch's changes. |
2097 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] | 2128 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2277 GenUsage(parser, 'help') | 2308 GenUsage(parser, 'help') |
2278 return CMDhelp(parser, argv) | 2309 return CMDhelp(parser, argv) |
2279 | 2310 |
2280 | 2311 |
2281 if __name__ == '__main__': | 2312 if __name__ == '__main__': |
2282 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2313 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2283 # unit testing. | 2314 # unit testing. |
2284 fix_encoding.fix_encoding() | 2315 fix_encoding.fix_encoding() |
2285 colorama.init() | 2316 colorama.init() |
2286 sys.exit(main(sys.argv[1:])) | 2317 sys.exit(main(sys.argv[1:])) |
OLD | NEW |