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

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

Issue 181453002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 import argparse
30 from collections import OrderedDict
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):
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.branch = options.branch
64 self.revisions = options.revisions
65
66
67 class Preparation(Step):
68 MESSAGE = "Preparation."
69
70 def RunStep(self):
71 if os.path.exists(self.Config(ALREADY_MERGING_SENTINEL_FILE)):
72 if self._options.delete_sentinel:
73 os.remove(self.Config(ALREADY_MERGING_SENTINEL_FILE))
74 elif self._options.s == 0:
75 self.Die("A merge is already in progress")
76 open(self.Config(ALREADY_MERGING_SENTINEL_FILE), "a").close()
77
78 self.InitialEnvironmentChecks()
79 if self._options.revert_bleeding_edge:
80 self["merge_to_branch"] = "bleeding_edge"
81 elif self._options.branch:
82 self["merge_to_branch"] = self._options.branch
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(
103 self._options.revisions))
104 port_revision_list = []
105 for revision in self["full_revision_list"]:
106 # Search for commits which matches the "Port rXXX" pattern.
107 git_hashes = self.GitLog(reverse=True, format="%H",
108 grep="Port r%d" % int(revision),
109 branch="svn/bleeding_edge")
110 for git_hash in git_hashes.splitlines():
111 svn_revision = self.GitSVNFindSVNRev(git_hash, "svn/bleeding_edge")
112 if not svn_revision:
113 self.Die("Cannot determine svn revision for %s" % git_hash)
114 revision_title = self.GitLog(n=1, format="%s", git_hash=git_hash)
115
116 # Is this revision included in the original revision list?
117 if svn_revision in self["full_revision_list"]:
118 print("Found port of r%s -> r%s (already included): %s"
119 % (revision, svn_revision, revision_title))
120 else:
121 print("Found port of r%s -> r%s: %s"
122 % (revision, svn_revision, revision_title))
123 port_revision_list.append(svn_revision)
124
125 # Do we find any port?
126 if len(port_revision_list) > 0:
127 if self.Confirm("Automatically add corresponding ports (%s)?"
128 % ", ".join(port_revision_list)):
129 #: 'y': Add ports to revision list.
130 self["full_revision_list"].extend(port_revision_list)
131
132
133 class FindGitRevisions(Step):
134 MESSAGE = "Find the git revisions associated with the patches."
135
136 def RunStep(self):
137 self["patch_commit_hashes"] = []
138 for revision in self["full_revision_list"]:
139 next_hash = self.GitSVNFindGitHash(revision, "svn/bleeding_edge")
140 if not next_hash:
141 self.Die("Cannot determine git hash for r%s" % revision)
142 self["patch_commit_hashes"].append(next_hash)
143
144 # Stringify: [123, 234] -> "r123, r234"
145 self["revision_list"] = ", ".join(map(lambda s: "r%s" % s,
146 self["full_revision_list"]))
147
148 if not self["revision_list"]:
149 self.Die("Revision list is empty.")
150
151 if self._options.revert:
152 if not self._options.revert_bleeding_edge:
153 self["new_commit_msg"] = ("Rollback of %s in %s branch."
154 % (self["revision_list"], self["merge_to_branch"]))
155 else:
156 self["new_commit_msg"] = "Revert %s." % self["revision_list"]
157 else:
158 self["new_commit_msg"] = ("Merged %s into %s branch."
159 % (self["revision_list"], self["merge_to_branch"]))
160 self["new_commit_msg"] += "\n\n"
161
162 for commit_hash in self["patch_commit_hashes"]:
163 patch_merge_desc = self.GitLog(n=1, format="%s", git_hash=commit_hash)
164 self["new_commit_msg"] += "%s\n\n" % patch_merge_desc
165
166 bugs = []
167 for commit_hash in self["patch_commit_hashes"]:
168 msg = self.GitLog(n=1, git_hash=commit_hash)
169 for bug in re.findall(r"^[ \t]*BUG[ \t]*=[ \t]*(.*?)[ \t]*$", msg,
170 re.M):
171 bugs.extend(map(lambda s: s.strip(), bug.split(",")))
172 bug_aggregate = ",".join(sorted(bugs))
173 if bug_aggregate:
174 self["new_commit_msg"] += "BUG=%s\nLOG=N\n" % bug_aggregate
175 TextToFile(self["new_commit_msg"], self.Config(COMMITMSG_FILE))
176
177
178 class ApplyPatches(Step):
179 MESSAGE = "Apply patches for selected revisions."
180
181 def RunStep(self):
182 for commit_hash in self["patch_commit_hashes"]:
183 print("Applying patch for %s to %s..."
184 % (commit_hash, self["merge_to_branch"]))
185 patch = self.GitLog(n=1, patch=True, git_hash=commit_hash)
186 TextToFile(patch, self.Config(TEMPORARY_PATCH_FILE))
187 self.ApplyPatch(self.Config(TEMPORARY_PATCH_FILE), self._options.revert)
188 if self._options.patch:
189 self.ApplyPatch(self._options.patch, self._options.revert)
190
191
192 class PrepareVersion(Step):
193 MESSAGE = "Prepare version file."
194
195 def RunStep(self):
196 if self._options.revert_bleeding_edge:
197 return
198 # These version numbers are used again for creating the tag
199 self.ReadAndPersistVersion()
200
201
202 class IncrementVersion(Step):
203 MESSAGE = "Increment version number."
204
205 def RunStep(self):
206 if self._options.revert_bleeding_edge:
207 return
208 new_patch = str(int(self["patch"]) + 1)
209 if self.Confirm("Automatically increment PATCH_LEVEL? (Saying 'n' will "
210 "fire up your EDITOR on %s so you can make arbitrary "
211 "changes. When you're done, save the file and exit your "
212 "EDITOR.)" % self.Config(VERSION_FILE)):
213 text = FileToText(self.Config(VERSION_FILE))
214 text = MSub(r"(?<=#define PATCH_LEVEL)(?P<space>\s+)\d*$",
215 r"\g<space>%s" % new_patch,
216 text)
217 TextToFile(text, self.Config(VERSION_FILE))
218 else:
219 self.Editor(self.Config(VERSION_FILE))
220 self.ReadAndPersistVersion("new_")
221
222
223 class CommitLocal(Step):
224 MESSAGE = "Commit to local branch."
225
226 def RunStep(self):
227 self.GitCommit(file_name=self.Config(COMMITMSG_FILE))
228
229
230 class CommitRepository(Step):
231 MESSAGE = "Commit to the repository."
232
233 def RunStep(self):
234 self.GitCheckout(self.Config(BRANCHNAME))
235 self.WaitForLGTM()
236 self.GitPresubmit()
237 self.GitDCommit()
238
239
240 class PrepareSVN(Step):
241 MESSAGE = "Determine svn commit revision."
242
243 def RunStep(self):
244 if self._options.revert_bleeding_edge:
245 return
246 self.GitSVNFetch()
247 commit_hash = self.GitLog(n=1, format="%H", grep=self["new_commit_msg"],
248 branch="svn/%s" % self["merge_to_branch"])
249 if not commit_hash:
250 self.Die("Unable to map git commit to svn revision.")
251 self["svn_revision"] = self.GitSVNFindSVNRev(commit_hash)
252 print "subversion revision number is r%s" % self["svn_revision"]
253
254
255 class TagRevision(Step):
256 MESSAGE = "Create the tag."
257
258 def RunStep(self):
259 if self._options.revert_bleeding_edge:
260 return
261 self["version"] = "%s.%s.%s.%s" % (self["new_major"],
262 self["new_minor"],
263 self["new_build"],
264 self["new_patch"])
265 print "Creating tag svn/tags/%s" % self["version"]
266 if self["merge_to_branch"] == "trunk":
267 self["to_url"] = "trunk"
268 else:
269 self["to_url"] = "branches/%s" % self["merge_to_branch"]
270 self.SVN("copy -r %s https://v8.googlecode.com/svn/%s "
271 "https://v8.googlecode.com/svn/tags/%s -m "
272 "\"Tagging version %s\""
273 % (self["svn_revision"], self["to_url"],
274 self["version"], self["version"]))
275
276
277 class CleanUp(Step):
278 MESSAGE = "Cleanup."
279
280 def RunStep(self):
281 self.CommonCleanup()
282 if not self._options.revert_bleeding_edge:
283 print "*** SUMMARY ***"
284 print "version: %s" % self["version"]
285 print "branch: %s" % self["to_url"]
286 print "svn revision: %s" % self["svn_revision"]
287 if self["revision_list"]:
288 print "patches: %s" % self["revision_list"]
289
290
291 def RunMergeToBranch(config,
292 options,
293 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER):
294 step_classes = [
295 Preparation,
296 CreateBranch,
297 SearchArchitecturePorts,
298 FindGitRevisions,
299 ApplyPatches,
300 PrepareVersion,
301 IncrementVersion,
302 CommitLocal,
303 UploadStep,
304 CommitRepository,
305 PrepareSVN,
306 TagRevision,
307 CleanUp,
308 ]
309
310 RunScript(step_classes, config, options, side_effect_handler)
311
312
313 def BuildOptions():
314 parser = argparse.ArgumentParser(
315 description=("Performs the necessary steps to merge revisions from "
316 "bleeding_edge to other branches, including trunk."))
317 group = parser.add_mutually_exclusive_group(required=True)
318 group.add_argument("--branch", help="The branch to merge to.")
319 group.add_argument("-R", "--revert-bleeding-edge",
320 help="Revert specified patches from bleeding edge.",
321 default=False, action="store_true")
322 parser.add_argument("revisions", nargs="*",
323 help="The revisions to merge.")
324 parser.add_argument("-a", "--author", default="",
325 help="The author email used for rietveld.")
326 parser.add_argument("-f",
327 help="Delete sentinel file.",
328 default=False, action="store_true")
329 parser.add_argument("-m", "--message",
330 help="A commit message for the patch.")
331 parser.add_argument("-r", "--revert",
332 help="Revert specified patches.",
333 default=False, action="store_true")
334 parser.add_argument("-p", "--patch", dest="p",
335 help="A patch file to apply as part of the merge.")
336 parser.add_argument("-s", "--step", dest="s",
337 help="The step where to start work. Default: 0.",
338 default=0, type=int)
339 return parser
340
341
342 def ProcessOptions(options):
343 # TODO(machenbach): Add a test that covers revert from bleeding_edge
344 if len(options.revisions) < 1:
345 if not options.patch:
346 print "Either a patch file or revision numbers must be specified"
347 return False
348 if not options.message:
349 print "You must specify a merge comment if no patches are specified"
350 return False
351 return True
352
353
354 def Main():
355 parser = BuildOptions()
356 options = parser.parse_args()
357 if not ProcessOptions(options):
358 parser.print_help()
359 return 1
360 RunMergeToBranch(CONFIG, MergeToBranchOptions(options))
361
362 if __name__ == "__main__":
363 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