mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Automatically guess Gerrit change number in "repo upload --replace"
This feature only works if you have one commit to replace right now (the common case).
This commit is contained in:
parent
2f968c943b
commit
bc7ef67d9b
13
project.py
13
project.py
@ -155,6 +155,19 @@ class ReviewableBranch(object):
|
|||||||
self.replace_changes,
|
self.replace_changes,
|
||||||
people)
|
people)
|
||||||
|
|
||||||
|
def GetPublishedRefs(self):
|
||||||
|
refs = {}
|
||||||
|
output = self.project.bare_git.ls_remote(
|
||||||
|
self.branch.remote.SshReviewUrl(self.project.UserEmail),
|
||||||
|
'refs/changes/*')
|
||||||
|
for line in output.split('\n'):
|
||||||
|
try:
|
||||||
|
(sha, ref) = line.split()
|
||||||
|
refs[sha] = ref
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return refs
|
||||||
|
|
||||||
class StatusColoring(Coloring):
|
class StatusColoring(Coloring):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
|
@ -194,6 +194,18 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
_die("nothing uncommented for upload")
|
_die("nothing uncommented for upload")
|
||||||
self._UploadAndReport(todo, people)
|
self._UploadAndReport(todo, people)
|
||||||
|
|
||||||
|
def _FindGerritChange(self, branch):
|
||||||
|
last_pub = branch.project.WasPublished(branch.name)
|
||||||
|
if last_pub is None:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
refs = branch.GetPublishedRefs()
|
||||||
|
try:
|
||||||
|
# refs/changes/XYZ/N --> XYZ
|
||||||
|
return refs.get(last_pub).split('/')[-2]
|
||||||
|
except:
|
||||||
|
return ""
|
||||||
|
|
||||||
def _ReplaceBranch(self, project, people):
|
def _ReplaceBranch(self, project, people):
|
||||||
branch = project.CurrentBranch
|
branch = project.CurrentBranch
|
||||||
if not branch:
|
if not branch:
|
||||||
@ -206,8 +218,14 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
|
|||||||
|
|
||||||
script = []
|
script = []
|
||||||
script.append('# Replacing from branch %s' % branch.name)
|
script.append('# Replacing from branch %s' % branch.name)
|
||||||
|
|
||||||
|
if len(branch.commits) == 1:
|
||||||
|
change = self._FindGerritChange(branch)
|
||||||
|
script.append('[%-6s] %s' % (change, branch.commits[0]))
|
||||||
|
else:
|
||||||
for commit in branch.commits:
|
for commit in branch.commits:
|
||||||
script.append('[ ] %s' % commit)
|
script.append('[ ] %s' % commit)
|
||||||
|
|
||||||
script.append('')
|
script.append('')
|
||||||
script.append('# Insert change numbers in the brackets to add a new patch set.')
|
script.append('# Insert change numbers in the brackets to add a new patch set.')
|
||||||
script.append('# To create a new change record, leave the brackets empty.')
|
script.append('# To create a new change record, leave the brackets empty.')
|
||||||
|
Loading…
Reference in New Issue
Block a user