OLD | NEW |
---|---|
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 2854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2865 @subcommand.usage('[upstream branch to apply against]') | 2865 @subcommand.usage('[upstream branch to apply against]') |
2866 def CMDland(parser, args): | 2866 def CMDland(parser, args): |
2867 """Commits the current changelist via git.""" | 2867 """Commits the current changelist via git.""" |
2868 if settings.GetIsGitSvn() or get_footer_svn_id(): | 2868 if settings.GetIsGitSvn() or get_footer_svn_id(): |
2869 print('This appears to be an SVN repository.') | 2869 print('This appears to be an SVN repository.') |
2870 print('Are you sure you didn\'t mean \'git cl dcommit\'?') | 2870 print('Are you sure you didn\'t mean \'git cl dcommit\'?') |
2871 print('(Ignore if this is the first commit after migrating from svn->git)') | 2871 print('(Ignore if this is the first commit after migrating from svn->git)') |
2872 ask_for_data('[Press enter to push or ctrl-C to quit]') | 2872 ask_for_data('[Press enter to push or ctrl-C to quit]') |
2873 return SendUpstream(parser, args, 'land') | 2873 return SendUpstream(parser, args, 'land') |
2874 | 2874 |
2875 def ParseIssueNum(arg): | |
scottmg
2015/09/23 19:17:03
nit; two blank lines between top level functions i
dsinclair
2015/09/23 19:22:28
Done.
Didn't see comments on the other ones, didn
| |
2876 if re.match(r'\d+', arg): | |
scottmg
2015/09/23 19:17:03
maybe
or args.endswith('.diff')
would be a saf
dsinclair
2015/09/23 19:22:28
It's not as easy to share in that case as the git
scottmg
2015/09/23 19:35:45
Oh, right. OK, lgtm then.
| |
2877 return arg | |
2878 if arg.startswith('http'): | |
2879 return re.sub(r'.*/(\d+)/?', r'\1', arg) | |
2880 return None | |
2875 | 2881 |
2876 @subcommand.usage('<patch url or issue id>') | 2882 @subcommand.usage('<patch url or issue id or issue url>') |
2877 def CMDpatch(parser, args): | 2883 def CMDpatch(parser, args): |
2878 """Patches in a code review.""" | 2884 """Patches in a code review.""" |
2879 parser.add_option('-b', dest='newbranch', | 2885 parser.add_option('-b', dest='newbranch', |
2880 help='create a new branch off trunk for the patch') | 2886 help='create a new branch off trunk for the patch') |
2881 parser.add_option('-f', '--force', action='store_true', | 2887 parser.add_option('-f', '--force', action='store_true', |
2882 help='with -b, clobber any existing branch') | 2888 help='with -b, clobber any existing branch') |
2883 parser.add_option('-d', '--directory', action='store', metavar='DIR', | 2889 parser.add_option('-d', '--directory', action='store', metavar='DIR', |
2884 help='Change to the directory DIR immediately, ' | 2890 help='Change to the directory DIR immediately, ' |
2885 'before doing anything else.') | 2891 'before doing anything else.') |
2886 parser.add_option('--reject', action='store_true', | 2892 parser.add_option('--reject', action='store_true', |
2887 help='failed patches spew .rej files rather than ' | 2893 help='failed patches spew .rej files rather than ' |
2888 'attempting a 3-way merge') | 2894 'attempting a 3-way merge') |
2889 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 2895 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', |
2890 help="don't commit after patch applies") | 2896 help="don't commit after patch applies") |
2891 auth.add_auth_options(parser) | 2897 auth.add_auth_options(parser) |
2892 (options, args) = parser.parse_args(args) | 2898 (options, args) = parser.parse_args(args) |
2893 auth_config = auth.extract_auth_config_from_options(options) | 2899 auth_config = auth.extract_auth_config_from_options(options) |
2894 | 2900 |
2895 if len(args) != 1: | 2901 if len(args) != 1: |
2896 parser.print_help() | 2902 parser.print_help() |
2897 return 1 | 2903 return 1 |
2898 issue_arg = args[0] | 2904 |
2905 issue_arg = ParseIssueNum(args[0]) | |
2906 # The patch URL works because ParseIssueNum won't do any substitution | |
2907 # as the re.sub pattern fails to match and just returns it. | |
2908 if issue_arg == None: | |
2909 parser.print_help() | |
2910 return 1 | |
2899 | 2911 |
2900 # We don't want uncommitted changes mixed up with the patch. | 2912 # We don't want uncommitted changes mixed up with the patch. |
2901 if git_common.is_dirty_git_tree('patch'): | 2913 if git_common.is_dirty_git_tree('patch'): |
2902 return 1 | 2914 return 1 |
2903 | 2915 |
2904 # TODO(maruel): Use apply_issue.py | 2916 # TODO(maruel): Use apply_issue.py |
2905 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? | 2917 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? |
2906 | 2918 |
2907 if options.newbranch: | 2919 if options.newbranch: |
2908 if options.force: | 2920 if options.force: |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3543 | 3555 |
3544 @subcommand.usage('<codereview url or issue id>') | 3556 @subcommand.usage('<codereview url or issue id>') |
3545 def CMDcheckout(parser, args): | 3557 def CMDcheckout(parser, args): |
3546 """Checks out a branch associated with a given Rietveld issue.""" | 3558 """Checks out a branch associated with a given Rietveld issue.""" |
3547 _, args = parser.parse_args(args) | 3559 _, args = parser.parse_args(args) |
3548 | 3560 |
3549 if len(args) != 1: | 3561 if len(args) != 1: |
3550 parser.print_help() | 3562 parser.print_help() |
3551 return 1 | 3563 return 1 |
3552 | 3564 |
3553 if re.match(r'\d+', args[0]): | 3565 target_issue = ParseIssueNum(args[0]) |
3554 target_issue = args[0] | 3566 if target_issue == None: |
3555 elif args[0].startswith('http'): | |
3556 target_issue = re.sub(r'.*/(\d+)/?', r'\1', args[0]) | |
3557 else: | |
3558 parser.print_help() | 3567 parser.print_help() |
3559 return 1 | 3568 return 1 |
3560 | 3569 |
3561 key_and_issues = [x.split() for x in RunGit( | 3570 key_and_issues = [x.split() for x in RunGit( |
3562 ['config', '--local', '--get-regexp', r'branch\..*\.rietveldissue']) | 3571 ['config', '--local', '--get-regexp', r'branch\..*\.rietveldissue']) |
3563 .splitlines()] | 3572 .splitlines()] |
3564 branches = [] | 3573 branches = [] |
3565 for key, issue in key_and_issues: | 3574 for key, issue in key_and_issues: |
3566 if issue == target_issue: | 3575 if issue == target_issue: |
3567 branches.append(re.sub(r'branch\.(.*)\.rietveldissue', r'\1', key)) | 3576 branches.append(re.sub(r'branch\.(.*)\.rietveldissue', r'\1', key)) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3640 if __name__ == '__main__': | 3649 if __name__ == '__main__': |
3641 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3650 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3642 # unit testing. | 3651 # unit testing. |
3643 fix_encoding.fix_encoding() | 3652 fix_encoding.fix_encoding() |
3644 colorama.init() | 3653 colorama.init() |
3645 try: | 3654 try: |
3646 sys.exit(main(sys.argv[1:])) | 3655 sys.exit(main(sys.argv[1:])) |
3647 except KeyboardInterrupt: | 3656 except KeyboardInterrupt: |
3648 sys.stderr.write('interrupted\n') | 3657 sys.stderr.write('interrupted\n') |
3649 sys.exit(1) | 3658 sys.exit(1) |
OLD | NEW |