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

Side by Side Diff: git_cl.py

Issue 1584703005: Add a setting to squash Gerrit uploads by default, and a --no-squash command line option to overrid… (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: x Created 4 years, 11 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 | tests/git_cl_test.py » ('j') | 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.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 def __init__(self): 426 def __init__(self):
427 self.default_server = None 427 self.default_server = None
428 self.cc = None 428 self.cc = None
429 self.root = None 429 self.root = None
430 self.is_git_svn = None 430 self.is_git_svn = None
431 self.svn_branch = None 431 self.svn_branch = None
432 self.tree_status_url = None 432 self.tree_status_url = None
433 self.viewvc_url = None 433 self.viewvc_url = None
434 self.updated = False 434 self.updated = False
435 self.is_gerrit = None 435 self.is_gerrit = None
436 self.squash_gerrit_uploads = None
436 self.git_editor = None 437 self.git_editor = None
437 self.project = None 438 self.project = None
438 self.force_https_commit_url = None 439 self.force_https_commit_url = None
439 self.pending_ref_prefix = None 440 self.pending_ref_prefix = None
440 441
441 def LazyUpdateIfNeeded(self): 442 def LazyUpdateIfNeeded(self):
442 """Updates the settings from a codereview.settings file, if available.""" 443 """Updates the settings from a codereview.settings file, if available."""
443 if not self.updated: 444 if not self.updated:
444 # The only value that actually changes the behavior is 445 # The only value that actually changes the behavior is
445 # autoupdate = "false". Everything else means "true". 446 # autoupdate = "false". Everything else means "true".
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 592
592 def GetDefaultPrivateFlag(self): 593 def GetDefaultPrivateFlag(self):
593 return self._GetRietveldConfig('private', error_ok=True) 594 return self._GetRietveldConfig('private', error_ok=True)
594 595
595 def GetIsGerrit(self): 596 def GetIsGerrit(self):
596 """Return true if this repo is assosiated with gerrit code review system.""" 597 """Return true if this repo is assosiated with gerrit code review system."""
597 if self.is_gerrit is None: 598 if self.is_gerrit is None:
598 self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True) 599 self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True)
599 return self.is_gerrit 600 return self.is_gerrit
600 601
602 def GetSquashGerritUploads(self):
603 """Return true if uploads to Gerrit should be squashed by default."""
604 if self.squash_gerrit_uploads is None:
605 self.squash_gerrit_uploads = (
606 RunGit(['config', '--bool', 'gerrit.squash-uploads'],
607 error_ok=True).strip() == 'true')
608 return self.squash_gerrit_uploads
609
601 def GetGitEditor(self): 610 def GetGitEditor(self):
602 """Return the editor specified in the git config, or None if none is.""" 611 """Return the editor specified in the git config, or None if none is."""
603 if self.git_editor is None: 612 if self.git_editor is None:
604 self.git_editor = self._GetConfig('core.editor', error_ok=True) 613 self.git_editor = self._GetConfig('core.editor', error_ok=True)
605 return self.git_editor or None 614 return self.git_editor or None
606 615
607 def GetLintRegex(self): 616 def GetLintRegex(self):
608 return (self._GetRietveldConfig('cpplint-regex', error_ok=True) or 617 return (self._GetRietveldConfig('cpplint-regex', error_ok=True) or
609 DEFAULT_LINT_REGEX) 618 DEFAULT_LINT_REGEX)
610 619
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 unset_error_ok=True) 1388 unset_error_ok=True)
1380 SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True) 1389 SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True)
1381 SetProperty('project', 'PROJECT', unset_error_ok=True) 1390 SetProperty('project', 'PROJECT', unset_error_ok=True)
1382 SetProperty('pending-ref-prefix', 'PENDING_REF_PREFIX', unset_error_ok=True) 1391 SetProperty('pending-ref-prefix', 'PENDING_REF_PREFIX', unset_error_ok=True)
1383 SetProperty('run-post-upload-hook', 'RUN_POST_UPLOAD_HOOK', 1392 SetProperty('run-post-upload-hook', 'RUN_POST_UPLOAD_HOOK',
1384 unset_error_ok=True) 1393 unset_error_ok=True)
1385 1394
1386 if 'GERRIT_HOST' in keyvals: 1395 if 'GERRIT_HOST' in keyvals:
1387 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) 1396 RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']])
1388 1397
1398 if 'GERRIT_SQUASH_UPLOADS' in keyvals:
1399 RunGit(['config', 'gerrit.squash-uploads',
1400 keyvals['GERRIT_SQUASH_UPLOADS']])
1401
1389 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: 1402 if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals:
1390 #should be of the form 1403 #should be of the form
1391 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof 1404 #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof
1392 #ORIGIN_URL_CONFIG: http://src.chromium.org/git 1405 #ORIGIN_URL_CONFIG: http://src.chromium.org/git
1393 RunGit(['config', keyvals['PUSH_URL_CONFIG'], 1406 RunGit(['config', keyvals['PUSH_URL_CONFIG'],
1394 keyvals['ORIGIN_URL_CONFIG']]) 1407 keyvals['ORIGIN_URL_CONFIG']])
1395 1408
1396 1409
1397 def urlretrieve(source, destination): 1410 def urlretrieve(source, destination):
1398 """urllib is broken for SSL connections via a proxy therefore we 1411 """urllib is broken for SSL connections via a proxy therefore we
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
2346 help='tell the commit queue to commit this patchset') 2359 help='tell the commit queue to commit this patchset')
2347 parser.add_option('--private', action='store_true', 2360 parser.add_option('--private', action='store_true',
2348 help='set the review private (rietveld only)') 2361 help='set the review private (rietveld only)')
2349 parser.add_option('--target_branch', 2362 parser.add_option('--target_branch',
2350 '--target-branch', 2363 '--target-branch',
2351 metavar='TARGET', 2364 metavar='TARGET',
2352 help='Apply CL to remote ref TARGET. ' + 2365 help='Apply CL to remote ref TARGET. ' +
2353 'Default: remote branch head, or master') 2366 'Default: remote branch head, or master')
2354 parser.add_option('--squash', action='store_true', 2367 parser.add_option('--squash', action='store_true',
2355 help='Squash multiple commits into one (Gerrit only)') 2368 help='Squash multiple commits into one (Gerrit only)')
2369 parser.add_option('--no-squash', action='store_true',
2370 help='Don\'t squash multiple commits into one ' +
2371 '(Gerrit only)')
2356 parser.add_option('--email', default=None, 2372 parser.add_option('--email', default=None,
2357 help='email address to use to connect to Rietveld') 2373 help='email address to use to connect to Rietveld')
2358 parser.add_option('--tbr-owners', dest='tbr_owners', action='store_true', 2374 parser.add_option('--tbr-owners', dest='tbr_owners', action='store_true',
2359 help='add a set of OWNERS to TBR') 2375 help='add a set of OWNERS to TBR')
2360 parser.add_option('-d', '--cq-dry-run', dest='cq_dry_run', 2376 parser.add_option('-d', '--cq-dry-run', dest='cq_dry_run',
2361 action='store_true', 2377 action='store_true',
2362 help='Send the patchset to do a CQ dry run right after ' 2378 help='Send the patchset to do a CQ dry run right after '
2363 'upload.') 2379 'upload.')
2364 parser.add_option('--dependencies', action='store_true', 2380 parser.add_option('--dependencies', action='store_true',
2365 help='Uploads CLs of all the local branches that depend on ' 2381 help='Uploads CLs of all the local branches that depend on '
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2429 print ('The last upload made from this repository was patchset #%d but ' 2445 print ('The last upload made from this repository was patchset #%d but '
2430 'the most recent patchset on the server is #%d.' 2446 'the most recent patchset on the server is #%d.'
2431 % (local_patchset, latest_patchset)) 2447 % (local_patchset, latest_patchset))
2432 print ('Uploading will still work, but if you\'ve uploaded to this issue ' 2448 print ('Uploading will still work, but if you\'ve uploaded to this issue '
2433 'from another machine or branch the patch you\'re uploading now ' 2449 'from another machine or branch the patch you\'re uploading now '
2434 'might not include those changes.') 2450 'might not include those changes.')
2435 ask_for_data('About to upload; enter to confirm.') 2451 ask_for_data('About to upload; enter to confirm.')
2436 2452
2437 print_stats(options.similarity, options.find_copies, args) 2453 print_stats(options.similarity, options.find_copies, args)
2438 if settings.GetIsGerrit(): 2454 if settings.GetIsGerrit():
2455 if options.squash and options.no_squash:
2456 DieWithError('Can only use one of --squash or --no-squash')
2457
2458 options.squash = ((settings.GetSquashGerritUploads() or options.squash) and
2459 not options.no_squash)
2460
2439 return GerritUpload(options, args, cl, change) 2461 return GerritUpload(options, args, cl, change)
2440 ret = RietveldUpload(options, args, cl, change) 2462 ret = RietveldUpload(options, args, cl, change)
2441 if not ret: 2463 if not ret:
2442 git_set_branch_value('last-upload-hash', 2464 git_set_branch_value('last-upload-hash',
2443 RunGit(['rev-parse', 'HEAD']).strip()) 2465 RunGit(['rev-parse', 'HEAD']).strip())
2444 # Run post upload hooks, if specified. 2466 # Run post upload hooks, if specified.
2445 if settings.GetRunPostUploadHook(): 2467 if settings.GetRunPostUploadHook():
2446 presubmit_support.DoPostUploadExecuter( 2468 presubmit_support.DoPostUploadExecuter(
2447 change, 2469 change,
2448 cl, 2470 cl,
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
3672 if __name__ == '__main__': 3694 if __name__ == '__main__':
3673 # These affect sys.stdout so do it outside of main() to simplify mocks in 3695 # These affect sys.stdout so do it outside of main() to simplify mocks in
3674 # unit testing. 3696 # unit testing.
3675 fix_encoding.fix_encoding() 3697 fix_encoding.fix_encoding()
3676 colorama.init() 3698 colorama.init()
3677 try: 3699 try:
3678 sys.exit(main(sys.argv[1:])) 3700 sys.exit(main(sys.argv[1:]))
3679 except KeyboardInterrupt: 3701 except KeyboardInterrupt:
3680 sys.stderr.write('interrupted\n') 3702 sys.stderr.write('interrupted\n')
3681 sys.exit(1) 3703 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698