diff options
author | Shawn O. Pearce <sop@google.com> | 2008-11-11 17:12:43 -0800 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2008-11-12 09:12:19 -0800 |
commit | c99883fee990a1baa7e0bf5f854c7485b7d0f0d9 (patch) | |
tree | 870cfd73b1fc2faf53da6d613ae820984695b305 /subcmds/upload.py | |
parent | ec18b4bac4f3c0760c26e83b8ade01ad1c815a9b (diff) | |
download | git-repo-c99883fee990a1baa7e0bf5f854c7485b7d0f0d9.tar.gz |
Teach 'repo upload --replace' how to add replacement patch setsv1.3
Users are prompted with the list of known changes we are about
to upload, and they can fill out the current change numbers for
any changes which already exist in the data store. For each of
those changes the change number and commit id is sent as part of
the upload request, so Gerrit can insert the new commit as a new
patch set of the existing change, rather than make a new change.
This facility permits developers to replace a patch so they can
address comments made on a prior version of the same change.
Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'subcmds/upload.py')
-rw-r--r-- | subcmds/upload.py | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py index 9018455f..11f035d7 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
@@ -29,7 +29,7 @@ class Upload(InteractiveCommand): | |||
29 | common = True | 29 | common = True |
30 | helpSummary = "Upload changes for code review" | 30 | helpSummary = "Upload changes for code review" |
31 | helpUsage=""" | 31 | helpUsage=""" |
32 | %prog [<project>]... | 32 | %prog {[<project>]... | --replace <project>} |
33 | """ | 33 | """ |
34 | helpDescription = """ | 34 | helpDescription = """ |
35 | The '%prog' command is used to send changes to the Gerrit code | 35 | The '%prog' command is used to send changes to the Gerrit code |
@@ -46,6 +46,11 @@ no projects are specified, '%prog' will search for uploadable | |||
46 | changes in all projects listed in the manifest. | 46 | changes in all projects listed in the manifest. |
47 | """ | 47 | """ |
48 | 48 | ||
49 | def _Options(self, p): | ||
50 | p.add_option('--replace', | ||
51 | dest='replace', action='store_true', | ||
52 | help='Upload replacement patchesets from this branch') | ||
53 | |||
49 | def _SingleBranch(self, branch): | 54 | def _SingleBranch(self, branch): |
50 | project = branch.project | 55 | project = branch.project |
51 | name = branch.name | 56 | name = branch.name |
@@ -129,6 +134,50 @@ changes in all projects listed in the manifest. | |||
129 | _die("nothing uncommented for upload") | 134 | _die("nothing uncommented for upload") |
130 | self._UploadAndReport(todo) | 135 | self._UploadAndReport(todo) |
131 | 136 | ||
137 | def _ReplaceBranch(self, project): | ||
138 | branch = project.CurrentBranch | ||
139 | if not branch: | ||
140 | print >>sys.stdout, "no branches ready for upload" | ||
141 | return | ||
142 | branch = project.GetUploadableBranch(branch) | ||
143 | if not branch: | ||
144 | print >>sys.stdout, "no branches ready for upload" | ||
145 | return | ||
146 | |||
147 | script = [] | ||
148 | script.append('# Replacing from branch %s' % branch.name) | ||
149 | for commit in branch.commits: | ||
150 | script.append('[ ] %s' % commit) | ||
151 | script.append('') | ||
152 | script.append('# Insert change numbers in the brackets to add a new patch set.') | ||
153 | script.append('# To create a new change record, leave the brackets empty.') | ||
154 | |||
155 | script = Editor.EditString("\n".join(script)).split("\n") | ||
156 | |||
157 | change_re = re.compile(r'^\[\s*(\d{1,})\s*\]\s*([0-9a-f]{1,}) .*$') | ||
158 | to_replace = dict() | ||
159 | full_hashes = branch.unabbrev_commits | ||
160 | |||
161 | for line in script: | ||
162 | m = change_re.match(line) | ||
163 | if m: | ||
164 | f = m.group(2) | ||
165 | try: | ||
166 | f = full_hashes[f] | ||
167 | except KeyError: | ||
168 | print 'fh = %s' % full_hashes | ||
169 | print >>sys.stderr, "error: commit %s not found" % f | ||
170 | sys.exit(1) | ||
171 | to_replace[m.group(1)] = f | ||
172 | |||
173 | if not to_replace: | ||
174 | print >>sys.stderr, "error: no replacements specified" | ||
175 | print >>sys.stderr, " use 'repo upload' without --replace" | ||
176 | sys.exit(1) | ||
177 | |||
178 | branch.replace_changes = to_replace | ||
179 | self._UploadAndReport([branch]) | ||
180 | |||
132 | def _UploadAndReport(self, todo): | 181 | def _UploadAndReport(self, todo): |
133 | have_errors = False | 182 | have_errors = False |
134 | for branch in todo: | 183 | for branch in todo: |
@@ -168,6 +217,14 @@ changes in all projects listed in the manifest. | |||
168 | project_list = self.GetProjects(args) | 217 | project_list = self.GetProjects(args) |
169 | pending = [] | 218 | pending = [] |
170 | 219 | ||
220 | if opt.replace: | ||
221 | if len(project_list) != 1: | ||
222 | print >>sys.stderr, \ | ||
223 | 'error: --replace requires exactly one project' | ||
224 | sys.exit(1) | ||
225 | self._ReplaceBranch(project_list[0]) | ||
226 | return | ||
227 | |||
171 | for project in project_list: | 228 | for project in project_list: |
172 | avail = project.GetUploadableBranches() | 229 | avail = project.GetUploadableBranches() |
173 | if avail: | 230 | if avail: |