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 and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 options.squash = ((settings.GetSquashGerritUploads() or options.squash) and | 2227 options.squash = ((settings.GetSquashGerritUploads() or options.squash) and |
2228 not options.no_squash) | 2228 not options.no_squash) |
2229 # We assume the remote called "origin" is the one we want. | 2229 # We assume the remote called "origin" is the one we want. |
2230 # It is probably not worthwhile to support different workflows. | 2230 # It is probably not worthwhile to support different workflows. |
2231 gerrit_remote = 'origin' | 2231 gerrit_remote = 'origin' |
2232 | 2232 |
2233 remote, remote_branch = self.GetRemoteBranch() | 2233 remote, remote_branch = self.GetRemoteBranch() |
2234 branch = GetTargetRef(remote, remote_branch, options.target_branch, | 2234 branch = GetTargetRef(remote, remote_branch, options.target_branch, |
2235 pending_prefix='') | 2235 pending_prefix='') |
2236 | 2236 |
2237 if options.title: | |
2238 # TODO(tandrii): it's now supported by Gerrit, implement! | |
2239 print "\nPatch titles (-t) are not supported in Gerrit. Aborting..." | |
2240 return 1 | |
2241 | |
2242 if options.squash: | 2237 if options.squash: |
2243 if not self.GetIssue(): | 2238 if not self.GetIssue(): |
2244 # TODO(tandrii): deperecate this after 2016Q2. Backwards compatibility | 2239 # TODO(tandrii): deperecate this after 2016Q2. Backwards compatibility |
2245 # with shadow branch, which used to contain change-id for a given | 2240 # with shadow branch, which used to contain change-id for a given |
2246 # branch, using which we can fetch actual issue number and set it as the | 2241 # branch, using which we can fetch actual issue number and set it as the |
2247 # property of the branch, which is the new way. | 2242 # property of the branch, which is the new way. |
2248 message = RunGitSilent([ | 2243 message = RunGitSilent([ |
2249 'show', '--format=%B', '-s', | 2244 'show', '--format=%B', '-s', |
2250 'refs/heads/git_cl_uploads/%s' % self.GetBranch()]) | 2245 'refs/heads/git_cl_uploads/%s' % self.GetBranch()]) |
2251 if message: | 2246 if message: |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2379 'to see which commits will be uploaded: ' % len(commits)) | 2374 'to see which commits will be uploaded: ' % len(commits)) |
2380 print('git log %s..%s' % (parent, ref_to_push)) | 2375 print('git log %s..%s' % (parent, ref_to_push)) |
2381 print('You can also use `git squash-branch` to squash these into a ' | 2376 print('You can also use `git squash-branch` to squash these into a ' |
2382 'single commit.') | 2377 'single commit.') |
2383 ask_for_data('About to upload; enter to confirm.') | 2378 ask_for_data('About to upload; enter to confirm.') |
2384 | 2379 |
2385 if options.reviewers or options.tbr_owners: | 2380 if options.reviewers or options.tbr_owners: |
2386 change_desc.update_reviewers(options.reviewers, options.tbr_owners, | 2381 change_desc.update_reviewers(options.reviewers, options.tbr_owners, |
2387 change) | 2382 change) |
2388 | 2383 |
| 2384 # Extra options that can be specified at push time. Doc: |
| 2385 # https://gerrit-review.googlesource.com/Documentation/user-upload.html |
| 2386 refspec_opts = [] |
| 2387 if options.title: |
| 2388 # Per doc, spaces must be converted to underscores, and Gerrit will do the |
| 2389 # reverse on its side. |
| 2390 if '_' in options.title: |
| 2391 print('WARNING: underscores in title will be converted to spaces.') |
| 2392 refspec_opts.append('m=' + options.title.replace(' ', '_')) |
| 2393 |
2389 receive_options = [] | 2394 receive_options = [] |
2390 cc = self.GetCCList().split(',') | 2395 cc = self.GetCCList().split(',') |
2391 if options.cc: | 2396 if options.cc: |
2392 cc.extend(options.cc) | 2397 cc.extend(options.cc) |
2393 cc = filter(None, cc) | 2398 cc = filter(None, cc) |
2394 if cc: | 2399 if cc: |
2395 receive_options += ['--cc=' + email for email in cc] | 2400 receive_options += ['--cc=' + email for email in cc] |
2396 if change_desc.get_reviewers(): | 2401 if change_desc.get_reviewers(): |
2397 receive_options.extend( | 2402 receive_options.extend( |
2398 '--reviewer=' + email for email in change_desc.get_reviewers()) | 2403 '--reviewer=' + email for email in change_desc.get_reviewers()) |
2399 | 2404 |
2400 git_command = ['push'] | 2405 git_command = ['git', 'push'] |
2401 if receive_options: | 2406 if receive_options: |
| 2407 # TODO(tandrii): clean this up in follow up. This doesn't work, as it gets |
| 2408 # totally ignored by Gerrit. |
2402 git_command.append('--receive-pack=git receive-pack %s' % | 2409 git_command.append('--receive-pack=git receive-pack %s' % |
2403 ' '.join(receive_options)) | 2410 ' '.join(receive_options)) |
2404 git_command += [gerrit_remote, ref_to_push + ':refs/for/' + branch] | 2411 |
| 2412 refspec_suffix = '' |
| 2413 if refspec_opts: |
| 2414 refspec_suffix = '%' + ','.join(refspec_opts) |
| 2415 assert ' ' not in refspec_suffix, ( |
| 2416 'spaces not allowed in refspec: "%s"' % refspec_suffix) |
| 2417 |
| 2418 refspec = '%s:refs/for/%s%s' % (ref_to_push, branch, refspec_suffix) |
| 2419 git_command += [gerrit_remote, refspec] |
| 2420 |
2405 push_stdout = gclient_utils.CheckCallAndFilter( | 2421 push_stdout = gclient_utils.CheckCallAndFilter( |
2406 ['git'] + git_command, | 2422 git_command, |
2407 print_stdout=True, | 2423 print_stdout=True, |
2408 # Flush after every line: useful for seeing progress when running as | 2424 # Flush after every line: useful for seeing progress when running as |
2409 # recipe. | 2425 # recipe. |
2410 filter_fn=lambda _: sys.stdout.flush()) | 2426 filter_fn=lambda _: sys.stdout.flush()) |
2411 | 2427 |
2412 if options.squash: | 2428 if options.squash: |
2413 regex = re.compile(r'remote:\s+https?://[\w\-\.\/]*/(\d+)\s.*') | 2429 regex = re.compile(r'remote:\s+https?://[\w\-\.\/]*/(\d+)\s.*') |
2414 change_numbers = [m.group(1) | 2430 change_numbers = [m.group(1) |
2415 for m in map(regex.match, push_stdout.splitlines()) | 2431 for m in map(regex.match, push_stdout.splitlines()) |
2416 if m] | 2432 if m] |
(...skipping 2280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4697 if __name__ == '__main__': | 4713 if __name__ == '__main__': |
4698 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4714 # These affect sys.stdout so do it outside of main() to simplify mocks in |
4699 # unit testing. | 4715 # unit testing. |
4700 fix_encoding.fix_encoding() | 4716 fix_encoding.fix_encoding() |
4701 setup_color.init() | 4717 setup_color.init() |
4702 try: | 4718 try: |
4703 sys.exit(main(sys.argv[1:])) | 4719 sys.exit(main(sys.argv[1:])) |
4704 except KeyboardInterrupt: | 4720 except KeyboardInterrupt: |
4705 sys.stderr.write('interrupted\n') | 4721 sys.stderr.write('interrupted\n') |
4706 sys.exit(1) | 4722 sys.exit(1) |
OLD | NEW |