summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--project.py13
-rw-r--r--subcmds/upload.py22
2 files changed, 33 insertions, 2 deletions
diff --git a/project.py b/project.py
index a698b316..1d908e7f 100644
--- a/project.py
+++ b/project.py
@@ -155,6 +155,19 @@ class ReviewableBranch(object):
155 self.replace_changes, 155 self.replace_changes,
156 people) 156 people)
157 157
158 def GetPublishedRefs(self):
159 refs = {}
160 output = self.project.bare_git.ls_remote(
161 self.branch.remote.SshReviewUrl(self.project.UserEmail),
162 'refs/changes/*')
163 for line in output.split('\n'):
164 try:
165 (sha, ref) = line.split()
166 refs[sha] = ref
167 except ValueError:
168 pass
169
170 return refs
158 171
159class StatusColoring(Coloring): 172class StatusColoring(Coloring):
160 def __init__(self, config): 173 def __init__(self, config):
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 01ba4ad0..aea399b6 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -194,6 +194,18 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
194 _die("nothing uncommented for upload") 194 _die("nothing uncommented for upload")
195 self._UploadAndReport(todo, people) 195 self._UploadAndReport(todo, people)
196 196
197 def _FindGerritChange(self, branch):
198 last_pub = branch.project.WasPublished(branch.name)
199 if last_pub is None:
200 return ""
201
202 refs = branch.GetPublishedRefs()
203 try:
204 # refs/changes/XYZ/N --> XYZ
205 return refs.get(last_pub).split('/')[-2]
206 except:
207 return ""
208
197 def _ReplaceBranch(self, project, people): 209 def _ReplaceBranch(self, project, people):
198 branch = project.CurrentBranch 210 branch = project.CurrentBranch
199 if not branch: 211 if not branch:
@@ -206,8 +218,14 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
206 218
207 script = [] 219 script = []
208 script.append('# Replacing from branch %s' % branch.name) 220 script.append('# Replacing from branch %s' % branch.name)
209 for commit in branch.commits: 221
210 script.append('[ ] %s' % commit) 222 if len(branch.commits) == 1:
223 change = self._FindGerritChange(branch)
224 script.append('[%-6s] %s' % (change, branch.commits[0]))
225 else:
226 for commit in branch.commits:
227 script.append('[ ] %s' % commit)
228
211 script.append('') 229 script.append('')
212 script.append('# Insert change numbers in the brackets to add a new patch set.') 230 script.append('# Insert change numbers in the brackets to add a new patch set.')
213 script.append('# To create a new change record, leave the brackets empty.') 231 script.append('# To create a new change record, leave the brackets empty.')