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))
-
- # 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"]))
+ text = FileToText(self.Config(CHANGELOG_ENTRY_FILE))
+
+ # 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.")
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"],
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()