Running git cl patch sets the rietveld patchset.

BUG=none


Review URL: https://chromiumcodereview.appspot.com/10907229

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@156796 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cl.py b/git_cl.py
index e894f08..29ee421 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -509,9 +509,11 @@
              stderr=subprocess2.PIPE, error_ok=True)
     self.has_patchset = False
 
-  def GetPatchSetDiff(self, issue):
-    patchset = self.RpcServer().get_issue_properties(
+  def GetMostRecentPatchset(self, issue):
+    return self.RpcServer().get_issue_properties(
         int(issue), False)['patchsets'][-1]
+
+  def GetPatchSetDiff(self, issue, patchset):
     return self.RpcServer().get(
         '/download/issue%s_%s.diff' % (issue, patchset))
 
@@ -1403,16 +1405,19 @@
 
   if issue_arg.isdigit():
     # Input is an issue id.  Figure out the URL.
+    cl = Changelist()
     issue = int(issue_arg)
-    patch_data = Changelist().GetPatchSetDiff(issue)
+    patchset = cl.GetMostRecentPatchset(issue)
+    patch_data = cl.GetPatchSetDiff(issue, patchset)
   else:
     # Assume it's a URL to the patch. Default to https.
     issue_url = gclient_utils.UpgradeToHttps(issue_arg)
-    match = re.match(r'.*?/issue(\d+)_\d+.diff', issue_url)
+    match = re.match(r'.*?/issue(\d+)_(\d+).diff', issue_url)
     if not match:
       DieWithError('Must pass an issue ID or full URL for '
           '\'Download raw patch set\'')
     issue = int(match.group(1))
+    patchset = int(match.group(2))
     patch_data = urllib2.urlopen(issue_arg).read()
 
   if options.newbranch:
@@ -1454,6 +1459,7 @@
     RunGit(['commit', '-m', 'patch from issue %s' % issue])
     cl = Changelist()
     cl.SetIssue(issue)
+    cl.SetPatchset(patchset)
     print "Committed patch."
   else:
     print "Patch applied to index."
@@ -1587,8 +1593,7 @@
 
   patchset = cl.GetPatchset()
   if not cl.GetPatchset():
-    properties = cl.RpcServer().get_issue_properties(cl.GetIssue(), False)
-    patchset = properties['patchsets'][-1]
+    patchset = cl.GetMostRecentPatchset(cl.GetIssue())
 
   cl.RpcServer().trigger_try_jobs(
       cl.GetIssue(), patchset, options.name, options.clobber, options.revision,