Revision: 19451
Author:   [email protected]
Date:     Tue Feb 18 14:13:01 2014 UTC
Log:      Merged r19443 into trunk branch.

Add merge-to-branch python port.

[email protected]
BUG=

Review URL: https://codereview.chromium.org/167463005
http://code.google.com/p/v8/source/detail?r=19451

Added:
 /trunk/tools/push-to-trunk/merge_to_branch.py
Modified:
 /trunk/src/version.cc
 /trunk/tools/merge-to-branch.sh
 /trunk/tools/push-to-trunk/auto_roll.py
 /trunk/tools/push-to-trunk/common_includes.py
 /trunk/tools/push-to-trunk/push_to_trunk.py
 /trunk/tools/push-to-trunk/test_scripts.py

=======================================
--- /dev/null
+++ /trunk/tools/push-to-trunk/merge_to_branch.py Tue Feb 18 14:13:01 2014 UTC
@@ -0,0 +1,400 @@
+#!/usr/bin/env python
+# Copyright 2014 the V8 project authors. All rights reserved.
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+#       copyright notice, this list of conditions and the following
+#       disclaimer in the documentation and/or other materials provided
+#       with the distribution.
+#     * Neither the name of Google Inc. nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from collections import OrderedDict
+
+from common_includes import *
+
+ALREADY_MERGING_SENTINEL_FILE = "ALREADY_MERGING_SENTINEL_FILE"
+COMMIT_HASHES_FILE = "COMMIT_HASHES_FILE"
+TEMPORARY_PATCH_FILE = "TEMPORARY_PATCH_FILE"
+
+CONFIG = {
+  BRANCHNAME: "prepare-merge",
+  PERSISTFILE_BASENAME: "/tmp/v8-merge-to-branch-tempfile",
+  ALREADY_MERGING_SENTINEL_FILE:
+      "/tmp/v8-merge-to-branch-tempfile-already-merging",
+  TEMP_BRANCH: "prepare-merge-temporary-branch-created-by-script",
+  DOT_GIT_LOCATION: ".git",
+  VERSION_FILE: "src/version.cc",
+  TEMPORARY_PATCH_FILE: "/tmp/v8-prepare-merge-tempfile-temporary-patch",
+  COMMITMSG_FILE: "/tmp/v8-prepare-merge-tempfile-commitmsg",
+ COMMIT_HASHES_FILE: "/tmp/v8-merge-to-branch-tempfile-PATCH_COMMIT_HASHES",
+}
+
+
+class MergeToBranchOptions(CommonOptions):
+  def __init__(self, options, args):
+    super(MergeToBranchOptions, self).__init__(options, options.m)
+    self.requires_editor = True
+    self.wait_for_lgtm = True
+    self.delete_sentinel = options.f
+    self.message = options.m
+    self.revert = "--reverse" if getattr(options, "r", None) else ""
+ self.revert_bleeding_edge = getattr(options, "revert_bleeding_edge", False)
+    self.patch = getattr(options, "p", "")
+    self.args = args
+
+
+class Preparation(Step):
+  MESSAGE = "Preparation."
+
+  def RunStep(self):
+    if os.path.exists(self.Config(ALREADY_MERGING_SENTINEL_FILE)):
+      if self._options.delete_sentinel:
+        os.remove(self.Config(ALREADY_MERGING_SENTINEL_FILE))
+      elif self._options.s == 0:
+        self.Die("A merge is already in progress")
+    open(self.Config(ALREADY_MERGING_SENTINEL_FILE), "a").close()
+
+    self.InitialEnvironmentChecks()
+    if self._options.revert_bleeding_edge:
+      self.Persist("merge_to_branch", "bleeding_edge")
+    elif self._options.args[0]:
+      self.Persist("merge_to_branch", self._options.args[0])
+      self._options.args = self._options.args[1:]
+    else:
+      self.Die("Please specify a branch to merge to")
+
+    self.CommonPrepare()
+    self.PrepareBranch()
+
+
+class CreateBranch(Step):
+  MESSAGE = "Create a fresh branch for the patch."
+
+  def RunStep(self):
+    self.RestoreIfUnset("merge_to_branch")
+    args = "checkout -b %s svn/%s" % (self.Config(BRANCHNAME),
+                                      self._state["merge_to_branch"])
+    if self.Git(args) is None:
+      self.die("Creating branch %s failed." % self.Config(BRANCHNAME))
+
+
+class SearchArchitecturePorts(Step):
+  MESSAGE = "Search for corresponding architecture ports."
+
+  def RunStep(self):
+    full_revision_list = list(OrderedDict.fromkeys(self._options.args))
+    port_revision_list = []
+    for revision in full_revision_list:
+      # Search for commits which matches the "Port rXXX" pattern.
+      args = ("log svn/bleeding_edge --reverse "
+              "--format=%%H --grep=\"Port r%d\"" % int(revision))
+      git_hashes = self.Git(args) or ""
+      for git_hash in git_hashes.strip().splitlines():
+        args = "svn find-rev %s svn/bleeding_edge" % git_hash
+        svn_revision = self.Git(args).strip()
+        if not svn_revision:
+          self.Die("Cannot determine svn revision for %s" % git_hash)
+        revision_title = self.Git("log -1 --format=%%s %s" % git_hash)
+
+        # Is this revision included in the original revision list?
+        if svn_revision in full_revision_list:
+          print("Found port of r%s -> r%s (already included): %s"
+                % (revision, svn_revision, revision_title))
+        else:
+          print("Found port of r%s -> r%s: %s"
+                % (revision, svn_revision, revision_title))
+          port_revision_list.append(svn_revision)
+
+    # Do we find any port?
+    if len(port_revision_list) > 0:
+      if self.Confirm("Automatically add corresponding ports (%s)?"
+                      % ", ".join(port_revision_list)):
+        #: 'y': Add ports to revision list.
+        full_revision_list.extend(port_revision_list)
+    self.Persist("full_revision_list", ",".join(full_revision_list))
+
+
+class FindGitRevisions(Step):
+  MESSAGE = "Find the git revisions associated with the patches."
+
+  def RunStep(self):
+    self.RestoreIfUnset("full_revision_list")
+    self.RestoreIfUnset("merge_to_branch")
+    full_revision_list = self._state["full_revision_list"].split(",")
+    patch_commit_hashes = []
+    for revision in full_revision_list:
+ next_hash = self.Git("svn find-rev \"r%s\" svn/bleeding_edge" % revision)
+      if not next_hash:
+        self.Die("Cannot determine git hash for r%s" % revision)
+      patch_commit_hashes.append(next_hash)
+
+    # Stringify: [123, 234] -> "r123, r234"
+    revision_list = ", ".join(map(lambda s: "r%s" % s, full_revision_list))
+
+    if not revision_list:
+      self.Die("Revision list is empty.")
+
+    if self._options.revert:
+      if not self._options.revert_bleeding_edge:
+        new_commit_msg = ("Rollback of %s in %s branch."
+ % (revision_list, self._state["merge_to_branch"]))
+      else:
+        new_commit_msg = "Revert %s ." % revision_list
+    else:
+      new_commit_msg = ("Merged %s into %s branch."
+                        % (revision_list, self._state["merge_to_branch"]))
+    new_commit_msg += "\n\n"
+
+    for commit_hash in patch_commit_hashes:
+      patch_merge_desc = self.Git("log -1 --format=%%s %s" % commit_hash)
+      new_commit_msg += "%s\n\n" % patch_merge_desc.strip()
+
+    bugs = []
+    for commit_hash in patch_commit_hashes:
+      msg = self.Git("log -1 %s" % commit_hash)
+      for bug in re.findall(r"^[ \t]*BUG[ \t]*=[ \t]*(.*?)[ \t]*$", msg,
+                            re.M):
+        bugs.extend(map(lambda s: s.strip(), bug.split(",")))
+    bug_aggregate = ",".join(sorted(bugs))
+    if bug_aggregate:
+      new_commit_msg += "BUG=%s\nLOG=N\n" % bug_aggregate
+    TextToFile(new_commit_msg, self.Config(COMMITMSG_FILE))
+    self.Persist("new_commit_msg", new_commit_msg)
+    self.Persist("revision_list", revision_list)
+    self._state["patch_commit_hashes"] = patch_commit_hashes
+    self.Persist("patch_commit_hashes_list", " ".join(patch_commit_hashes))
+
+
+class ApplyPatches(Step):
+  MESSAGE = "Apply patches for selected revisions."
+
+  def RunStep(self):
+    self.RestoreIfUnset("merge_to_branch")
+    self.RestoreIfUnset("patch_commit_hashes_list")
+    patch_commit_hashes = self._state.get("patch_commit_hashes")
+    if not patch_commit_hashes:
+      patch_commit_hashes = (
+          self._state.get("patch_commit_hashes_list").strip().split(" "))
+    if not patch_commit_hashes and not options.patch:
+      self.Die("Variable patch_commit_hashes could not be restored.")
+    for commit_hash in patch_commit_hashes:
+      print("Applying patch for %s to %s..."
+            % (commit_hash, self._state["merge_to_branch"]))
+      patch = self.Git("log -1 -p %s" % commit_hash)
+      TextToFile(patch, self.Config(TEMPORARY_PATCH_FILE))
+ self.ApplyPatch(self.Config(TEMPORARY_PATCH_FILE), self._options.revert)
+    if self._options.patch:
+      self.ApplyPatch(self._options.patch, self._options.revert)
+
+
+class PrepareVersion(Step):
+  MESSAGE = "Prepare version file."
+
+  def RunStep(self):
+    if self._options.revert_bleeding_edge:
+      return
+    # These version numbers are used again for creating the tag
+    self.ReadAndPersistVersion()
+
+
+class IncrementVersion(Step):
+  MESSAGE = "Increment version number."
+
+  def RunStep(self):
+    if self._options.revert_bleeding_edge:
+      return
+    self.RestoreIfUnset("patch")
+    new_patch = str(int(self._state["patch"]) + 1)
+ if self.Confirm("Automatically increment PATCH_LEVEL? (Saying 'n' will "
+                    "fire up your EDITOR on %s so you can make arbitrary "
+ "changes. When you're done, save the file and exit your "
+                    "EDITOR.)" % self.Config(VERSION_FILE)):
+      text = FileToText(self.Config(VERSION_FILE))
+      text = MSub(r"(?<=#define PATCH_LEVEL)(?P<space>\s+)\d*$",
+                  r"\g<space>%s" % new_patch,
+                  text)
+      TextToFile(text, self.Config(VERSION_FILE))
+    else:
+      self.Editor(self.Config(VERSION_FILE))
+    self.ReadAndPersistVersion("new_")
+
+
+class CommitLocal(Step):
+  MESSAGE = "Commit to local branch."
+
+  def RunStep(self):
+ if self.Git("commit -a -F \"%s\"" % self.Config(COMMITMSG_FILE)) is None:
+      self.Die("'git commit -a' failed.")
+
+
+class CommitRepository(Step):
+  MESSAGE = "Commit to the repository."
+
+  def RunStep(self):
+    self.RestoreIfUnset("merge_to_branch")
+    if self.Git("checkout %s" % self.Config(BRANCHNAME)) is None:
+      self.Die("Cannot ensure that the current branch is %s"
+               % self.Config(BRANCHNAME))
+    self.WaitForLGTM()
+    if self.Git("cl presubmit", "PRESUBMIT_TREE_CHECK=\"skip\"") is None:
+      self.Die("Presubmit failed.")
+
+    if self.Git("cl dcommit -f --bypass-hooks",
+                retry_on=lambda x: x is None) is None:
+      self.Die("Failed to commit to %s" % self._status["merge_to_branch"])
+
+
+class PrepareSVN(Step):
+  MESSAGE = "Determine svn commit revision."
+
+  def RunStep(self):
+    if self._options.revert_bleeding_edge:
+      return
+    self.RestoreIfUnset("new_commit_msg")
+    self.RestoreIfUnset("merge_to_branch")
+    if self.Git("svn fetch") is None:
+      self.Die("'git svn fetch' failed.")
+    args = ("log -1 --format=%%H --grep=\"%s\" svn/%s"
+ % (self._state["new_commit_msg"], self._state["merge_to_branch"]))
+    commit_hash = self.Git(args).strip()
+    if not commit_hash:
+      self.Die("Unable to map git commit to svn revision.")
+    svn_revision = self.Git("svn find-rev %s" % commit_hash).strip()
+    print "subversion revision number is r%s" % svn_revision
+    self.Persist("svn_revision", svn_revision)
+
+
+class TagRevision(Step):
+  MESSAGE = "Create the tag."
+
+  def RunStep(self):
+    if self._options.revert_bleeding_edge:
+      return
+    self.RestoreVersionIfUnset("new_")
+    self.RestoreIfUnset("svn_revision")
+    self.RestoreIfUnset("merge_to_branch")
+    ver = "%s.%s.%s.%s" % (self._state["new_major"],
+                           self._state["new_minor"],
+                           self._state["new_build"],
+                           self._state["new_patch"])
+    print "Creating tag svn/tags/%s" % ver
+    if self._state["merge_to_branch"] == "trunk":
+      to_url = "trunk"
+    else:
+      to_url = "branches/%s" % self._state["merge_to_branch"]
+    self.SVN("copy -r %s https://v8.googlecode.com/svn/%s "
+             "https://v8.googlecode.com/svn/tags/%s -m "
+             "\"Tagging version %s\""
+             % (self._state["svn_revision"], to_url, ver, ver))
+    self.Persist("to_url", to_url)
+
+
+class CleanUp(Step):
+  MESSAGE = "Cleanup."
+
+  def RunStep(self):
+    self.RestoreIfUnset("svn_revision")
+    self.RestoreIfUnset("to_url")
+    self.RestoreIfUnset("revision_list")
+    self.RestoreVersionIfUnset("new_")
+    ver = "%s.%s.%s.%s" % (self._state["new_major"],
+                           self._state["new_minor"],
+                           self._state["new_build"],
+                           self._state["new_patch"])
+    self.CommonCleanup()
+    if not self._options.revert_bleeding_edge:
+      print "*** SUMMARY ***"
+      print "version: %s" % ver
+      print "branch: %s" % self._state["to_url"]
+      print "svn revision: %s" % self._state["svn_revision"]
+      if self._state["revision_list"]:
+        print "patches: %s" % self._state["revision_list"]
+
+
+def RunMergeToBranch(config,
+                     options,
+                     side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER):
+  step_classes = [
+    Preparation,
+    CreateBranch,
+    SearchArchitecturePorts,
+    FindGitRevisions,
+    ApplyPatches,
+    PrepareVersion,
+    IncrementVersion,
+    CommitLocal,
+    UploadStep,
+    CommitRepository,
+    PrepareSVN,
+    TagRevision,
+    CleanUp,
+  ]
+
+  RunScript(step_classes, config, options, side_effect_handler)
+
+
+def BuildOptions():
+  result = optparse.OptionParser()
+  result.add_option("-f",
+                    help="Delete sentinel file.",
+                    default=False, action="store_true")
+  result.add_option("-m", "--message",
+                    help="Specify a commit message for the patch.")
+  result.add_option("-r", "--revert",
+                    help="Revert specified patches.",
+                    default=False, action="store_true")
+  result.add_option("-R", "--revert-bleeding-edge",
+                    help="Revert specified patches from bleeding edge.",
+                    default=False, action="store_true")
+  result.add_option("-p", "--patch", dest="p",
+ help="Specify a patch file to apply as part of the merge.")
+  result.add_option("-s", "--step", dest="s",
+ help="Specify the step where to start work. Default: 0.",
+                    default=0, type="int")
+  return result
+
+
+def ProcessOptions(options, args):
+  revert_from_bleeding_edge = 1 if options.revert_bleeding_edge else 0
+  min_exp_args = 2 - revert_from_bleeding_edge
+  if len(args) < min_exp_args:
+    if not options.p:
+      print "Either a patch file or revision numbers must be specified"
+      return False
+    if not options.message:
+      print "You must specify a merge comment if no patches are specified"
+      return False
+  if options.s < 0:
+    print "Bad step number %d" % options.s
+    return False
+  return True
+
+
+def Main():
+  parser = BuildOptions()
+  (options, args) = parser.parse_args()
+  if not ProcessOptions(options, args):
+    parser.print_help()
+    return 1
+  RunMergeToBranch(CONFIG, MergeToBranchOptions(options))
+
+if __name__ == "__main__":
+  sys.exit(Main())
=======================================
--- /trunk/src/version.cc       Fri Feb 14 10:06:37 2014 UTC
+++ /trunk/src/version.cc       Tue Feb 18 14:13:01 2014 UTC
@@ -35,7 +35,7 @@
 #define MAJOR_VERSION     3
 #define MINOR_VERSION     24
 #define BUILD_NUMBER      39
-#define PATCH_LEVEL       1
+#define PATCH_LEVEL       2
 // Use 1 for candidates and 0 otherwise.
 // (Boolean macro values are not supported by all preprocessors.)
 #define IS_CANDIDATE_VERSION 0
=======================================
--- /trunk/tools/merge-to-branch.sh     Fri Feb  7 09:11:16 2014 UTC
+++ /trunk/tools/merge-to-branch.sh     Tue Feb 18 14:13:01 2014 UTC
@@ -235,7 +235,6 @@
   echo ">>> Step $CURRENT_STEP: Apply patches for selected revisions."
   restore_if_unset "MERGE_TO_BRANCH"
   restore_patch_commit_hashes_if_unset "PATCH_COMMIT_HASHES"
-  rm -f "$TOUCHED_FILES_FILE"
   for HASH in ${PATCH_COMMIT_HASHES[@]} ; do
     echo "Applying patch for $HASH to $MERGE_TO_BRANCH..."
     git log -1 -p $HASH > "$TEMPORARY_PATCH_FILE"
=======================================
--- /trunk/tools/push-to-trunk/auto_roll.py     Tue Feb 11 08:13:48 2014 UTC
+++ /trunk/tools/push-to-trunk/auto_roll.py     Tue Feb 18 14:13:01 2014 UTC
@@ -52,7 +52,6 @@
     super(AutoRollOptions, self).__init__(options)
     self.requires_editor = False
     self.status_password = options.status_password
-    self.r = options.r
     self.c = options.c
     self.push = getattr(options, 'push', False)
     self.author = getattr(options, 'a', None)
@@ -162,7 +161,7 @@
               RunPushToTrunk,
               push_to_trunk.CONFIG,
               PushToTrunkOptions.MakeForcedOptions(self._options.author,
-                                                   self._options.r,
+                                                   self._options.reviewer,
                                                    self._options.c),
               self._side_effect_handler)
       finally:
@@ -197,7 +196,7 @@
   result.add_option("-p", "--push",
help="Push to trunk if possible. Dry run if unspecified.",
                     default=False, action="store_true")
-  result.add_option("-r", "--reviewer", dest="r",
+  result.add_option("-r", "--reviewer",
help=("Specify the account name to be used for reviews."))
   result.add_option("-s", "--step", dest="s",
help="Specify the step where to start work. Default: 0.",
@@ -210,7 +209,7 @@
 def Main():
   parser = BuildOptions()
   (options, args) = parser.parse_args()
-  if not options.a or not options.c or not options.r:
+  if not options.a or not options.c or not options.reviewer:
     print "You need to specify author, chromium src location and reviewer."
     parser.print_help()
     return 1
=======================================
--- /trunk/tools/push-to-trunk/common_includes.py Tue Feb 11 08:13:48 2014 UTC +++ /trunk/tools/push-to-trunk/common_includes.py Tue Feb 18 14:13:01 2014 UTC
@@ -227,6 +227,7 @@
     self.force_readline_defaults = not manual
     self.force_upload = not manual
     self.manual = manual
+    self.reviewer = getattr(options, 'reviewer', None)
     self.author = getattr(options, 'a', None)


@@ -302,6 +303,10 @@
cmd = lambda: self._side_effect_handler.Command("git", args, prefix, pipe)
     return self.Retry(cmd, retry_on, [5, 30])

+  def SVN(self, args="", prefix="", pipe=True, retry_on=None):
+ cmd = lambda: self._side_effect_handler.Command("svn", args, prefix, pipe)
+    return self.Retry(cmd, retry_on, [5, 30])
+
   def Editor(self, args):
     if self._options.requires_editor:
       return self._side_effect_handler.Command(os.environ["EDITOR"], args,
@@ -462,9 +467,9 @@
   MESSAGE = "Upload for code review."

   def RunStep(self):
-    if self._options.r:
-      print "Using account %s for review." % self._options.r
-      reviewer = self._options.r
+    if self._options.reviewer:
+      print "Using account %s for review." % self._options.reviewer
+      reviewer = self._options.reviewer
     else:
print "Please enter the email address of a V8 reviewer for your patch: ",
       self.DieNoManualMode("A reviewer must be specified in forced mode.")
=======================================
--- /trunk/tools/push-to-trunk/push_to_trunk.py Tue Feb 11 08:13:48 2014 UTC
+++ /trunk/tools/push-to-trunk/push_to_trunk.py Tue Feb 18 14:13:01 2014 UTC
@@ -63,7 +63,6 @@
     options.l = None
     options.f = True
     options.m = False
-    options.r = reviewer
     options.c = chrome_path
     options.a = author
     return PushToTrunkOptions(options)
@@ -74,7 +73,7 @@
     self.wait_for_lgtm = not options.f
     self.tbr_commit = not options.m
     self.l = options.l
-    self.r = options.r
+    self.reviewer = options.reviewer
     self.c = options.c
     self.author = getattr(options, 'a', None)

@@ -240,7 +239,10 @@

     # Include optional TBR only in the git command. The persisted commit
     # message is used for finding the commit again later.
- review = "\n\nTBR=%s" % self._options.r if self._options.tbr_commit else ""
+    if self._options.tbr_commit:
+      review = "\n\nTBR=%s" % self._options.reviewer
+    else:
+      review = ""
if self.Git("commit -a -m \"%s%s\"" % (prep_commit_msg, review)) is None:
       self.Die("'git commit -a' failed.")

@@ -481,9 +483,9 @@
     ver = "%s.%s.%s" % (self._state["major"],
                         self._state["minor"],
                         self._state["build"])
-    if self._options.r:
-      print "Using account %s for review." % self._options.r
-      rev = self._options.r
+    if self._options.reviewer:
+      print "Using account %s for review." % self._options.reviewer
+      rev = self._options.reviewer
     else:
print "Please enter the email address of a reviewer for the roll CL: ",
       self.DieNoManualMode("A reviewer must be specified in forced mode.")
@@ -587,7 +589,7 @@
   result.add_option("-m", "--manual", dest="m",
                     help="Prompt the user at every important step.",
                     default=False, action="store_true")
-  result.add_option("-r", "--reviewer", dest="r",
+  result.add_option("-r", "--reviewer",
help=("Specify the account name to be used for reviews."))
   result.add_option("-s", "--step", dest="s",
help="Specify the step where to start work. Default: 0.",
@@ -599,7 +601,7 @@
   if options.s < 0:
     print "Bad step number %d" % options.s
     return False
-  if not options.m and not options.r:
+  if not options.m and not options.reviewer:
     print "A reviewer (-r) is required in (semi-)automatic mode."
     return False
   if options.f and options.m:
=======================================
--- /trunk/tools/push-to-trunk/test_scripts.py  Tue Feb 11 08:13:48 2014 UTC
+++ /trunk/tools/push-to-trunk/test_scripts.py  Tue Feb 18 14:13:01 2014 UTC
@@ -31,15 +31,17 @@
 import traceback
 import unittest

-import common_includes
-from common_includes import *
-import push_to_trunk
-from push_to_trunk import *
 import auto_roll
 from auto_roll import AutoRollOptions
 from auto_roll import CheckLastPush
 from auto_roll import FetchLatestRevision
 from auto_roll import SETTINGS_LOCATION
+import common_includes
+from common_includes import *
+import merge_to_branch
+from merge_to_branch import *
+import push_to_trunk
+from push_to_trunk import *


 TEST_CONFIG = {
@@ -56,11 +58,15 @@
   CHROMIUM: "/tmp/test-v8-push-to-trunk-tempfile-chromium",
   DEPS_FILE: "/tmp/test-v8-push-to-trunk-tempfile-chromium/DEPS",
   SETTINGS_LOCATION: None,
+  ALREADY_MERGING_SENTINEL_FILE:
+      "/tmp/test-merge-to-branch-tempfile-already-merging",
+ COMMIT_HASHES_FILE: "/tmp/test-merge-to-branch-tempfile-PATCH_COMMIT_HASHES", + TEMPORARY_PATCH_FILE: "/tmp/test-merge-to-branch-tempfile-temporary-patch",
 }


 def MakeOptions(s=0, l=None, f=False, m=True, r=None, c=None, a=None,
-                status_password=None):
+                status_password=None, revert_bleeding_edge=None, p=None):
   """Convenience wrapper."""
   class Options(object):
       pass
@@ -69,10 +75,12 @@
   options.l = l
   options.f = f
   options.m = m
-  options.r = r
+  options.reviewer = r
   options.c = c
   options.a = a
+  options.p = p
   options.status_password = status_password
+  options.revert_bleeding_edge = revert_bleeding_edge
   return options


@@ -228,7 +236,7 @@
     try:
       expected_call = self._recipe[self._index]
     except IndexError:
-      raise Exception("Calling %s %s" % (self._name, " ".join(args)))
+ raise NoRetryException("Calling %s %s" % (self._name, " ".join(args)))

     # Pack expectations without arguments into a list.
     if not isinstance(expected_call, list):
@@ -303,6 +311,10 @@

   MOCKS = {
     "git": GitMock,
+ # TODO(machenbach): Little hack to reuse the git mock for the one svn call
+    # in merge-to-branch. The command should be made explicit in the test
+    # expectations.
+    "svn": GitMock,
     "vi": LogMock,
   }

@@ -837,6 +849,124 @@
auto_roll.RunAutoRoll(TEST_CONFIG, AutoRollOptions(MakeOptions()), self)
     self.assertRaises(Exception, RunAutoRoll)

+  def testMergeToBranch(self):
+    TEST_CONFIG[ALREADY_MERGING_SENTINEL_FILE] = self.MakeEmptyTempFile()
+    TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
+    TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()
+    os.environ["EDITOR"] = "vi"
+    extra_patch = self.MakeEmptyTempFile()
+
+    def VerifyPatch(patch):
+      return lambda: self.assertEquals(patch,
+          FileToText(TEST_CONFIG[TEMPORARY_PATCH_FILE]))
+
+ msg = """Merged r12345, r23456, r34567, r45678, r56789 into trunk branch.
+
+Title4
+
+Title2
+
+Title3
+
+Title1
+
+Title5
+
+BUG=123,234,345,456,567,v8:123
+LOG=N
+"""
+
+    def VerifySVNCommit():
+      commit = FileToText(TEST_CONFIG[COMMITMSG_FILE])
+      self.assertEquals(msg, commit)
+      version = FileToText(TEST_CONFIG[VERSION_FILE])
+      self.assertTrue(re.search(r"#define MINOR_VERSION\s+22", version))
+      self.assertTrue(re.search(r"#define BUILD_NUMBER\s+5", version))
+      self.assertTrue(re.search(r"#define PATCH_LEVEL\s+1", version))
+ self.assertTrue(re.search(r"#define IS_CANDIDATE_VERSION\s+0", version))
+
+    self.ExpectGit([
+      ["status -s -uno", ""],
+      ["status -s -b -uno", "## some_branch\n"],
+      ["svn fetch", ""],
+      ["branch", "  branch1\n* branch2\n"],
+      ["checkout -b %s" % TEST_CONFIG[TEMP_BRANCH], ""],
+      ["branch", "  branch1\n* branch2\n"],
+      ["checkout -b %s svn/trunk" % TEST_CONFIG[BRANCHNAME], ""],
+ ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r12345\"",
+       "hash1\nhash2"],
+      ["svn find-rev hash1 svn/bleeding_edge", "45678"],
+      ["log -1 --format=%s hash1", "Title1"],
+      ["svn find-rev hash2 svn/bleeding_edge", "23456"],
+      ["log -1 --format=%s hash2", "Title2"],
+ ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r23456\"",
+       ""],
+ ["log svn/bleeding_edge --reverse --format=%H --grep=\"Port r34567\"",
+       "hash3"],
+      ["svn find-rev hash3 svn/bleeding_edge", "56789"],
+      ["log -1 --format=%s hash3", "Title3"],
+      ["svn find-rev \"r12345\" svn/bleeding_edge", "hash4"],
+      ["svn find-rev \"r23456\" svn/bleeding_edge", "hash2"],
+      ["svn find-rev \"r34567\" svn/bleeding_edge", "hash3"],
+      ["svn find-rev \"r45678\" svn/bleeding_edge", "hash1"],
+      ["svn find-rev \"r56789\" svn/bleeding_edge", "hash5"],
+      ["log -1 --format=%s hash4", "Title4"],
+      ["log -1 --format=%s hash2", "Title2"],
+      ["log -1 --format=%s hash3", "Title3"],
+      ["log -1 --format=%s hash1", "Title1"],
+      ["log -1 --format=%s hash5", "Title5"],
+      ["log -1 hash4", "Title4\nBUG=123\nBUG=234"],
+      ["log -1 hash2", "Title2\n BUG = v8:123,345"],
+      ["log -1 hash3", "Title3\nLOG=n\nBUG=567, 456"],
+      ["log -1 hash1", "Title1"],
+      ["log -1 hash5", "Title5"],
+      ["log -1 -p hash4", "patch4"],
+ ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
+       "", VerifyPatch("patch4")],
+      ["log -1 -p hash2", "patch2"],
+ ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
+       "", VerifyPatch("patch2")],
+      ["log -1 -p hash3", "patch3"],
+ ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
+       "", VerifyPatch("patch3")],
+      ["log -1 -p hash1", "patch1"],
+ ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
+       "", VerifyPatch("patch1")],
+      ["log -1 -p hash5", "patch5"],
+ ["apply --index --reject \"%s\"" % TEST_CONFIG[TEMPORARY_PATCH_FILE],
+       "", VerifyPatch("patch5")],
+      ["apply --index --reject  \"%s\"" % extra_patch, ""],
+      ["commit -a -F \"%s\"" % TEST_CONFIG[COMMITMSG_FILE], ""],
+      ["cl upload -r \"[email protected]\" --send-mail", ""],
+      ["checkout %s" % TEST_CONFIG[BRANCHNAME], ""],
+      ["cl presubmit", "Presubmit successfull\n"],
+      ["cl dcommit -f --bypass-hooks", "Closing issue\n", VerifySVNCommit],
+      ["svn fetch", ""],
+      ["log -1 --format=%%H --grep=\"%s\" svn/trunk" % msg, "hash6"],
+      ["svn find-rev hash6", "1324"],
+      [("copy -r 1324 https://v8.googlecode.com/svn/trunk "
+        "https://v8.googlecode.com/svn/tags/3.22.5.1 -m "
+        "\"Tagging version 3.22.5.1\""), ""],
+      ["checkout -f some_branch", ""],
+      ["branch -D %s" % TEST_CONFIG[TEMP_BRANCH], ""],
+      ["branch -D %s" % TEST_CONFIG[BRANCHNAME], ""],
+    ])
+
+    self.ExpectReadline([
+      "Y",  # Automatically add corresponding ports (34567, 56789)?
+      "Y",  # Automatically increment patch level?
+      "[email protected]",  # V8 reviewer.
+      "LGTM",  # Enter LGTM for V8 CL.
+    ])
+
+    options = MakeOptions(p=extra_patch, f=True)
+ # r12345 and r34567 are patches. r23456 (included) and r45678 are the MIPS
+    # ports of r12345. r56789 is the MIPS port of r34567.
+    args = ["trunk", "12345", "23456", "34567"]
+    self.assertTrue(merge_to_branch.ProcessOptions(options, args))
+ RunMergeToBranch(TEST_CONFIG, MergeToBranchOptions(options, args), self)
+
+
 class SystemTest(unittest.TestCase):
   def testReload(self):
step = MakeStep(step_class=PrepareChangeLog, number=0, state={}, config={},

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to