Skip to content

Commit 2303835

Browse files
committed
pkg/vcs: extend ListCommitHashes
Support filtering by the commit date.
1 parent 444551c commit 2303835

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

pkg/email/lore/read.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package lore
55

66
import (
77
"fmt"
8+
"time"
89

910
"github.com/google/syzkaller/pkg/vcs"
1011
)
@@ -16,7 +17,7 @@ type EmailReader struct {
1617
// ReadArchive queries the parsed messages from a single LKML message archive.
1718
func ReadArchive(dir string, messages chan<- *EmailReader) error {
1819
repo := vcs.NewLKMLRepo(dir)
19-
commits, err := repo.ListCommitHashes("HEAD")
20+
commits, err := repo.ListCommitHashes("HEAD", time.Time{})
2021
if err != nil {
2122
return fmt.Errorf("failed to get recent commits: %w", err)
2223
}

pkg/vcs/fuchsia.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"time"
1011

1112
"github.com/google/syzkaller/pkg/osutil"
1213
)
@@ -105,8 +106,8 @@ func (ctx *fuchsia) Contains(commit string) (bool, error) {
105106
return ctx.repo.Contains(commit)
106107
}
107108

108-
func (ctx *fuchsia) ListCommitHashes(base string) ([]string, error) {
109-
return ctx.repo.ListCommitHashes(base)
109+
func (ctx *fuchsia) ListCommitHashes(baseCommit string, from time.Time) ([]string, error) {
110+
return ctx.repo.ListCommitHashes(baseCommit, from)
110111
}
111112

112113
func (ctx *fuchsia) Object(name, commit string) ([]byte, error) {

pkg/vcs/git.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,18 @@ func (git *git) GetCommitsByTitles(titles []string) ([]*Commit, []string, error)
381381
return results, missing, nil
382382
}
383383

384-
func (git *git) ListCommitHashes(baseCommit string) ([]string, error) {
385-
output, err := git.git("log", "--pretty=format:%h", baseCommit)
384+
func (git *git) ListCommitHashes(baseCommit string, from time.Time) ([]string, error) {
385+
args := []string{"log", "--pretty=format:%h"}
386+
if !from.IsZero() {
387+
args = append(args, "--since", from.Format(time.RFC3339))
388+
}
389+
output, err := git.git(append(args, baseCommit)...)
386390
if err != nil {
387391
return nil, err
388392
}
393+
if len(output) == 0 {
394+
return nil, nil
395+
}
389396
return strings.Split(string(output), "\n"), nil
390397
}
391398

pkg/vcs/git_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func TestCommitHashes(t *testing.T) {
248248
repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target")
249249
repo.Git("checkout", "-b", "branch-b")
250250
repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target")
251-
got, err := repo.repo.ListCommitHashes("HEAD")
251+
got, err := repo.repo.ListCommitHashes("HEAD", time.Time{})
252252
if err != nil {
253253
t.Fatal(err)
254254
}
@@ -263,7 +263,7 @@ func TestCommitHashes(t *testing.T) {
263263

264264
// Now change HEAD.
265265
repo.Git("checkout", "branch-a")
266-
got, err = repo.repo.ListCommitHashes("HEAD")
266+
got, err = repo.repo.ListCommitHashes("HEAD", time.Time{})
267267
if err != nil {
268268
t.Fatal(err)
269269
}
@@ -293,7 +293,7 @@ func TestObject(t *testing.T) {
293293
repo.Git("add", "object.txt")
294294
repo.Git("commit", "--no-edit", "--allow-empty", "-m", "target")
295295

296-
commits, err := repo.repo.ListCommitHashes("HEAD")
296+
commits, err := repo.repo.ListCommitHashes("HEAD", time.Time{})
297297
if err != nil {
298298
t.Fatal(err)
299299
}

pkg/vcs/vcs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Repo interface {
6363
Contains(commit string) (bool, error)
6464

6565
// ListCommitHashes lists all commit hashes reachable from baseCommit.
66-
ListCommitHashes(baseCommit string) ([]string, error)
66+
ListCommitHashes(baseCommit string, from time.Time) ([]string, error)
6767

6868
// Object returns the contents of a git repository object at the particular moment in history.
6969
Object(name, commit string) ([]byte, error)

0 commit comments

Comments
 (0)