Revision: 18305
Author:   [email protected]
Date:     Wed Dec 11 15:05:53 2013 UTC
Log:      Make squash commits step more pythony in push-to-trunk script.

Get rid of linux-only shell commands. Solve issue with quotation marks in commit messages.

Further behavioral change: Strip white space on line endings. Strip trailing new lines.

Test=python -m unittest test_scripts

[email protected]

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

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

=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py Wed Dec 4 08:47:18 2013 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py Wed Dec 11 15:05:53 2013 UTC
@@ -257,31 +257,19 @@
     args = "diff svn/trunk %s" % self._state["prepare_commit_hash"]
     TextToFile(self.Git(args), self.Config(PATCH_FILE))

-    # Convert the ChangeLog entry to commit message format:
-    # - remove date
-    # - remove indentation
- # - merge paragraphs into single long lines, keeping empty lines between
-    #   them.
+    # Convert the ChangeLog entry to commit message format.
     self.RestoreIfUnset("date")
-    changelog_entry = FileToText(self.Config(CHANGELOG_ENTRY_FILE))
+    text = FileToText(self.Config(CHANGELOG_ENTRY_FILE))

- # TODO(machenbach): This could create a problem if the changelog contained
-    # any quotation marks.
-    text = Command("echo \"%s\" \
-        | sed -e \"s/^%s: //\" \
-        | sed -e 's/^ *//' \
-        | awk '{ \
-            if (need_space == 1) {\
-              printf(\" \");\
-            };\
-            printf(\"%%s\", $0);\
-            if ($0 ~ /^$/) {\
-              printf(\"\\n\\n\");\
-              need_space = 0;\
-            } else {\
-              need_space = 1;\
-            }\
-          }'" % (changelog_entry, self._state["date"]))
+    # Remove date and trailing white space.
+    text = re.sub(r"^%s: " % self._state["date"], "", text.rstrip())
+
+ # Remove indentation and merge paragraphs into single long lines, keeping
+    # empty lines between them.
+    def SplitMapJoin(split_text, fun, join_text):
+      return lambda text: join_text.join(map(fun, text.split(split_text)))
+    strip = lambda line: line.strip()
+ text = SplitMapJoin("\n\n", SplitMapJoin("\n", strip, " "), "\n\n")(text)

     if not text:
       self.Die("Commit message editing failed.")
=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/test_scripts.py Wed Dec 4 08:47:18 2013 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/test_scripts.py Wed Dec 11 15:05:53 2013 UTC
@@ -543,16 +543,10 @@
     cl = GetLastChangeLogEntries(TEST_CONFIG[CHANGELOG_FILE])
     self.assertEquals(cl_chunk, cl)

-  def testSquashCommits(self):
+  def _TestSquashCommits(self, change_log, expected_msg):
     TEST_CONFIG[CHANGELOG_ENTRY_FILE] = self.MakeEmptyTempFile()
     with open(TEST_CONFIG[CHANGELOG_ENTRY_FILE], "w") as f:
-      f.write("1999-11-11: Version 3.22.5\n")
-      f.write("\n")
-      f.write("        Log text 1.\n")
-      f.write("        Chromium issue 12345\n")
-      f.write("\n")
-      f.write("        Performance and stability improvements on all "
-              "platforms.\n")
+      f.write(change_log)

     self.ExpectGit([
       ["diff svn/trunk hash1", "patch content"],
@@ -562,16 +556,44 @@
     self.MakeStep().Persist("date", "1999-11-11")

     self.MakeStep(SquashCommits).Run()
-
-    msg = FileToText(TEST_CONFIG[COMMITMSG_FILE])
-    self.assertTrue(re.search(r"Version 3\.22\.5", msg))
-    self.assertTrue(re.search(r"Performance and stability", msg))
-    self.assertTrue(re.search(r"Log text 1\. Chromium issue 12345", msg))
-    self.assertFalse(re.search(r"\d+\-\d+\-\d+", msg))
+ self.assertEquals(FileToText(TEST_CONFIG[COMMITMSG_FILE]), expected_msg)

     patch = FileToText(TEST_CONFIG[ PATCH_FILE])
     self.assertTrue(re.search(r"patch content", patch))

+  def testSquashCommitsUnformatted(self):
+    change_log = """1999-11-11: Version 3.22.5
+
+        Log text 1.
+        Chromium issue 12345
+
+        Performance and stability improvements on all platforms.\n"""
+    commit_msg = """Version 3.22.5
+
+Log text 1. Chromium issue 12345
+
+Performance and stability improvements on all platforms."""
+    self._TestSquashCommits(change_log, commit_msg)
+
+  def testSquashCommitsFormatted(self):
+    change_log = """1999-11-11: Version 3.22.5
+
+ Long commit message that fills more than 80 characters (Chromium issue
+        12345).
+
+        Performance and stability improvements on all platforms.\n"""
+    commit_msg = """Version 3.22.5
+
+Long commit message that fills more than 80 characters (Chromium issue 12345).
+
+Performance and stability improvements on all platforms."""
+    self._TestSquashCommits(change_log, commit_msg)
+
+  def testSquashCommitsQuotationMarks(self):
+    change_log = """Line with "quotation marks".\n"""
+    commit_msg = """Line with "quotation marks"."""
+    self._TestSquashCommits(change_log, commit_msg)
+
   def _PushToTrunk(self, force=False, manual=False):
     TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
     TEST_CONFIG[VERSION_FILE] = self.MakeTempVersionFile()

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