Revision: 19494
Author:   [email protected]
Date:     Wed Feb 19 14:56:19 2014 UTC
Log:      Refactoring: Extract git checks in push and merge scripts.

This extracts the pattern "if call git fails: raise exception", which is spread all over the place. Now all calls to git are required to return gracefully and give a uniform exception message if they don't.

BUG=
[email protected]

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

Modified:
 /branches/bleeding_edge/tools/push-to-trunk/common_includes.py
 /branches/bleeding_edge/tools/push-to-trunk/merge_to_branch.py
 /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py

=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/common_includes.py Wed Feb 19 13:40:30 2014 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/common_includes.py Wed Feb 19 14:56:19 2014 UTC
@@ -220,6 +220,10 @@
   pass


+class GitFailedException(Exception):
+  pass
+
+
 class CommonOptions(object):
   def __init__(self, options, manual=True):
     self.requires_editor = True
@@ -320,7 +324,10 @@

   def Git(self, args="", prefix="", pipe=True, retry_on=None):
cmd = lambda: self._side_effect_handler.Command("git", args, prefix, pipe)
-    return self.Retry(cmd, retry_on, [5, 30])
+    result = self.Retry(cmd, retry_on, [5, 30])
+    if result is None:
+      raise GitFailedException("'git %s' failed." % args)
+    return result

   def SVN(self, args="", prefix="", pipe=True, retry_on=None):
cmd = lambda: self._side_effect_handler.Command("svn", args, prefix, pipe)
@@ -361,8 +368,7 @@
       if re.match(r".*\s+%s$" % name, line):
         msg = "Branch %s exists, do you want to delete it?" % name
         if self.Confirm(msg):
-          if self.Git("branch -D %s" % name) is None:
-            self.Die("Deleting branch '%s' failed." % name)
+          self.Git("branch -D %s" % name)
           print "Branch %s deleted." % name
         else:
msg = "Can't continue. Please delete branch %s and try again." % name
@@ -393,8 +399,7 @@
         break

     # Fetch unfetched revisions.
-    if self.Git("svn fetch") is None:
-      self.Die("'git svn fetch' failed.")
+    self.Git("svn fetch")

   def PrepareBranch(self):
     # Get ahold of a safe temporary branch and check it out.
@@ -457,7 +462,9 @@
   # Takes a file containing the patch to apply as first argument.
   def ApplyPatch(self, patch_file, reverse_patch=""):
     args = "apply --index --reject %s \"%s\"" % (reverse_patch, patch_file)
-    if self.Git(args) is None:
+    try:
+      self.Git(args)
+    except GitFailedException:
       self.WaitForResolvingConflicts(patch_file)

   def FindLastTrunkPush(self):
@@ -484,8 +491,7 @@
             % (author, reviewer, force_flag))
# TODO(machenbach): Check output in forced mode. Verify that all required
     # base files were uploaded, if not retry.
-    if self.Git(args, pipe=False) is None:
-      self.Die("'git cl upload' failed, please try again.")
+    self.Git(args, pipe=False)


 def MakeStep(step_class=Step, number=0, state=None, config=None,
=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/merge_to_branch.py Wed Feb 19 11:56:48 2014 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/merge_to_branch.py Wed Feb 19 14:56:19 2014 UTC
@@ -91,10 +91,8 @@
   MESSAGE = "Create a fresh branch for the patch."

   def RunStep(self):
-    args = "checkout -b %s svn/%s" % (self.Config(BRANCHNAME),
-                                      self["merge_to_branch"])
-    if self.Git(args) is None:
-      self.die("Creating branch %s failed." % self.Config(BRANCHNAME))
+    self.Git("checkout -b %s svn/%s" % (self.Config(BRANCHNAME),
+                                        self["merge_to_branch"]))


 class SearchArchitecturePorts(Step):
@@ -226,24 +224,17 @@
   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.")
+    self.Git("commit -a -F \"%s\"" % self.Config(COMMITMSG_FILE))


 class CommitRepository(Step):
   MESSAGE = "Commit to the repository."

   def RunStep(self):
-    if self.Git("checkout %s" % self.Config(BRANCHNAME)) is None:
-      self.Die("Cannot ensure that the current branch is %s"
-               % self.Config(BRANCHNAME))
+    self.Git("checkout %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"])
+    self.Git("cl presubmit", "PRESUBMIT_TREE_CHECK=\"skip\"")
+    self.Git("cl dcommit -f --bypass-hooks", retry_on=lambda x: x is None)


 class PrepareSVN(Step):
@@ -252,8 +243,7 @@
   def RunStep(self):
     if self._options.revert_bleeding_edge:
       return
-    if self.Git("svn fetch") is None:
-      self.Die("'git svn fetch' failed.")
+    self.Git("svn fetch")
     args = ("log -1 --format=%%H --grep=\"%s\" svn/%s"
             % (self["new_commit_msg"], self["merge_to_branch"]))
     commit_hash = self.Git(args).strip()
=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py Wed Feb 19 13:40:30 2014 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py Wed Feb 19 14:56:19 2014 UTC
@@ -97,8 +97,7 @@

   def RunStep(self):
     args = "checkout -b %s svn/bleeding_edge" % self.Config(BRANCHNAME)
-    if self.Git(args) is None:
-      self.Die("Creating branch %s failed." % self.Config(BRANCHNAME))
+    self.Git(args)


 class DetectLastPush(Step):
@@ -268,9 +267,7 @@
       review = "\n\nTBR=%s" % self._options.reviewer
     else:
       review = ""
-    if self.Git("commit -a -m \"%s%s\""
-                % (self["prep_commit_msg"], review)) is None:
-      self.Die("'git commit -a' failed.")
+    self.Git("commit -a -m \"%s%s\"" % (self["prep_commit_msg"], review))


 class CommitRepository(Step):
@@ -283,21 +280,16 @@
     TextToFile(GetLastChangeLogEntries(self.Config(CHANGELOG_FILE)),
                self.Config(CHANGELOG_ENTRY_FILE))

-    if self.Git("cl presubmit", "PRESUBMIT_TREE_CHECK=\"skip\"") is None:
-      self.Die("'git cl presubmit' failed, please try again.")
+    self.Git("cl presubmit", "PRESUBMIT_TREE_CHECK=\"skip\"")
+    self.Git("cl dcommit -f --bypass-hooks", retry_on=lambda x: x is None)

-    if self.Git("cl dcommit -f --bypass-hooks",
-                retry_on=lambda x: x is None) is None:
-      self.Die("'git cl dcommit' failed, please try again.")
-

 class StragglerCommits(Step):
MESSAGE = ("Fetch straggler commits that sneaked in since this script was "
              "started.")

   def RunStep(self):
-    if self.Git("svn fetch") is None:
-      self.Die("'git svn fetch' failed.")
+    self.Git("svn fetch")
     self.Git("checkout svn/bleeding_edge")
     args = "log -1 --format=%%H --grep=\"%s\"" % self["prep_commit_msg"]
     self["prepare_commit_hash"] = self.Git(args).strip()
@@ -342,9 +334,7 @@
   MESSAGE = "Create a new branch from trunk."

   def RunStep(self):
- if self.Git("checkout -b %s svn/trunk" % self.Config(TRUNKBRANCH)) is None:
-      self.Die("Checking out a new branch '%s' failed." %
-               self.Config(TRUNKBRANCH))
+    self.Git("checkout -b %s svn/trunk" % self.Config(TRUNKBRANCH))


 class ApplyChanges(Step):
@@ -380,8 +370,7 @@

   def RunStep(self):
     self.Git("add \"%s\"" % self.Config(VERSION_FILE))
-    if self.Git("commit -F \"%s\"" % self.Config(COMMITMSG_FILE)) is None:
-      self.Die("'git commit' failed.")
+    self.Git("commit -F \"%s\"" % self.Config(COMMITMSG_FILE))
     Command("rm", "-f %s*" % self.Config(COMMITMSG_FILE))


@@ -423,10 +412,9 @@
   MESSAGE = "Tag the new revision."

   def RunStep(self):
-    if self.Git(("svn tag %s -m \"Tagging version %s\""
-                 % (self["version"], self["version"])),
-                retry_on=lambda x: x is None) is None:
-      self.Die("'git svn tag' failed.")
+    self.Git(("svn tag %s -m \"Tagging version %s\""
+              % (self["version"], self["version"])),
+             retry_on=lambda x: x is None)


 class CheckChromium(Step):
@@ -466,14 +454,9 @@

   def RunStep(self):
     os.chdir(self["chrome_path"])
-    if self.Git("checkout master") is None:
-      self.Die("'git checkout master' failed.")
-    if self.Git("pull") is None:
-      self.Die("'git pull' failed, please try again.")
-
-    args = "checkout -b v8-roll-%s" % self["trunk_revision"]
-    if self.Git(args) is None:
-      self.Die("Failed to checkout a new branch.")
+    self.Git("checkout master")
+    self.Git("pull")
+    self.Git("checkout -b v8-roll-%s" % self["trunk_revision"])


 class UploadCL(Step):
@@ -497,17 +480,13 @@
print "Please enter the email address of a reviewer for the roll CL: ",
       self.DieNoManualMode("A reviewer must be specified in forced mode.")
       rev = self.ReadLine()
-    args = ("commit -am \"Update V8 to version %s "
-            "(based on bleeding_edge revision r%s).\n\nTBR=%s\""
-            % (self["version"], self["svn_revision"], rev))
-    if self.Git(args) is None:
-      self.Die("'git commit' failed.")
+    self.Git("commit -am \"Update V8 to version %s "
+             "(based on bleeding_edge revision r%s).\n\nTBR=%s\""
+             % (self["version"], self["svn_revision"], rev))
     author_option = self._options.author
     author = " --email \"%s\"" % author_option if author_option else ""
     force_flag = " -f" if self._options.force_upload else ""
-    if self.Git("cl upload%s --send-mail%s" % (author, force_flag),
-                pipe=False) is None:
-      self.Die("'git cl upload' failed, please try again.")
+ self.Git("cl upload%s --send-mail%s" % (author, force_flag), pipe=False)
     print "CL uploaded."


--
--
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