From c0b702098381e5e2560dd0b23de8b02dd0bb9f30 Mon Sep 17 00:00:00 2001 From: "machenbach@chromium.org" Date: Mon, 18 Nov 2013 13:34:32 +0000 Subject: [PATCH] Refactor ChangeLog generation for push-to-trunk script. This extracts the Git-independent part of the change log body generation. This CL intends no change in behavior. R=jkummerow@chromium.org Review URL: https://codereview.chromium.org/61263011 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17829 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- tools/push-to-trunk/common_includes.py | 28 ++++++++++++++++++++++++ tools/push-to-trunk/push_to_trunk.py | 39 +++++++++++----------------------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/tools/push-to-trunk/common_includes.py b/tools/push-to-trunk/common_includes.py index eb2bfb0..669aa6b 100644 --- a/tools/push-to-trunk/common_includes.py +++ b/tools/push-to-trunk/common_includes.py @@ -75,6 +75,34 @@ def GetLastChangeLogEntries(change_log_file): return "".join(result) +def MakeChangeLogBody(commit_generator): + result = "" + for (title, body, author) in commit_generator(): + # Add the commit's title line. + result += "%s\n" % title.rstrip() + + # Grep for "BUG=xxxx" lines in the commit message and convert them to + # "(issue xxxx)". + out = body.splitlines() + out = filter(lambda x: re.search(r"^BUG=", x), out) + out = filter(lambda x: not re.search(r"BUG=$", x), out) + out = filter(lambda x: not re.search(r"BUG=none$", x), out) + + # TODO(machenbach): Handle multiple entries (e.g. BUG=123, 234). + def FormatIssue(text): + text = re.sub(r"BUG=v8:(.*)$", r"(issue \1)", text) + text = re.sub(r"BUG=chromium:(.*)$", r"(Chromium issue \1)", text) + text = re.sub(r"BUG=(.*)$", r"(Chromium issue \1)", text) + return " %s\n" % text + + for line in map(FormatIssue, out): + result += line + + # Append the commit's author for reference. + result += "%s\n\n" % author.rstrip() + return result + + # Some commands don't like the pipe, e.g. calling vi from within the script or # from subscripts like git cl upload. def Command(cmd, args="", prefix="", pipe=True): diff --git a/tools/push-to-trunk/push_to_trunk.py b/tools/push-to-trunk/push_to_trunk.py index 669ba52..04e992d 100755 --- a/tools/push-to-trunk/push_to_trunk.py +++ b/tools/push-to-trunk/push_to_trunk.py @@ -110,37 +110,22 @@ class PrepareChangeLog(Step): args = "log %s..HEAD --format=%%H" % self._state["last_push"] commits = self.Git(args).strip() - for commit in commits.splitlines(): - # Get the commit's title line. - args = "log -1 %s --format=\"%%w(80,8,8)%%s\"" % commit - title = "%s\n" % self.Git(args).rstrip() - AppendToFile(title, self.Config(CHANGELOG_ENTRY_FILE)) - - # Grep for "BUG=xxxx" lines in the commit message and convert them to - # "(issue xxxx)". - out = self.Git("log -1 %s --format=\"%%B\"" % commit).splitlines() - out = filter(lambda x: re.search(r"^BUG=", x), out) - out = filter(lambda x: not re.search(r"BUG=$", x), out) - out = filter(lambda x: not re.search(r"BUG=none$", x), out) - - # TODO(machenbach): Handle multiple entries (e.g. BUG=123, 234). - def FormatIssue(text): - text = re.sub(r"BUG=v8:(.*)$", r"(issue \1)", text) - text = re.sub(r"BUG=chromium:(.*)$", r"(Chromium issue \1)", text) - text = re.sub(r"BUG=(.*)$", r"(Chromium issue \1)", text) - return " %s\n" % text - - for line in map(FormatIssue, out): - AppendToFile(line, self.Config(CHANGELOG_ENTRY_FILE)) - - # Append the commit's author for reference. - args = "log -1 %s --format=\"%%w(80,8,8)(%%an)\"" % commit - author = self.Git(args).rstrip() - AppendToFile("%s\n\n" % author, self.Config(CHANGELOG_ENTRY_FILE)) + + def GetCommitMessages(): + for commit in commits.splitlines(): + yield [ + self.Git("log -1 %s --format=\"%%w(80,8,8)%%s\"" % commit), + self.Git("log -1 %s --format=\"%%B\"" % commit), + self.Git("log -1 %s --format=\"%%w(80,8,8)(%%an)\"" % commit), + ] + + body = MakeChangeLogBody(GetCommitMessages) + AppendToFile(body, self.Config(CHANGELOG_ENTRY_FILE)) msg = " Performance and stability improvements on all platforms.\n" AppendToFile(msg, self.Config(CHANGELOG_ENTRY_FILE)) + class EditChangeLog(Step): def __init__(self): Step.__init__(self, "Edit ChangeLog entry.") -- 2.7.4