Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tools/push-to-trunk/merge_to_branch.py

Issue 178223011: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/push-to-trunk/git_recipes.py ('k') | tools/push-to-trunk/push_to_trunk.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2014 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following
11 # disclaimer in the documentation and/or other materials provided
12 # with the distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived
15 # from this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 from collections import OrderedDict
30 import optparse
31 import sys
32
33 from common_includes import *
34
35 ALREADY_MERGING_SENTINEL_FILE = "ALREADY_MERGING_SENTINEL_FILE"
36 COMMIT_HASHES_FILE = "COMMIT_HASHES_FILE"
37 TEMPORARY_PATCH_FILE = "TEMPORARY_PATCH_FILE"
38
39 CONFIG = {
40 BRANCHNAME: "prepare-merge",
41 PERSISTFILE_BASENAME: "/tmp/v8-merge-to-branch-tempfile",
42 ALREADY_MERGING_SENTINEL_FILE:
43 "/tmp/v8-merge-to-branch-tempfile-already-merging",
44 TEMP_BRANCH: "prepare-merge-temporary-branch-created-by-script",
45 DOT_GIT_LOCATION: ".git",
46 VERSION_FILE: "src/version.cc",
47 TEMPORARY_PATCH_FILE: "/tmp/v8-prepare-merge-tempfile-temporary-patch",
48 COMMITMSG_FILE: "/tmp/v8-prepare-merge-tempfile-commitmsg",
49 COMMIT_HASHES_FILE: "/tmp/v8-merge-to-branch-tempfile-PATCH_COMMIT_HASHES",
50 }
51
52
53 class MergeToBranchOptions(CommonOptions):
54 def __init__(self, options, args):
55 super(MergeToBranchOptions, self).__init__(options, True)
56 self.requires_editor = True
57 self.wait_for_lgtm = True
58 self.delete_sentinel = options.f
59 self.message = getattr(options, "message", "")
60 self.revert = getattr(options, "r", False)
61 self.revert_bleeding_edge = getattr(options, "revert_bleeding_edge", False)
62 self.patch = getattr(options, "p", "")
63 self.args = args
64
65
66 class Preparation(Step):
67 MESSAGE = "Preparation."
68
69 def RunStep(self):
70 if os.path.exists(self.Config(ALREADY_MERGING_SENTINEL_FILE)):
71 if self._options.delete_sentinel:
72 os.remove(self.Config(ALREADY_MERGING_SENTINEL_FILE))
73 elif self._options.s == 0:
74 self.Die("A merge is already in progress")
75 open(self.Config(ALREADY_MERGING_SENTINEL_FILE), "a").close()
76
77 self.InitialEnvironmentChecks()
78 if self._options.revert_bleeding_edge:
79 self["merge_to_branch"] = "bleeding_edge"
80 elif self._options.args[0]:
81 self["merge_to_branch"] = self._options.args[0]
82 self._options.args = self._options.args[1:]
83 else:
84 self.Die("Please specify a branch to merge to")
85
86 self.CommonPrepare()
87 self.PrepareBranch()
88
89
90 class CreateBranch(Step):
91 MESSAGE = "Create a fresh branch for the patch."
92
93 def RunStep(self):
94 self.GitCreateBranch(self.Config(BRANCHNAME),
95 "svn/%s" % self["merge_to_branch"])
96
97
98 class SearchArchitecturePorts(Step):
99 MESSAGE = "Search for corresponding architecture ports."
100
101 def RunStep(self):
102 self["full_revision_list"] = list(OrderedDict.fromkeys(self._options.args))
103 port_revision_list = []
104 for revision in self["full_revision_list"]:
105 # Search for commits which matches the "Port rXXX" pattern.
106 git_hashes = self.GitLog(reverse=True, format="%H",
107 grep="Port r%d" % int(revision),
108 branch="svn/bleeding_edge")
109 for git_hash in git_hashes.splitlines():
110 svn_revision = self.GitSVNFindSVNRev(git_hash, "svn/bleeding_edge")
111 if not svn_revision:
112 self.Die("Cannot determine svn revision for %s" % git_hash)
113 revision_title = self.GitLog(n=1, format="%s", git_hash=git_hash)
114
115 # Is this revision included in the original revision list?
116 if svn_revision in self["full_revision_list"]:
117 print("Found port of r%s -> r%s (already included): %s"
118 % (revision, svn_revision, revision_title))
119 else:
120 print("Found port of r%s -> r%s: %s"
121 % (revision, svn_revision, revision_title))
122 port_revision_list.append(svn_revision)
123
124 # Do we find any port?
125 if len(port_revision_list) > 0:
126 if self.Confirm("Automatically add corresponding ports (%s)?"
127 % ", ".join(port_revision_list)):
128 #: 'y': Add ports to revision list.
129 self["full_revision_list"].extend(port_revision_list)
130
131
132 class FindGitRevisions(Step):
133 MESSAGE = "Find the git revisions associated with the patches."
134
135 def RunStep(self):
136 self["patch_commit_hashes"] = []
137 for revision in self["full_revision_list"]:
138 next_hash = self.GitSVNFindGitHash(revision, "svn/bleeding_edge")
139 if not next_hash:
140 self.Die("Cannot determine git hash for r%s" % revision)
141 self["patch_commit_hashes"].append(next_hash)
142
143 # Stringify: [123, 234] -> "r123, r234"
144 self["revision_list"] = ", ".join(map(lambda s: "r%s" % s,
145 self["full_revision_list"]))
146
147 if not self["revision_list"]:
148 self.Die("Revision list is empty.")
149
150 if self._options.revert:
151 if not self._options.revert_bleeding_edge:
152 self["new_commit_msg"] = ("Rollback of %s in %s branch."
153 % (self["revision_list"], self["merge_to_branch"]))
154 else:
155 self["new_commit_msg"] = "Revert %s." % self["revision_list"]
156 else:
157 self["new_commit_msg"] = ("Merged %s into %s branch."
158 % (self["revision_list"], self["merge_to_branch"]))
159 self["new_commit_msg"] += "\n\n"
160
161 for commit_hash in self["patch_commit_hashes"]:
162 patch_merge_desc = self.GitLog(n=1, format="%s", git_hash=commit_hash)
163 self["new_commit_msg"] += "%s\n\n" % patch_merge_desc
164
165 bugs = []
166 for commit_hash in self["patch_commit_hashes"]:
167 msg = self.GitLog(n=1, git_hash=commit_hash)
168 for bug in re.findall(r"^[ \t]*BUG[ \t]*=[ \t]*(.*?)[ \t]*$", msg,
169 re.M):
170 bugs.extend(map(lambda s: s.strip(), bug.split(",")))
171 bug_aggregate = ",".join(sorted(bugs))
172 if bug_aggregate:
173 self["new_commit_msg"] += "BUG=%s\nLOG=N\n" % bug_aggregate
174 TextToFile(self["new_commit_msg"], self.Config(COMMITMSG_FILE))
175
176
177 class ApplyPatches(Step):
178 MESSAGE = "Apply patches for selected revisions."
179
180 def RunStep(self):
181 for commit_hash in self["patch_commit_hashes"]:
182 print("Applying patch for %s to %s..."
183 % (commit_hash, self["merge_to_branch"]))
184 patch = self.GitLog(n=1, patch=True, git_hash=commit_hash)
185 TextToFile(patch, self.Config(TEMPORARY_PATCH_FILE))
186 self.ApplyPatch(self.Config(TEMPORARY_PATCH_FILE), self._options.revert)
187 if self._options.patch:
188 self.ApplyPatch(self._options.patch, self._options.revert)
189
190
191 class PrepareVersion(Step):
192 MESSAGE = "Prepare version file."
193
194 def RunStep(self):
195 if self._options.revert_bleeding_edge:
196 return
197 # These version numbers are used again for creating the tag
198 self.ReadAndPersistVersion()
199
200
201 class IncrementVersion(Step):
202 MESSAGE = "Increment version number."
203
204 def RunStep(self):
205 if self._options.revert_bleeding_edge:
206 return
207 new_patch = str(int(self["patch"]) + 1)
208 if self.Confirm("Automatically increment PATCH_LEVEL? (Saying 'n' will "
209 "fire up your EDITOR on %s so you can make arbitrary "
210 "changes. When you're done, save the file and exit your "
211 "EDITOR.)" % self.Config(VERSION_FILE)):
212 text = FileToText(self.Config(VERSION_FILE))
213 text = MSub(r"(?<=#define PATCH_LEVEL)(?P<space>\s+)\d*$",
214 r"\g<space>%s" % new_patch,
215 text)
216 TextToFile(text, self.Config(VERSION_FILE))
217 else:
218 self.Editor(self.Config(VERSION_FILE))
219 self.ReadAndPersistVersion("new_")
220
221
222 class CommitLocal(Step):
223 MESSAGE = "Commit to local branch."
224
225 def RunStep(self):
226 self.GitCommit(file_name=self.Config(COMMITMSG_FILE))
227
228
229 class CommitRepository(Step):
230 MESSAGE = "Commit to the repository."
231
232 def RunStep(self):
233 self.GitCheckout(self.Config(BRANCHNAME))
234 self.WaitForLGTM()
235 self.GitPresubmit()
236 self.GitDCommit()
237
238
239 class PrepareSVN(Step):
240 MESSAGE = "Determine svn commit revision."
241
242 def RunStep(self):
243 if self._options.revert_bleeding_edge:
244 return
245 self.GitSVNFetch()
246 commit_hash = self.GitLog(n=1, format="%H", grep=self["new_commit_msg"],
247 branch="svn/%s" % self["merge_to_branch"])
248 if not commit_hash:
249 self.Die("Unable to map git commit to svn revision.")
250 self["svn_revision"] = self.GitSVNFindSVNRev(commit_hash)
251 print "subversion revision number is r%s" % self["svn_revision"]
252
253
254 class TagRevision(Step):
255 MESSAGE = "Create the tag."
256
257 def RunStep(self):
258 if self._options.revert_bleeding_edge:
259 return
260 self["version"] = "%s.%s.%s.%s" % (self["new_major"],
261 self["new_minor"],
262 self["new_build"],
263 self["new_patch"])
264 print "Creating tag svn/tags/%s" % self["version"]
265 if self["merge_to_branch"] == "trunk":
266 self["to_url"] = "trunk"
267 else:
268 self["to_url"] = "branches/%s" % self["merge_to_branch"]
269 self.SVN("copy -r %s https://v8.googlecode.com/svn/%s "
270 "https://v8.googlecode.com/svn/tags/%s -m "
271 "\"Tagging version %s\""
272 % (self["svn_revision"], self["to_url"],
273 self["version"], self["version"]))
274
275
276 class CleanUp(Step):
277 MESSAGE = "Cleanup."
278
279 def RunStep(self):
280 self.CommonCleanup()
281 if not self._options.revert_bleeding_edge:
282 print "*** SUMMARY ***"
283 print "version: %s" % self["version"]
284 print "branch: %s" % self["to_url"]
285 print "svn revision: %s" % self["svn_revision"]
286 if self["revision_list"]:
287 print "patches: %s" % self["revision_list"]
288
289
290 def RunMergeToBranch(config,
291 options,
292 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER):
293 step_classes = [
294 Preparation,
295 CreateBranch,
296 SearchArchitecturePorts,
297 FindGitRevisions,
298 ApplyPatches,
299 PrepareVersion,
300 IncrementVersion,
301 CommitLocal,
302 UploadStep,
303 CommitRepository,
304 PrepareSVN,
305 TagRevision,
306 CleanUp,
307 ]
308
309 RunScript(step_classes, config, options, side_effect_handler)
310
311
312 def BuildOptions():
313 result = optparse.OptionParser()
314 result.set_usage("""%prog [OPTIONS]... [BRANCH] [REVISION]...
315
316 Performs the necessary steps to merge revisions from bleeding_edge
317 to other branches, including trunk.""")
318 result.add_option("-f",
319 help="Delete sentinel file.",
320 default=False, action="store_true")
321 result.add_option("-m", "--message",
322 help="Specify a commit message for the patch.")
323 result.add_option("-r", "--revert",
324 help="Revert specified patches.",
325 default=False, action="store_true")
326 result.add_option("-R", "--revert-bleeding-edge",
327 help="Revert specified patches from bleeding edge.",
328 default=False, action="store_true")
329 result.add_option("-p", "--patch", dest="p",
330 help="Specify a patch file to apply as part of the merge.")
331 result.add_option("-s", "--step", dest="s",
332 help="Specify the step where to start work. Default: 0.",
333 default=0, type="int")
334 return result
335
336
337 def ProcessOptions(options, args):
338 revert_from_bleeding_edge = 1 if options.revert_bleeding_edge else 0
339 min_exp_args = 2 - revert_from_bleeding_edge
340 if len(args) < min_exp_args:
341 if not options.p:
342 print "Either a patch file or revision numbers must be specified"
343 return False
344 if not options.message:
345 print "You must specify a merge comment if no patches are specified"
346 return False
347 if options.s < 0:
348 print "Bad step number %d" % options.s
349 return False
350 return True
351
352
353 def Main():
354 parser = BuildOptions()
355 (options, args) = parser.parse_args()
356 if not ProcessOptions(options, args):
357 parser.print_help()
358 return 1
359 RunMergeToBranch(CONFIG, MergeToBranchOptions(options, args))
360
361 if __name__ == "__main__":
362 sys.exit(Main())
OLDNEW
« no previous file with comments | « tools/push-to-trunk/git_recipes.py ('k') | tools/push-to-trunk/push_to_trunk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698