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 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| 11 import glob |
11 import json | 12 import json |
12 import logging | 13 import logging |
13 import optparse | 14 import optparse |
14 import os | 15 import os |
15 import Queue | 16 import Queue |
16 import re | 17 import re |
17 import stat | 18 import stat |
18 import sys | 19 import sys |
19 import textwrap | 20 import textwrap |
20 import threading | 21 import threading |
(...skipping 10 matching lines...) Expand all Loading... |
31 from third_party import upload | 32 from third_party import upload |
32 import breakpad # pylint: disable=W0611 | 33 import breakpad # pylint: disable=W0611 |
33 import fix_encoding | 34 import fix_encoding |
34 import gclient_utils | 35 import gclient_utils |
35 import presubmit_support | 36 import presubmit_support |
36 import rietveld | 37 import rietveld |
37 import scm | 38 import scm |
38 import subcommand | 39 import subcommand |
39 import subprocess2 | 40 import subprocess2 |
40 import watchlists | 41 import watchlists |
| 42 import owners_finder |
41 | 43 |
42 __version__ = '1.0' | 44 __version__ = '1.0' |
43 | 45 |
44 DEFAULT_SERVER = 'https://codereview.appspot.com' | 46 DEFAULT_SERVER = 'https://codereview.appspot.com' |
45 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' | 47 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' |
46 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' | 48 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' |
47 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' | 49 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' |
48 CHANGE_ID = 'Change-Id:' | 50 CHANGE_ID = 'Change-Id:' |
49 | 51 |
50 # Shortcut since it quickly becomes redundant. | 52 # Shortcut since it quickly becomes redundant. |
(...skipping 2068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2119 _, args = parser.parse_args(args) | 2121 _, args = parser.parse_args(args) |
2120 if args: | 2122 if args: |
2121 parser.error('Unrecognized args: %s' % ' '.join(args)) | 2123 parser.error('Unrecognized args: %s' % ' '.join(args)) |
2122 cl = Changelist() | 2124 cl = Changelist() |
2123 # Ensure there actually is an issue to close. | 2125 # Ensure there actually is an issue to close. |
2124 cl.GetDescription() | 2126 cl.GetDescription() |
2125 cl.CloseIssue() | 2127 cl.CloseIssue() |
2126 return 0 | 2128 return 0 |
2127 | 2129 |
2128 | 2130 |
| 2131 def CMDowners(parser, args): |
| 2132 """interactively find the owners for reviewing""" |
| 2133 parser.add_option( |
| 2134 '--no-color', |
| 2135 action='store_true', |
| 2136 help='Use this option to disable color output') |
| 2137 options, args = parser.parse_args(args) |
| 2138 |
| 2139 author = RunGit(['config', 'user.email']).strip() or None |
| 2140 |
| 2141 cl = Changelist() |
| 2142 |
| 2143 if args: |
| 2144 if len(args) > 1: |
| 2145 parser.error('Unknown args') |
| 2146 base_branch = args[0] |
| 2147 else: |
| 2148 # Default to diffing against the common ancestor of the upstream branch. |
| 2149 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() |
| 2150 |
| 2151 change = cl.GetChange(base_branch, None) |
| 2152 return owners_finder.OwnersFinder( |
| 2153 [f.LocalPath() for f in |
| 2154 cl.GetChange(base_branch, None).AffectedFiles()], |
| 2155 change.RepositoryRoot(), author, |
| 2156 fopen=file, os_path=os.path, glob=glob.glob, |
| 2157 disable_color=options.no_color).run() |
| 2158 |
| 2159 |
2129 def CMDformat(parser, args): | 2160 def CMDformat(parser, args): |
2130 """Runs clang-format on the diff.""" | 2161 """Runs clang-format on the diff.""" |
2131 CLANG_EXTS = ['.cc', '.cpp', '.h'] | 2162 CLANG_EXTS = ['.cc', '.cpp', '.h'] |
2132 parser.add_option('--full', action='store_true', default=False) | 2163 parser.add_option('--full', action='store_true', default=False) |
2133 opts, args = parser.parse_args(args) | 2164 opts, args = parser.parse_args(args) |
2134 if args: | 2165 if args: |
2135 parser.error('Unrecognized args: %s' % ' '.join(args)) | 2166 parser.error('Unrecognized args: %s' % ' '.join(args)) |
2136 | 2167 |
2137 # Generate diff for the current branch's changes. | 2168 # Generate diff for the current branch's changes. |
2138 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] | 2169 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2225 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2256 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
2226 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2257 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
2227 | 2258 |
2228 | 2259 |
2229 if __name__ == '__main__': | 2260 if __name__ == '__main__': |
2230 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2261 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2231 # unit testing. | 2262 # unit testing. |
2232 fix_encoding.fix_encoding() | 2263 fix_encoding.fix_encoding() |
2233 colorama.init() | 2264 colorama.init() |
2234 sys.exit(main(sys.argv[1:])) | 2265 sys.exit(main(sys.argv[1:])) |
OLD | NEW |