| OLD | NEW |
| 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 |
| 11 # disclaimer in the documentation and/or other materials provided | 11 # disclaimer in the documentation and/or other materials provided |
| 12 # with the distribution. | 12 # with the distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived | 14 # contributors may be used to endorse or promote products derived |
| 15 # from this software without specific prior written permission. | 15 # from this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import argparse |
| 29 from collections import OrderedDict | 30 from collections import OrderedDict |
| 30 import optparse | |
| 31 import sys | 31 import sys |
| 32 | 32 |
| 33 from common_includes import * | 33 from common_includes import * |
| 34 | 34 |
| 35 ALREADY_MERGING_SENTINEL_FILE = "ALREADY_MERGING_SENTINEL_FILE" | 35 ALREADY_MERGING_SENTINEL_FILE = "ALREADY_MERGING_SENTINEL_FILE" |
| 36 COMMIT_HASHES_FILE = "COMMIT_HASHES_FILE" | 36 COMMIT_HASHES_FILE = "COMMIT_HASHES_FILE" |
| 37 TEMPORARY_PATCH_FILE = "TEMPORARY_PATCH_FILE" | 37 TEMPORARY_PATCH_FILE = "TEMPORARY_PATCH_FILE" |
| 38 | 38 |
| 39 CONFIG = { | 39 CONFIG = { |
| 40 BRANCHNAME: "prepare-merge", | 40 BRANCHNAME: "prepare-merge", |
| 41 PERSISTFILE_BASENAME: "/tmp/v8-merge-to-branch-tempfile", | 41 PERSISTFILE_BASENAME: "/tmp/v8-merge-to-branch-tempfile", |
| 42 ALREADY_MERGING_SENTINEL_FILE: | 42 ALREADY_MERGING_SENTINEL_FILE: |
| 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): | 53 class MergeToBranchOptions(CommonOptions): |
| 54 def __init__(self, options, args): | 54 def __init__(self, options): |
| 55 super(MergeToBranchOptions, self).__init__(options, True) | 55 super(MergeToBranchOptions, self).__init__(options, True) |
| 56 self.requires_editor = True | 56 self.requires_editor = True |
| 57 self.wait_for_lgtm = True | 57 self.wait_for_lgtm = True |
| 58 self.delete_sentinel = options.f | 58 self.delete_sentinel = options.f |
| 59 self.message = getattr(options, "message", "") | 59 self.message = getattr(options, "message", "") |
| 60 self.revert = getattr(options, "r", False) | 60 self.revert = getattr(options, "r", False) |
| 61 self.revert_bleeding_edge = getattr(options, "revert_bleeding_edge", False) | 61 self.revert_bleeding_edge = getattr(options, "revert_bleeding_edge", False) |
| 62 self.patch = getattr(options, "p", "") | 62 self.patch = getattr(options, "p", "") |
| 63 self.args = args | 63 self.branch = options.branch |
| 64 self.revisions = options.revisions |
| 64 | 65 |
| 65 | 66 |
| 66 class Preparation(Step): | 67 class Preparation(Step): |
| 67 MESSAGE = "Preparation." | 68 MESSAGE = "Preparation." |
| 68 | 69 |
| 69 def RunStep(self): | 70 def RunStep(self): |
| 70 if os.path.exists(self.Config(ALREADY_MERGING_SENTINEL_FILE)): | 71 if os.path.exists(self.Config(ALREADY_MERGING_SENTINEL_FILE)): |
| 71 if self._options.delete_sentinel: | 72 if self._options.delete_sentinel: |
| 72 os.remove(self.Config(ALREADY_MERGING_SENTINEL_FILE)) | 73 os.remove(self.Config(ALREADY_MERGING_SENTINEL_FILE)) |
| 73 elif self._options.s == 0: | 74 elif self._options.s == 0: |
| 74 self.Die("A merge is already in progress") | 75 self.Die("A merge is already in progress") |
| 75 open(self.Config(ALREADY_MERGING_SENTINEL_FILE), "a").close() | 76 open(self.Config(ALREADY_MERGING_SENTINEL_FILE), "a").close() |
| 76 | 77 |
| 77 self.InitialEnvironmentChecks() | 78 self.InitialEnvironmentChecks() |
| 78 if self._options.revert_bleeding_edge: | 79 if self._options.revert_bleeding_edge: |
| 79 self["merge_to_branch"] = "bleeding_edge" | 80 self["merge_to_branch"] = "bleeding_edge" |
| 80 elif self._options.args[0]: | 81 elif self._options.branch: |
| 81 self["merge_to_branch"] = self._options.args[0] | 82 self["merge_to_branch"] = self._options.branch |
| 82 self._options.args = self._options.args[1:] | |
| 83 else: | 83 else: |
| 84 self.Die("Please specify a branch to merge to") | 84 self.Die("Please specify a branch to merge to") |
| 85 | 85 |
| 86 self.CommonPrepare() | 86 self.CommonPrepare() |
| 87 self.PrepareBranch() | 87 self.PrepareBranch() |
| 88 | 88 |
| 89 | 89 |
| 90 class CreateBranch(Step): | 90 class CreateBranch(Step): |
| 91 MESSAGE = "Create a fresh branch for the patch." | 91 MESSAGE = "Create a fresh branch for the patch." |
| 92 | 92 |
| 93 def RunStep(self): | 93 def RunStep(self): |
| 94 self.GitCreateBranch(self.Config(BRANCHNAME), | 94 self.GitCreateBranch(self.Config(BRANCHNAME), |
| 95 "svn/%s" % self["merge_to_branch"]) | 95 "svn/%s" % self["merge_to_branch"]) |
| 96 | 96 |
| 97 | 97 |
| 98 class SearchArchitecturePorts(Step): | 98 class SearchArchitecturePorts(Step): |
| 99 MESSAGE = "Search for corresponding architecture ports." | 99 MESSAGE = "Search for corresponding architecture ports." |
| 100 | 100 |
| 101 def RunStep(self): | 101 def RunStep(self): |
| 102 self["full_revision_list"] = list(OrderedDict.fromkeys(self._options.args)) | 102 self["full_revision_list"] = list(OrderedDict.fromkeys( |
| 103 self._options.revisions)) |
| 103 port_revision_list = [] | 104 port_revision_list = [] |
| 104 for revision in self["full_revision_list"]: | 105 for revision in self["full_revision_list"]: |
| 105 # Search for commits which matches the "Port rXXX" pattern. | 106 # Search for commits which matches the "Port rXXX" pattern. |
| 106 git_hashes = self.GitLog(reverse=True, format="%H", | 107 git_hashes = self.GitLog(reverse=True, format="%H", |
| 107 grep="Port r%d" % int(revision), | 108 grep="Port r%d" % int(revision), |
| 108 branch="svn/bleeding_edge") | 109 branch="svn/bleeding_edge") |
| 109 for git_hash in git_hashes.splitlines(): | 110 for git_hash in git_hashes.splitlines(): |
| 110 svn_revision = self.GitSVNFindSVNRev(git_hash, "svn/bleeding_edge") | 111 svn_revision = self.GitSVNFindSVNRev(git_hash, "svn/bleeding_edge") |
| 111 if not svn_revision: | 112 if not svn_revision: |
| 112 self.Die("Cannot determine svn revision for %s" % git_hash) | 113 self.Die("Cannot determine svn revision for %s" % git_hash) |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 CommitRepository, | 304 CommitRepository, |
| 304 PrepareSVN, | 305 PrepareSVN, |
| 305 TagRevision, | 306 TagRevision, |
| 306 CleanUp, | 307 CleanUp, |
| 307 ] | 308 ] |
| 308 | 309 |
| 309 RunScript(step_classes, config, options, side_effect_handler) | 310 RunScript(step_classes, config, options, side_effect_handler) |
| 310 | 311 |
| 311 | 312 |
| 312 def BuildOptions(): | 313 def BuildOptions(): |
| 313 result = optparse.OptionParser() | 314 parser = argparse.ArgumentParser( |
| 314 result.set_usage("""%prog [OPTIONS]... [BRANCH] [REVISION]... | 315 description=("Performs the necessary steps to merge revisions from " |
| 315 | 316 "bleeding_edge to other branches, including trunk.")) |
| 316 Performs the necessary steps to merge revisions from bleeding_edge | 317 group = parser.add_mutually_exclusive_group(required=True) |
| 317 to other branches, including trunk.""") | 318 group.add_argument("--branch", help="The branch to merge to.") |
| 318 result.add_option("-f", | 319 group.add_argument("-R", "--revert-bleeding-edge", |
| 319 help="Delete sentinel file.", | 320 help="Revert specified patches from bleeding edge.", |
| 320 default=False, action="store_true") | 321 default=False, action="store_true") |
| 321 result.add_option("-m", "--message", | 322 parser.add_argument("revisions", nargs="*", |
| 322 help="Specify a commit message for the patch.") | 323 help="The revisions to merge.") |
| 323 result.add_option("-r", "--revert", | 324 parser.add_argument("-a", "--author", default="", |
| 324 help="Revert specified patches.", | 325 help="The author email used for rietveld.") |
| 325 default=False, action="store_true") | 326 parser.add_argument("-f", |
| 326 result.add_option("-R", "--revert-bleeding-edge", | 327 help="Delete sentinel file.", |
| 327 help="Revert specified patches from bleeding edge.", | 328 default=False, action="store_true") |
| 328 default=False, action="store_true") | 329 parser.add_argument("-m", "--message", |
| 329 result.add_option("-p", "--patch", dest="p", | 330 help="A commit message for the patch.") |
| 330 help="Specify a patch file to apply as part of the merge.") | 331 parser.add_argument("-r", "--revert", |
| 331 result.add_option("-s", "--step", dest="s", | 332 help="Revert specified patches.", |
| 332 help="Specify the step where to start work. Default: 0.", | 333 default=False, action="store_true") |
| 333 default=0, type="int") | 334 parser.add_argument("-p", "--patch", dest="p", |
| 334 return result | 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 |
| 335 | 340 |
| 336 | 341 |
| 337 def ProcessOptions(options, args): | 342 def ProcessOptions(options): |
| 338 revert_from_bleeding_edge = 1 if options.revert_bleeding_edge else 0 | 343 # TODO(machenbach): Add a test that covers revert from bleeding_edge |
| 339 min_exp_args = 2 - revert_from_bleeding_edge | 344 if len(options.revisions) < 1: |
| 340 if len(args) < min_exp_args: | 345 if not options.patch: |
| 341 if not options.p: | |
| 342 print "Either a patch file or revision numbers must be specified" | 346 print "Either a patch file or revision numbers must be specified" |
| 343 return False | 347 return False |
| 344 if not options.message: | 348 if not options.message: |
| 345 print "You must specify a merge comment if no patches are specified" | 349 print "You must specify a merge comment if no patches are specified" |
| 346 return False | 350 return False |
| 347 if options.s < 0: | |
| 348 print "Bad step number %d" % options.s | |
| 349 return False | |
| 350 return True | 351 return True |
| 351 | 352 |
| 352 | 353 |
| 353 def Main(): | 354 def Main(): |
| 354 parser = BuildOptions() | 355 parser = BuildOptions() |
| 355 (options, args) = parser.parse_args() | 356 options = parser.parse_args() |
| 356 if not ProcessOptions(options, args): | 357 if not ProcessOptions(options): |
| 357 parser.print_help() | 358 parser.print_help() |
| 358 return 1 | 359 return 1 |
| 359 RunMergeToBranch(CONFIG, MergeToBranchOptions(options, args)) | 360 RunMergeToBranch(CONFIG, MergeToBranchOptions(options)) |
| 360 | 361 |
| 361 if __name__ == "__main__": | 362 if __name__ == "__main__": |
| 362 sys.exit(Main()) | 363 sys.exit(Main()) |
| OLD | NEW |