From fbed6568a95526f45c946cc702caca8a27f213b5 Mon Sep 17 00:00:00 2001 From: "dsinclair@chromium.org" Date: Fri, 25 Sep 2015 21:22:36 +0000 Subject: [PATCH] Allow using issue URL for git cl patch. This CL allows passing the Rietveld URL to git cl patch along with the CL number or patch URL. Review URL: https://codereview.chromium.org/1363043002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@296889 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/git_cl.py b/git_cl.py index b981b8f76..2f88d0b4a 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2885,7 +2885,16 @@ def CMDland(parser, args): return SendUpstream(parser, args, 'land') -@subcommand.usage('') +def ParseIssueNum(arg): + """Parses the issue number from args if present otherwise returns None.""" + if re.match(r'\d+', arg): + return arg + if arg.startswith('http'): + return re.sub(r'.*/(\d+)/?', r'\1', arg) + return None + + +@subcommand.usage('') def CMDpatch(parser, args): """Patches in a code review.""" parser.add_option('-b', dest='newbranch', @@ -2907,7 +2916,13 @@ def CMDpatch(parser, args): if len(args) != 1: parser.print_help() return 1 - issue_arg = args[0] + + issue_arg = ParseIssueNum(args[0]) + # The patch URL works because ParseIssueNum won't do any substitution + # as the re.sub pattern fails to match and just returns it. + if issue_arg == None: + parser.print_help() + return 1 # We don't want uncommitted changes mixed up with the patch. if git_common.is_dirty_git_tree('patch'): @@ -3565,11 +3580,8 @@ def CMDcheckout(parser, args): parser.print_help() return 1 - if re.match(r'\d+', args[0]): - target_issue = args[0] - elif args[0].startswith('http'): - target_issue = re.sub(r'.*/(\d+)/?', r'\1', args[0]) - else: + target_issue = ParseIssueNum(args[0]) + if target_issue == None: parser.print_help() return 1