Chromium Code Reviews

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, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« 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...)
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 CMDco(parser, args):
Dirk Pranke 2015/09/22 17:52:34 it seems like this should probably be CMDcheckout,
scottmg 2015/09/22 17:57:23 Done.
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) == 1:
3570 RunGit(['checkout', branches[0]])
3571 else:
Dirk Pranke 2015/09/22 17:52:34 what if there's no match?
scottmg 2015/09/22 17:57:23 Done.
3572 print 'Multiple branches match issue %s:' % target_issue
3573 for i in range(len(branches)):
3574 print '%d: %s' % (i, branches[i])
3575 which = raw_input('Choose by index: ')
3576 try:
3577 RunGit(['checkout', branches[int(which)]])
3578 except (IndexError, ValueError):
3579 print 'Invalid selection, not checking out any branch.'
3580 return 1
3581
3582 cl = Changelist()
3583 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL())
Dirk Pranke 2015/09/22 17:52:34 Why print anything? You told it the issue number o
scottmg 2015/09/22 17:57:23 Done.
3584 return 0
3585
3586
3544 def CMDlol(parser, args): 3587 def CMDlol(parser, args):
3545 # This command is intentionally undocumented. 3588 # This command is intentionally undocumented.
3546 print zlib.decompress(base64.b64decode( 3589 print zlib.decompress(base64.b64decode(
3547 'eNptkLEOwyAMRHe+wupCIqW57v0Vq84WqWtXyrcXnCBsmgMJ+/SSAxMZgRB6NzE' 3590 'eNptkLEOwyAMRHe+wupCIqW57v0Vq84WqWtXyrcXnCBsmgMJ+/SSAxMZgRB6NzE'
3548 'E2ObgCKJooYdu4uAQVffUEoE1sRQLxAcqzd7uK2gmStrll1ucV3uZyaY5sXyDd9' 3591 'E2ObgCKJooYdu4uAQVffUEoE1sRQLxAcqzd7uK2gmStrll1ucV3uZyaY5sXyDd9'
3549 'JAnN+lAXsOMJ90GANAi43mq5/VeeacylKVgi8o6F1SC63FxnagHfJUTfUYdCR/W' 3592 'JAnN+lAXsOMJ90GANAi43mq5/VeeacylKVgi8o6F1SC63FxnagHfJUTfUYdCR/W'
3550 'Ofe+0dHL7PicpytKP750Fh1q2qnLVof4w8OZWNY')) 3593 'Ofe+0dHL7PicpytKP750Fh1q2qnLVof4w8OZWNY'))
3551 return 0 3594 return 0
3552 3595
3553 3596
(...skipping 42 matching lines...)
3596 if __name__ == '__main__': 3639 if __name__ == '__main__':
3597 # These affect sys.stdout so do it outside of main() to simplify mocks in 3640 # These affect sys.stdout so do it outside of main() to simplify mocks in
3598 # unit testing. 3641 # unit testing.
3599 fix_encoding.fix_encoding() 3642 fix_encoding.fix_encoding()
3600 colorama.init() 3643 colorama.init()
3601 try: 3644 try:
3602 sys.exit(main(sys.argv[1:])) 3645 sys.exit(main(sys.argv[1:]))
3603 except KeyboardInterrupt: 3646 except KeyboardInterrupt:
3604 sys.stderr.write('interrupted\n') 3647 sys.stderr.write('interrupted\n')
3605 sys.exit(1) 3648 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