summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkshay Verma <akshayverma948@gmail.com>2018-03-15 21:56:30 +0530
committerAkshay Verma <akshayverma948@gmail.com>2018-03-17 16:29:23 +0530
commitcf7c0834cfc24c5c9584695c657c6baf97d0fbb3 (patch)
tree49be7db9b2f7b0e0cf9026a84b81716ddfc66034
parent4ea1f0cabdda28fdee837ee2f99e14375028b5f4 (diff)
downloadgit-repo-cf7c0834cfc24c5c9584695c657c6baf97d0fbb3.tar.gz
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
-rwxr-xr-x[-rw-r--r--]project.py10
-rwxr-xr-x[-rw-r--r--]subcmds/download.py8
2 files changed, 18 insertions, 0 deletions
diff --git a/project.py b/project.py
index e4682e6a..5297a5cb 100644..100755
--- a/project.py
+++ b/project.py
@@ -2270,6 +2270,16 @@ class Project(object):
2270 if self._allrefs: 2270 if self._allrefs:
2271 raise GitError('%s cherry-pick %s ' % (self.name, rev)) 2271 raise GitError('%s cherry-pick %s ' % (self.name, rev))
2272 2272
2273 def _LsRemote(self):
2274 cmd = ['ls-remote']
2275 p = GitCommand(self, cmd, capture_stdout=True)
2276 if p.Wait() == 0:
2277 if hasattr(p.stdout, 'decode'):
2278 return p.stdout.decode('utf-8')
2279 else:
2280 return p.stdout
2281 return None
2282
2273 def _Revert(self, rev): 2283 def _Revert(self, rev):
2274 cmd = ['revert'] 2284 cmd = ['revert']
2275 cmd.append('--no-edit') 2285 cmd.append('--no-edit')
diff --git a/subcmds/download.py b/subcmds/download.py
index e1010aa2..384af781 100644..100755
--- a/subcmds/download.py
+++ b/subcmds/download.py
@@ -62,6 +62,14 @@ If no project is specified try to use current directory as a project.
62 ps_id = int(m.group(2)) 62 ps_id = int(m.group(2))
63 else: 63 else:
64 ps_id = 1 64 ps_id = 1
65 regex = r'refs/changes/%2.2d/%d/(\d+)' % (chg_id % 100, chg_id)
66 output = project._LsRemote()
67 if output:
68 rcomp = re.compile(regex, re.I)
69 for line in output.splitlines():
70 match = rcomp.search(line)
71 if match:
72 ps_id = max(int(match.group(1)), ps_id)
65 to_get.append((project, chg_id, ps_id)) 73 to_get.append((project, chg_id, ps_id))
66 else: 74 else:
67 project = self.GetProjects([a])[0] 75 project = self.GetProjects([a])[0]