Parcourir la source

Download latest patch when no patch is specified

When someone does "repo download -c <project> <change>"
without specifying a patch number, by default patch 1 is
downloaded. An alternative is to look for the latest patch
and download the same when no explicit patch is given.
This commit does the same by identifying the latest patch
using "git ls-remote".

Change-Id: Ia5fa7364415f53a3d9436df4643e38f3c90ded58
Akshay Verma il y a 8 ans
Parent
commit
cf7c0834cf
2 fichiers modifiés avec 18 ajouts et 0 suppressions
  1. 10 0
      project.py
  2. 8 0
      subcmds/download.py

+ 10 - 0
project.py

@@ -2270,6 +2270,16 @@ class Project(object):
       if self._allrefs:
       if self._allrefs:
         raise GitError('%s cherry-pick %s ' % (self.name, rev))
         raise GitError('%s cherry-pick %s ' % (self.name, rev))
 
 
+  def _LsRemote(self):
+    cmd = ['ls-remote']
+    p = GitCommand(self, cmd, capture_stdout=True)
+    if p.Wait() == 0:
+      if hasattr(p.stdout, 'decode'):
+        return p.stdout.decode('utf-8')
+      else:
+        return p.stdout
+    return None
+
   def _Revert(self, rev):
   def _Revert(self, rev):
     cmd = ['revert']
     cmd = ['revert']
     cmd.append('--no-edit')
     cmd.append('--no-edit')

+ 8 - 0
subcmds/download.py

@@ -62,6 +62,14 @@ If no project is specified try to use current directory as a project.
           ps_id = int(m.group(2))
           ps_id = int(m.group(2))
         else:
         else:
           ps_id = 1
           ps_id = 1
+          regex = r'refs/changes/%2.2d/%d/(\d+)' % (chg_id % 100, chg_id)
+          output = project._LsRemote()
+          if output:
+            rcomp = re.compile(regex, re.I)
+            for line in output.splitlines():
+              match = rcomp.search(line)
+              if match:
+                ps_id = max(int(match.group(1)), ps_id)
         to_get.append((project, chg_id, ps_id))
         to_get.append((project, chg_id, ps_id))
       else:
       else:
         project = self.GetProjects([a])[0]
         project = self.GetProjects([a])[0]