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

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

Issue 185263003: Refactoring: Make script dependencies more object-oriented in push and merge scripts. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
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/common_includes.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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 the V8 project authors. All rights reserved. 2 # Copyright 2014 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following 10 # copyright notice, this list of conditions and the following
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 "/tmp/v8-merge-to-branch-tempfile-already-merging", 43 "/tmp/v8-merge-to-branch-tempfile-already-merging",
44 TEMP_BRANCH: "prepare-merge-temporary-branch-created-by-script", 44 TEMP_BRANCH: "prepare-merge-temporary-branch-created-by-script",
45 DOT_GIT_LOCATION: ".git", 45 DOT_GIT_LOCATION: ".git",
46 VERSION_FILE: "src/version.cc", 46 VERSION_FILE: "src/version.cc",
47 TEMPORARY_PATCH_FILE: "/tmp/v8-prepare-merge-tempfile-temporary-patch", 47 TEMPORARY_PATCH_FILE: "/tmp/v8-prepare-merge-tempfile-temporary-patch",
48 COMMITMSG_FILE: "/tmp/v8-prepare-merge-tempfile-commitmsg", 48 COMMITMSG_FILE: "/tmp/v8-prepare-merge-tempfile-commitmsg",
49 COMMIT_HASHES_FILE: "/tmp/v8-merge-to-branch-tempfile-PATCH_COMMIT_HASHES", 49 COMMIT_HASHES_FILE: "/tmp/v8-merge-to-branch-tempfile-PATCH_COMMIT_HASHES",
50 } 50 }
51 51
52 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): 53 class Preparation(Step):
68 MESSAGE = "Preparation." 54 MESSAGE = "Preparation."
69 55
70 def RunStep(self): 56 def RunStep(self):
71 if os.path.exists(self.Config(ALREADY_MERGING_SENTINEL_FILE)): 57 if os.path.exists(self.Config(ALREADY_MERGING_SENTINEL_FILE)):
72 if self._options.delete_sentinel: 58 if self._options.force:
73 os.remove(self.Config(ALREADY_MERGING_SENTINEL_FILE)) 59 os.remove(self.Config(ALREADY_MERGING_SENTINEL_FILE))
74 elif self._options.step == 0: 60 elif self._options.step == 0:
75 self.Die("A merge is already in progress") 61 self.Die("A merge is already in progress")
76 open(self.Config(ALREADY_MERGING_SENTINEL_FILE), "a").close() 62 open(self.Config(ALREADY_MERGING_SENTINEL_FILE), "a").close()
77 63
78 self.InitialEnvironmentChecks() 64 self.InitialEnvironmentChecks()
79 if self._options.revert_bleeding_edge: 65 if self._options.revert_bleeding_edge:
80 self["merge_to_branch"] = "bleeding_edge" 66 self["merge_to_branch"] = "bleeding_edge"
81 elif self._options.branch: 67 elif self._options.branch:
82 self["merge_to_branch"] = self._options.branch 68 self["merge_to_branch"] = self._options.branch
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 self.CommonCleanup() 267 self.CommonCleanup()
282 if not self._options.revert_bleeding_edge: 268 if not self._options.revert_bleeding_edge:
283 print "*** SUMMARY ***" 269 print "*** SUMMARY ***"
284 print "version: %s" % self["version"] 270 print "version: %s" % self["version"]
285 print "branch: %s" % self["to_url"] 271 print "branch: %s" % self["to_url"]
286 print "svn revision: %s" % self["svn_revision"] 272 print "svn revision: %s" % self["svn_revision"]
287 if self["revision_list"]: 273 if self["revision_list"]:
288 print "patches: %s" % self["revision_list"] 274 print "patches: %s" % self["revision_list"]
289 275
290 276
291 def RunMergeToBranch(config, 277 class MergeToBranch(ScriptsBase):
292 options, 278 def _Description(self):
293 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER): 279 return ("Performs the necessary steps to merge revisions from "
294 step_classes = [ 280 "bleeding_edge to other branches, including trunk.")
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 281
310 RunScript(step_classes, config, options, side_effect_handler) 282 def _PrepareOptions(self, parser):
283 group = parser.add_mutually_exclusive_group(required=True)
284 group.add_argument("--branch", help="The branch to merge to.")
285 group.add_argument("-R", "--revert-bleeding-edge",
286 help="Revert specified patches from bleeding edge.",
287 default=False, action="store_true")
288 parser.add_argument("revisions", nargs="*",
289 help="The revisions to merge.")
290 parser.add_argument("-f", "--force",
291 help="Delete sentinel file.",
292 default=False, action="store_true")
293 parser.add_argument("-m", "--message",
294 help="A commit message for the patch.")
295 parser.add_argument("--revert",
296 help="Revert specified patches.",
297 default=False, action="store_true")
298 parser.add_argument("-p", "--patch",
299 help="A patch file to apply as part of the merge.")
300
301 def _ProcessOptions(self, options):
302 # TODO(machenbach): Add a test that covers revert from bleeding_edge
303 if len(options.revisions) < 1:
304 if not options.patch:
305 print "Either a patch file or revision numbers must be specified"
306 return False
307 if not options.message:
308 print "You must specify a merge comment if no patches are specified"
309 return False
310 return True
311
312 def _Steps(self):
313 return [
314 Preparation,
315 CreateBranch,
316 SearchArchitecturePorts,
317 FindGitRevisions,
318 ApplyPatches,
319 PrepareVersion,
320 IncrementVersion,
321 CommitLocal,
322 UploadStep,
323 CommitRepository,
324 PrepareSVN,
325 TagRevision,
326 CleanUp,
327 ]
311 328
312 329
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",
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__": 330 if __name__ == "__main__":
363 sys.exit(Main()) 331 sys.exit(MergeToBranch(CONFIG).Run())
OLDNEW
« no previous file with comments | « tools/push-to-trunk/common_includes.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