From 152311deec2469cdef26e9cca5bef385a3a98acc Mon Sep 17 00:00:00 2001 From: Jeff Peeler Date: Fri, 16 Jun 2017 14:59:01 -0400 Subject: [PATCH] Change git command for description extraction This code seems to perform slightly better and only retrieves the actual body/description of the commit with no additional whitespace. --- tools/rebasehelpers/commitchecker/commitchecker.go | 5 ++++- tools/rebasehelpers/util/git.go | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/rebasehelpers/commitchecker/commitchecker.go b/tools/rebasehelpers/commitchecker/commitchecker.go index 66ef7cef1388..6145bb677c03 100644 --- a/tools/rebasehelpers/commitchecker/commitchecker.go +++ b/tools/rebasehelpers/commitchecker/commitchecker.go @@ -30,7 +30,10 @@ func main() { // TODO: ...along with subtree merges. nonbumpCommits := []util.Commit{} for _, commit := range commits { - lastDescriptionLine := commit.Description[len(commit.Description)-1] + var lastDescriptionLine string + if descriptionLen := len(commit.Description); descriptionLen > 0 { + lastDescriptionLine = commit.Description[descriptionLen-1] + } if !strings.HasPrefix(commit.Summary, "bump(") && !strings.HasPrefix(lastDescriptionLine, "git-subtree-split:") { nonbumpCommits = append(nonbumpCommits, commit) } diff --git a/tools/rebasehelpers/util/git.go b/tools/rebasehelpers/util/git.go index 16407571c92d..f1c6bc06829d 100644 --- a/tools/rebasehelpers/util/git.go +++ b/tools/rebasehelpers/util/git.go @@ -343,7 +343,7 @@ func filesInCommit(sha string) ([]File, error) { func descriptionInCommit(sha string) ([]string, error) { descriptionLines := []string{} - stdout, stderr, err := run("git", "show", "--quiet", sha) + stdout, stderr, err := run("git", "log", "--pretty=%b", "-1", sha) if err != nil { return descriptionLines, fmt.Errorf("%s: %s", stderr, err) } @@ -352,7 +352,7 @@ func descriptionInCommit(sha string) ([]string, error) { if len(commitLine) == 0 { continue } - descriptionLines = append(descriptionLines, strings.Trim(commitLine, " ")) + descriptionLines = append(descriptionLines, commitLine) } return descriptionLines, nil }