diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-11-07 13:30:25 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-11-07 13:31:00 +0100 |
| commit | 8f3e774b76b4fb0955dc360bb82d66a2c4bb3b39 (patch) | |
| tree | c018fa81d7e114de5c0758c8bc3c759d1a3af0ac /pkg/git | |
| parent | c1c91039f78f1920c923fa9294166257276c886a (diff) | |
syz-ci: improve commit matching
1. Fetch last 200K commits instead of commits for past year.
For merged commits both author date and commit date can be
arbitrary long in past (e.g. we got a commit dated by 2014).
2. Strip some commit prefixes from commits.
We have some trees where backports are prefixed with "BACKPORT:".
Previously we could no match such commits.
Diffstat (limited to 'pkg/git')
| -rw-r--r-- | pkg/git/git.go | 29 | ||||
| -rw-r--r-- | pkg/git/git_test.go | 23 |
2 files changed, 48 insertions, 4 deletions
diff --git a/pkg/git/git.go b/pkg/git/git.go index a239453f8..e3dc8a142 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -81,16 +81,37 @@ func HeadCommit(dir string) (string, error) { return string(output), nil } -// ListRecentCommits returns list of commit titles for the last year starting from baseCommit. +// ListRecentCommits returns list of recent commit titles starting from baseCommit. func ListRecentCommits(dir, baseCommit string) ([]string, error) { - since := time.Now().Add(-time.Hour * 24 * 365).Format("01-02-2006") - // On upstream kernel this produces 3.5MB of output. + // On upstream kernel this produces ~11MB of output. // Somewhat inefficient to collect whole output in a slice // and then convert to string, but should be bearable. output, err := osutil.RunCmd(timeout, dir, "git", "log", - "--pretty=format:%s", "--no-merges", "--since", since, baseCommit) + "--pretty=format:%s", "--no-merges", "-n", "200000", baseCommit) if err != nil { return nil, err } return strings.Split(string(output), "\n"), nil } + +// CanonicalizeCommit returns commit title that can be used when checking +// if a particular commit is present in a git tree. +// Some trees add prefixes to commit titles during backporting, +// so we want e.g. commit "foo bar" match "BACKPORT: foo bar". +func CanonicalizeCommit(title string) string { + for _, prefix := range commitPrefixes { + if strings.HasPrefix(title, prefix) { + title = title[len(prefix):] + break + } + } + return strings.TrimSpace(title) +} + +var commitPrefixes = []string{ + "UPSTREAM:", + "CHROMIUM:", + "FROMLIST:", + "BACKPORT:", + "net-backports:", +} diff --git a/pkg/git/git_test.go b/pkg/git/git_test.go new file mode 100644 index 000000000..42d2d3a07 --- /dev/null +++ b/pkg/git/git_test.go @@ -0,0 +1,23 @@ +// Copyright 2017 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package git + +import ( + "testing" +) + +func TestCanonicalizeCommit(t *testing.T) { + tests := map[string]string{ + "foo bar": "foo bar", + " foo ": "foo", + "UPSTREAM: foo bar": "foo bar", + "BACKPORT: UPSTREAM: foo bar": "UPSTREAM: foo bar", + } + for in, want := range tests { + got := CanonicalizeCommit(in) + if got != want { + t.Errorf("input %q: got %q, want %q", in, got, want) + } + } +} |
