Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: git_cl.py

Issue 2117183004: Implement git cl upload --dry-run or --use-commit-queue for Gerrit. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@set-commit
Patch Set: review Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 __future__ import print_function 10 from __future__ import print_function
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 'the most recent patchset on the server is #%d.' 1411 'the most recent patchset on the server is #%d.'
1412 % (local_patchset, latest_patchset)) 1412 % (local_patchset, latest_patchset))
1413 print('Uploading will still work, but if you\'ve uploaded to this ' 1413 print('Uploading will still work, but if you\'ve uploaded to this '
1414 'issue from another machine or branch the patch you\'re ' 1414 'issue from another machine or branch the patch you\'re '
1415 'uploading now might not include those changes.') 1415 'uploading now might not include those changes.')
1416 ask_for_data('About to upload; enter to confirm.') 1416 ask_for_data('About to upload; enter to confirm.')
1417 1417
1418 print_stats(options.similarity, options.find_copies, git_diff_args) 1418 print_stats(options.similarity, options.find_copies, git_diff_args)
1419 ret = self.CMDUploadChange(options, git_diff_args, change) 1419 ret = self.CMDUploadChange(options, git_diff_args, change)
1420 if not ret: 1420 if not ret:
1421 if options.use_commit_queue:
1422 self.SetCQState(_CQState.COMMIT)
1423 elif options.cq_dry_run:
1424 self.SetCQState(_CQState.DRY_RUN)
1425
1421 git_set_branch_value('last-upload-hash', 1426 git_set_branch_value('last-upload-hash',
1422 RunGit(['rev-parse', 'HEAD']).strip()) 1427 RunGit(['rev-parse', 'HEAD']).strip())
1423 # Run post upload hooks, if specified. 1428 # Run post upload hooks, if specified.
1424 if settings.GetRunPostUploadHook(): 1429 if settings.GetRunPostUploadHook():
1425 presubmit_support.DoPostUploadExecuter( 1430 presubmit_support.DoPostUploadExecuter(
1426 change, 1431 change,
1427 self, 1432 self,
1428 settings.GetRoot(), 1433 settings.GetRoot(),
1429 options.verbose, 1434 options.verbose,
1430 sys.stdout) 1435 sys.stdout)
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 'The current branch (%s) is tracking a local branch (%s) with ' 2007 'The current branch (%s) is tracking a local branch (%s) with '
2003 'an associated CL.\n' 2008 'an associated CL.\n'
2004 'Adding %s/#ps%s as a dependency patchset.\n' 2009 'Adding %s/#ps%s as a dependency patchset.\n'
2005 '\n' % (self.GetBranch(), local_branch, branch_cl_issue_url, 2010 '\n' % (self.GetBranch(), local_branch, branch_cl_issue_url,
2006 branch_cl_patchset)) 2011 branch_cl_patchset))
2007 2012
2008 project = settings.GetProject() 2013 project = settings.GetProject()
2009 if project: 2014 if project:
2010 upload_args.extend(['--project', project]) 2015 upload_args.extend(['--project', project])
2011 2016
2012 if options.cq_dry_run:
2013 upload_args.extend(['--cq_dry_run'])
2014
2015 try: 2017 try:
2016 upload_args = ['upload'] + upload_args + args 2018 upload_args = ['upload'] + upload_args + args
2017 logging.info('upload.RealMain(%s)', upload_args) 2019 logging.info('upload.RealMain(%s)', upload_args)
2018 issue, patchset = upload.RealMain(upload_args) 2020 issue, patchset = upload.RealMain(upload_args)
2019 issue = int(issue) 2021 issue = int(issue)
2020 patchset = int(patchset) 2022 patchset = int(patchset)
2021 except KeyboardInterrupt: 2023 except KeyboardInterrupt:
2022 sys.exit(1) 2024 sys.exit(1)
2023 except: 2025 except:
2024 # If we got an exception after the user typed a description for their 2026 # If we got an exception after the user typed a description for their
2025 # change, back up the description before re-raising. 2027 # change, back up the description before re-raising.
2026 if change_desc: 2028 if change_desc:
2027 backup_path = os.path.expanduser(DESCRIPTION_BACKUP_FILE) 2029 backup_path = os.path.expanduser(DESCRIPTION_BACKUP_FILE)
2028 print('\nGot exception while uploading -- saving description to %s\n' % 2030 print('\nGot exception while uploading -- saving description to %s\n' %
2029 backup_path) 2031 backup_path)
2030 backup_file = open(backup_path, 'w') 2032 backup_file = open(backup_path, 'w')
2031 backup_file.write(change_desc.description) 2033 backup_file.write(change_desc.description)
2032 backup_file.close() 2034 backup_file.close()
2033 raise 2035 raise
2034 2036
2035 if not self.GetIssue(): 2037 if not self.GetIssue():
2036 self.SetIssue(issue) 2038 self.SetIssue(issue)
2037 self.SetPatchset(patchset) 2039 self.SetPatchset(patchset)
2038
2039 if options.use_commit_queue:
2040 self.SetCQState(_CQState.COMMIT)
2041 return 0 2040 return 0
2042 2041
2043 2042
2044 class _GerritChangelistImpl(_ChangelistCodereviewBase): 2043 class _GerritChangelistImpl(_ChangelistCodereviewBase):
2045 def __init__(self, changelist, auth_config=None): 2044 def __init__(self, changelist, auth_config=None):
2046 # auth_config is Rietveld thing, kept here to preserve interface only. 2045 # auth_config is Rietveld thing, kept here to preserve interface only.
2047 super(_GerritChangelistImpl, self).__init__(changelist) 2046 super(_GerritChangelistImpl, self).__init__(changelist)
2048 self._change_id = None 2047 self._change_id = None
2049 # Lazily cached values. 2048 # Lazily cached values.
2050 self._gerrit_server = None # e.g. https://chromium-review.googlesource.com 2049 self._gerrit_server = None # e.g. https://chromium-review.googlesource.com
(...skipping 1753 matching lines...) Expand 10 before | Expand all | Expand 10 after
3804 3803
3805 options.reviewers = cleanup_list(options.reviewers) 3804 options.reviewers = cleanup_list(options.reviewers)
3806 options.cc = cleanup_list(options.cc) 3805 options.cc = cleanup_list(options.cc)
3807 3806
3808 if options.message_file: 3807 if options.message_file:
3809 if options.message: 3808 if options.message:
3810 parser.error('only one of --message and --message-file allowed.') 3809 parser.error('only one of --message and --message-file allowed.')
3811 options.message = gclient_utils.FileRead(options.message_file) 3810 options.message = gclient_utils.FileRead(options.message_file)
3812 options.message_file = None 3811 options.message_file = None
3813 3812
3813 if options.cq_dry_run and options.use_commit_queue:
3814 parser.error('only one of --use-commit-queue and --cq-dry-run allowed.')
3815
3814 # For sanity of test expectations, do this otherwise lazy-loading *now*. 3816 # For sanity of test expectations, do this otherwise lazy-loading *now*.
3815 settings.GetIsGerrit() 3817 settings.GetIsGerrit()
3816 3818
3817 cl = Changelist(auth_config=auth_config, codereview=options.forced_codereview) 3819 cl = Changelist(auth_config=auth_config, codereview=options.forced_codereview)
3818 return cl.CMDUpload(options, args, orig_args) 3820 return cl.CMDUpload(options, args, orig_args)
3819 3821
3820 3822
3821 def IsSubmoduleMergeCommit(ref): 3823 def IsSubmoduleMergeCommit(ref):
3822 # When submodules are added to the repo, we expect there to be a single 3824 # When submodules are added to the repo, we expect there to be a single
3823 # non-git-svn merge commit at remote HEAD with a signature comment. 3825 # non-git-svn merge commit at remote HEAD with a signature comment.
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
4740 4742
4741 cl = Changelist(auth_config=auth_config) 4743 cl = Changelist(auth_config=auth_config)
4742 if options.clear: 4744 if options.clear:
4743 state = _CQState.CLEAR 4745 state = _CQState.CLEAR
4744 elif options.dry_run: 4746 elif options.dry_run:
4745 state = _CQState.DRY_RUN 4747 state = _CQState.DRY_RUN
4746 else: 4748 else:
4747 state = _CQState.COMMIT 4749 state = _CQState.COMMIT
4748 if not cl.GetIssue(): 4750 if not cl.GetIssue():
4749 parser.error('Must upload the issue first') 4751 parser.error('Must upload the issue first')
4750 cl.SetCQState(state) 4752 cl._codereview_impl.SetCQState(state)
4751 return 0 4753 return 0
4752 4754
4753 4755
4754 def CMDset_close(parser, args): 4756 def CMDset_close(parser, args):
4755 """Closes the issue.""" 4757 """Closes the issue."""
4756 auth.add_auth_options(parser) 4758 auth.add_auth_options(parser)
4757 options, args = parser.parse_args(args) 4759 options, args = parser.parse_args(args)
4758 auth_config = auth.extract_auth_config_from_options(options) 4760 auth_config = auth.extract_auth_config_from_options(options)
4759 if args: 4761 if args:
4760 parser.error('Unrecognized args: %s' % ' '.join(args)) 4762 parser.error('Unrecognized args: %s' % ' '.join(args))
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
5101 if __name__ == '__main__': 5103 if __name__ == '__main__':
5102 # These affect sys.stdout so do it outside of main() to simplify mocks in 5104 # These affect sys.stdout so do it outside of main() to simplify mocks in
5103 # unit testing. 5105 # unit testing.
5104 fix_encoding.fix_encoding() 5106 fix_encoding.fix_encoding()
5105 setup_color.init() 5107 setup_color.init()
5106 try: 5108 try:
5107 sys.exit(main(sys.argv[1:])) 5109 sys.exit(main(sys.argv[1:]))
5108 except KeyboardInterrupt: 5110 except KeyboardInterrupt:
5109 sys.stderr.write('interrupted\n') 5111 sys.stderr.write('interrupted\n')
5110 sys.exit(1) 5112 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698