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

Side by Side Diff: git_cl.py

Issue 1357213003: Add `git cl checkout` to checkout by Rietveld issue (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: . Created 5 years, 2 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.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 3523 matching lines...) Expand 10 before | Expand all | Expand 10 after
3534 stdout = RunCommand(command, cwd=top_dir, env=env) 3534 stdout = RunCommand(command, cwd=top_dir, env=env)
3535 if opts.dry_run and stdout: 3535 if opts.dry_run and stdout:
3536 return_value = 2 3536 return_value = 2
3537 except dart_format.NotFoundError as e: 3537 except dart_format.NotFoundError as e:
3538 print ('Unable to check dart code formatting. Dart SDK is not in ' + 3538 print ('Unable to check dart code formatting. Dart SDK is not in ' +
3539 'this checkout.') 3539 'this checkout.')
3540 3540
3541 return return_value 3541 return return_value
3542 3542
3543 3543
3544 @subcommand.usage('<codereview url or issue id>')
3545 def CMDcheckout(parser, args):
3546 """Checks out a branch associated with a given Rietveld issue."""
3547 _, args = parser.parse_args(args)
3548
3549 if len(args) != 1:
3550 parser.print_help()
3551 return 1
3552
3553 if re.match(r'\d+', args[0]):
3554 target_issue = args[0]
3555 elif args[0].startswith('http'):
3556 target_issue = re.sub(r'.*/(\d+)/?', r'\1', args[0])
3557 else:
3558 parser.print_help()
3559 return 1
3560
3561 key_and_issues = [x.split() for x in RunGit(
3562 ['config', '--local', '--get-regexp', r'branch\..*\.rietveldissue'])
3563 .splitlines()]
3564 branches = []
3565 for key, issue in key_and_issues:
3566 if issue == target_issue:
3567 branches.append(re.sub(r'branch\.(.*)\.rietveldissue', r'\1', key))
3568
3569 if len(branches) == 0:
3570 print 'No branch found for issue %s.' % target_issue
3571 return 1
3572 if len(branches) == 1:
3573 RunGit(['checkout', branches[0]])
3574 else:
3575 print 'Multiple branches match issue %s:' % target_issue
3576 for i in range(len(branches)):
3577 print '%d: %s' % (i, branches[i])
3578 which = raw_input('Choose by index: ')
3579 try:
3580 RunGit(['checkout', branches[int(which)]])
3581 except (IndexError, ValueError):
3582 print 'Invalid selection, not checking out any branch.'
3583 return 1
3584
3585 return 0
3586
3587
3544 def CMDlol(parser, args): 3588 def CMDlol(parser, args):
3545 # This command is intentionally undocumented. 3589 # This command is intentionally undocumented.
3546 print zlib.decompress(base64.b64decode( 3590 print zlib.decompress(base64.b64decode(
3547 'eNptkLEOwyAMRHe+wupCIqW57v0Vq84WqWtXyrcXnCBsmgMJ+/SSAxMZgRB6NzE' 3591 'eNptkLEOwyAMRHe+wupCIqW57v0Vq84WqWtXyrcXnCBsmgMJ+/SSAxMZgRB6NzE'
3548 'E2ObgCKJooYdu4uAQVffUEoE1sRQLxAcqzd7uK2gmStrll1ucV3uZyaY5sXyDd9' 3592 'E2ObgCKJooYdu4uAQVffUEoE1sRQLxAcqzd7uK2gmStrll1ucV3uZyaY5sXyDd9'
3549 'JAnN+lAXsOMJ90GANAi43mq5/VeeacylKVgi8o6F1SC63FxnagHfJUTfUYdCR/W' 3593 'JAnN+lAXsOMJ90GANAi43mq5/VeeacylKVgi8o6F1SC63FxnagHfJUTfUYdCR/W'
3550 'Ofe+0dHL7PicpytKP750Fh1q2qnLVof4w8OZWNY')) 3594 'Ofe+0dHL7PicpytKP750Fh1q2qnLVof4w8OZWNY'))
3551 return 0 3595 return 0
3552 3596
3553 3597
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3596 if __name__ == '__main__': 3640 if __name__ == '__main__':
3597 # These affect sys.stdout so do it outside of main() to simplify mocks in 3641 # These affect sys.stdout so do it outside of main() to simplify mocks in
3598 # unit testing. 3642 # unit testing.
3599 fix_encoding.fix_encoding() 3643 fix_encoding.fix_encoding()
3600 colorama.init() 3644 colorama.init()
3601 try: 3645 try:
3602 sys.exit(main(sys.argv[1:])) 3646 sys.exit(main(sys.argv[1:]))
3603 except KeyboardInterrupt: 3647 except KeyboardInterrupt:
3604 sys.stderr.write('interrupted\n') 3648 sys.stderr.write('interrupted\n')
3605 sys.exit(1) 3649 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