diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-12-17 15:46:57 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-01-03 10:31:18 +0000 |
| commit | 96d578a30a157fa6dc4c66f95f4cab953fbebfb7 (patch) | |
| tree | 72446ff1f5cd4c13405f1abe0c3c0611b4aacc4c | |
| parent | d3ccff6372e07c6aabd02b5da419aa6492b5f0ad (diff) | |
pkg/vcs: extend ListCommitHashes
Support filtering by the commit date.
| -rw-r--r-- | pkg/email/lore/read.go | 3 | ||||
| -rw-r--r-- | pkg/vcs/fuchsia.go | 5 | ||||
| -rw-r--r-- | pkg/vcs/git.go | 11 | ||||
| -rw-r--r-- | pkg/vcs/git_test.go | 6 | ||||
| -rw-r--r-- | pkg/vcs/vcs.go | 2 |
5 files changed, 18 insertions, 9 deletions
diff --git a/pkg/email/lore/read.go b/pkg/email/lore/read.go index 1cfa680b6..7489f750f 100644 --- a/pkg/email/lore/read.go +++ b/pkg/email/lore/read.go @@ -5,6 +5,7 @@ package lore import ( "fmt" + "time" "github.com/google/syzkaller/pkg/vcs" ) @@ -16,7 +17,7 @@ type EmailReader struct { // ReadArchive queries the parsed messages from a single LKML message archive. func ReadArchive(dir string, messages chan<- *EmailReader) error { repo := vcs.NewLKMLRepo(dir) - commits, err := repo.ListCommitHashes("HEAD") + commits, err := repo.ListCommitHashes("HEAD", time.Time{}) if err != nil { return fmt.Errorf("failed to get recent commits: %w", err) } diff --git a/pkg/vcs/fuchsia.go b/pkg/vcs/fuchsia.go index 3f6983f3b..4a119baeb 100644 --- a/pkg/vcs/fuchsia.go +++ b/pkg/vcs/fuchsia.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "time" "github.com/google/syzkaller/pkg/osutil" ) @@ -105,8 +106,8 @@ func (ctx *fuchsia) Contains(commit string) (bool, error) { return ctx.repo.Contains(commit) } -func (ctx *fuchsia) ListCommitHashes(base string) ([]string, error) { - return ctx.repo.ListCommitHashes(base) +func (ctx *fuchsia) ListCommitHashes(baseCommit string, from time.Time) ([]string, error) { + return ctx.repo.ListCommitHashes(baseCommit, from) } func (ctx *fuchsia) Object(name, commit string) ([]byte, error) { diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index b75859338..d8a4967ba 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -381,11 +381,18 @@ func (git *git) GetCommitsByTitles(titles []string) ([]*Commit, []string, error) return results, missing, nil } -func (git *git) ListCommitHashes(baseCommit string) ([]string, error) { - output, err := git.git("log", "--pretty=format:%h", baseCommit) +func (git *git) ListCommitHashes(baseCommit string, from time.Time) ([]string, error) { + args := []string{"log", "--pretty=format:%h"} + if !from.IsZero() { + args = append(args, "--since", from.Format(time.RFC3339)) + } + output, err := git.git(append(args, baseCommit)...) if err != nil { return nil, err } + if len(output) == 0 { + return nil, nil + } return strings.Split(string(output), "\n"), nil } diff --git a/pkg/vcs/git_test.go b/pkg/vcs/git_test.go index daef69501..76c34dbd3 100644 --- a/pkg/vcs/git_test.go +++ b/pkg/vcs/git_test.go @@ -248,7 +248,7 @@ func TestCommitHashes(t *testing.T) { repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") repo.Git("checkout", "-b", "branch-b") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") - got, err := repo.repo.ListCommitHashes("HEAD") + got, err := repo.repo.ListCommitHashes("HEAD", time.Time{}) if err != nil { t.Fatal(err) } @@ -263,7 +263,7 @@ func TestCommitHashes(t *testing.T) { // Now change HEAD. repo.Git("checkout", "branch-a") - got, err = repo.repo.ListCommitHashes("HEAD") + got, err = repo.repo.ListCommitHashes("HEAD", time.Time{}) if err != nil { t.Fatal(err) } @@ -293,7 +293,7 @@ func TestObject(t *testing.T) { repo.Git("add", "object.txt") repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target") - commits, err := repo.repo.ListCommitHashes("HEAD") + commits, err := repo.repo.ListCommitHashes("HEAD", time.Time{}) if err != nil { t.Fatal(err) } diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index cb32a4071..494e9a673 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -63,7 +63,7 @@ type Repo interface { Contains(commit string) (bool, error) // ListCommitHashes lists all commit hashes reachable from baseCommit. - ListCommitHashes(baseCommit string) ([]string, error) + ListCommitHashes(baseCommit string, from time.Time) ([]string, error) // Object returns the contents of a git repository object at the particular moment in history. Object(name, commit string) ([]byte, error) |
