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

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: 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 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 local_patchset != latest_patchset): 1409 local_patchset != latest_patchset):
1410 print('The last upload made from this repository was patchset #%d but ' 1410 print('The last upload made from this repository was patchset #%d but '
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)
Michael Achenbach 2016/07/06 07:30:39 Dumb question: How is 'self' referring to the 'imp
tandrii(chromium) 2016/07/06 10:38:25 __getattr__
1420 if not ret: 1420 if not ret:
1421 if options.use_commit_queue:
Michael Achenbach 2016/07/06 07:30:39 nit: Maybe give dry-run precedence over commit? If
tandrii(chromium) 2016/07/06 10:38:25 added a check early on.
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 def GetApprovingReviewers(self): 1469 def GetApprovingReviewers(self):
1465 return self._codereview_impl.GetApprovingReviewers() 1470 return self._codereview_impl.GetApprovingReviewers()
1466 1471
1467 def GetMostRecentPatchset(self): 1472 def GetMostRecentPatchset(self):
1468 return self._codereview_impl.GetMostRecentPatchset() 1473 return self._codereview_impl.GetMostRecentPatchset()
1469 1474
1470 def __getattr__(self, attr): 1475 def __getattr__(self, attr):
1471 # This is because lots of untested code accesses Rietveld-specific stuff 1476 # This is because lots of untested code accesses Rietveld-specific stuff
1472 # directly, and it's hard to fix for sure. So, just let it work, and fix 1477 # directly, and it's hard to fix for sure. So, just let it work, and fix
1473 # on a case by case basis. 1478 # on a case by case basis.
1474 return getattr(self._codereview_impl, attr) 1479 return getattr(self._codereview_impl, attr)
tandrii(chromium) 2016/07/06 10:38:25 this is the magic
1475 1480
1476 1481
1477 class _ChangelistCodereviewBase(object): 1482 class _ChangelistCodereviewBase(object):
1478 """Abstract base class encapsulating codereview specifics of a changelist.""" 1483 """Abstract base class encapsulating codereview specifics of a changelist."""
1479 def __init__(self, changelist): 1484 def __init__(self, changelist):
1480 self._changelist = changelist # instance of Changelist 1485 self._changelist = changelist # instance of Changelist
1481 1486
1482 def __getattr__(self, attr): 1487 def __getattr__(self, attr):
1483 # Forward methods to changelist. 1488 # Forward methods to changelist.
1484 # TODO(tandrii): maybe clean up _GerritChangelistImpl and 1489 # TODO(tandrii): maybe clean up _GerritChangelistImpl and
(...skipping 517 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 3050 matching lines...) Expand 10 before | Expand all | Expand 10 after
5101 if __name__ == '__main__': 5100 if __name__ == '__main__':
5102 # These affect sys.stdout so do it outside of main() to simplify mocks in 5101 # These affect sys.stdout so do it outside of main() to simplify mocks in
5103 # unit testing. 5102 # unit testing.
5104 fix_encoding.fix_encoding() 5103 fix_encoding.fix_encoding()
5105 setup_color.init() 5104 setup_color.init()
5106 try: 5105 try:
5107 sys.exit(main(sys.argv[1:])) 5106 sys.exit(main(sys.argv[1:]))
5108 except KeyboardInterrupt: 5107 except KeyboardInterrupt:
5109 sys.stderr.write('interrupted\n') 5108 sys.stderr.write('interrupted\n')
5110 sys.exit(1) 5109 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