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 2855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 2875 |
2876 @subcommand.usage('<patch url or issue id>') | 2876 def ParseIssueNum(arg): |
| 2877 """Parses the issue number from args if present otherwise returns None.""" |
| 2878 if re.match(r'\d+', arg): |
| 2879 return arg |
| 2880 if arg.startswith('http'): |
| 2881 return re.sub(r'.*/(\d+)/?', r'\1', arg) |
| 2882 return None |
| 2883 |
| 2884 |
| 2885 @subcommand.usage('<patch url or issue id or issue url>') |
2877 def CMDpatch(parser, args): | 2886 def CMDpatch(parser, args): |
2878 """Patches in a code review.""" | 2887 """Patches in a code review.""" |
2879 parser.add_option('-b', dest='newbranch', | 2888 parser.add_option('-b', dest='newbranch', |
2880 help='create a new branch off trunk for the patch') | 2889 help='create a new branch off trunk for the patch') |
2881 parser.add_option('-f', '--force', action='store_true', | 2890 parser.add_option('-f', '--force', action='store_true', |
2882 help='with -b, clobber any existing branch') | 2891 help='with -b, clobber any existing branch') |
2883 parser.add_option('-d', '--directory', action='store', metavar='DIR', | 2892 parser.add_option('-d', '--directory', action='store', metavar='DIR', |
2884 help='Change to the directory DIR immediately, ' | 2893 help='Change to the directory DIR immediately, ' |
2885 'before doing anything else.') | 2894 'before doing anything else.') |
2886 parser.add_option('--reject', action='store_true', | 2895 parser.add_option('--reject', action='store_true', |
2887 help='failed patches spew .rej files rather than ' | 2896 help='failed patches spew .rej files rather than ' |
2888 'attempting a 3-way merge') | 2897 'attempting a 3-way merge') |
2889 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 2898 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', |
2890 help="don't commit after patch applies") | 2899 help="don't commit after patch applies") |
2891 auth.add_auth_options(parser) | 2900 auth.add_auth_options(parser) |
2892 (options, args) = parser.parse_args(args) | 2901 (options, args) = parser.parse_args(args) |
2893 auth_config = auth.extract_auth_config_from_options(options) | 2902 auth_config = auth.extract_auth_config_from_options(options) |
2894 | 2903 |
2895 if len(args) != 1: | 2904 if len(args) != 1: |
2896 parser.print_help() | 2905 parser.print_help() |
2897 return 1 | 2906 return 1 |
2898 issue_arg = args[0] | 2907 |
| 2908 issue_arg = ParseIssueNum(args[0]) |
| 2909 # The patch URL works because ParseIssueNum won't do any substitution |
| 2910 # as the re.sub pattern fails to match and just returns it. |
| 2911 if issue_arg == None: |
| 2912 parser.print_help() |
| 2913 return 1 |
2899 | 2914 |
2900 # We don't want uncommitted changes mixed up with the patch. | 2915 # We don't want uncommitted changes mixed up with the patch. |
2901 if git_common.is_dirty_git_tree('patch'): | 2916 if git_common.is_dirty_git_tree('patch'): |
2902 return 1 | 2917 return 1 |
2903 | 2918 |
2904 # TODO(maruel): Use apply_issue.py | 2919 # TODO(maruel): Use apply_issue.py |
2905 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? | 2920 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? |
2906 | 2921 |
2907 if options.newbranch: | 2922 if options.newbranch: |
2908 if options.force: | 2923 if options.force: |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3543 | 3558 |
3544 @subcommand.usage('<codereview url or issue id>') | 3559 @subcommand.usage('<codereview url or issue id>') |
3545 def CMDcheckout(parser, args): | 3560 def CMDcheckout(parser, args): |
3546 """Checks out a branch associated with a given Rietveld issue.""" | 3561 """Checks out a branch associated with a given Rietveld issue.""" |
3547 _, args = parser.parse_args(args) | 3562 _, args = parser.parse_args(args) |
3548 | 3563 |
3549 if len(args) != 1: | 3564 if len(args) != 1: |
3550 parser.print_help() | 3565 parser.print_help() |
3551 return 1 | 3566 return 1 |
3552 | 3567 |
3553 if re.match(r'\d+', args[0]): | 3568 target_issue = ParseIssueNum(args[0]) |
3554 target_issue = args[0] | 3569 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() | 3570 parser.print_help() |
3559 return 1 | 3571 return 1 |
3560 | 3572 |
3561 key_and_issues = [x.split() for x in RunGit( | 3573 key_and_issues = [x.split() for x in RunGit( |
3562 ['config', '--local', '--get-regexp', r'branch\..*\.rietveldissue']) | 3574 ['config', '--local', '--get-regexp', r'branch\..*\.rietveldissue']) |
3563 .splitlines()] | 3575 .splitlines()] |
3564 branches = [] | 3576 branches = [] |
3565 for key, issue in key_and_issues: | 3577 for key, issue in key_and_issues: |
3566 if issue == target_issue: | 3578 if issue == target_issue: |
3567 branches.append(re.sub(r'branch\.(.*)\.rietveldissue', r'\1', key)) | 3579 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__': | 3652 if __name__ == '__main__': |
3641 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3653 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3642 # unit testing. | 3654 # unit testing. |
3643 fix_encoding.fix_encoding() | 3655 fix_encoding.fix_encoding() |
3644 colorama.init() | 3656 colorama.init() |
3645 try: | 3657 try: |
3646 sys.exit(main(sys.argv[1:])) | 3658 sys.exit(main(sys.argv[1:])) |
3647 except KeyboardInterrupt: | 3659 except KeyboardInterrupt: |
3648 sys.stderr.write('interrupted\n') | 3660 sys.stderr.write('interrupted\n') |
3649 sys.exit(1) | 3661 sys.exit(1) |
OLD | NEW |