Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/vcs: extend ListCommitHashes #5643

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/email/lore/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package lore

import (
"fmt"
"time"

"github.com/google/syzkaller/pkg/vcs"
)
Expand All @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/vcs/fuchsia.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/google/syzkaller/pkg/osutil"
)
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions pkg/vcs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/vcs/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading