diff --git a/api.go b/api.go index 95b0b4228..f61302a10 100644 --- a/api.go +++ b/api.go @@ -638,9 +638,9 @@ func (r *Repository) UnmarshalJSON(data []byte) error { // Sourcegraph indexserver doesn't set repo.Rank, so we set it here. Setting it // on read instead of during indexing allows us to avoid a complete reindex. // - // Prefer "latest_commit_date" over "priority" for ranking. We keep priority for + // Prefer "latestCommitDate" over "priority" for ranking. We keep priority for // backwards compatibility. - if _, ok := repo.RawConfig["latest_commit_date"]; ok { + if _, ok := repo.RawConfig["latestCommitDate"]; ok { // We use the number of months since 1970 as a simple measure of repo freshness. // It is monotonically increasing and stable across re-indexes and restarts. r.Rank = monthsSince1970(repo.LatestCommitDate) diff --git a/cmd/zoekt-sourcegraph-indexserver/index.go b/cmd/zoekt-sourcegraph-indexserver/index.go index 7ffc01883..7c1ae785e 100644 --- a/cmd/zoekt-sourcegraph-indexserver/index.go +++ b/cmd/zoekt-sourcegraph-indexserver/index.go @@ -122,7 +122,7 @@ func (o *indexArgs) BuildOptions() *build.Options { "fork": marshalBool(o.Fork), "archived": marshalBool(o.Archived), // Calculate repo rank based on the latest commit date. - "latest_commit_date": "1", + "latestCommitDate": "1", }, }, IndexDir: o.IndexDir, diff --git a/cmd/zoekt-sourcegraph-indexserver/index_test.go b/cmd/zoekt-sourcegraph-indexserver/index_test.go index c1eeb1ace..fcc38f63d 100644 --- a/cmd/zoekt-sourcegraph-indexserver/index_test.go +++ b/cmd/zoekt-sourcegraph-indexserver/index_test.go @@ -14,6 +14,7 @@ import ( "time" "github.com/sourcegraph/log/logtest" + "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/protobuf/testing/protocmp" "google.golang.org/protobuf/types/known/timestamppb" @@ -494,7 +495,7 @@ func TestIndex(t *testing.T) { "git -C $TMPDIR/test%2Frepo.git update-ref HEAD deadbeef", "git -C $TMPDIR/test%2Frepo.git config zoekt.archived 0", "git -C $TMPDIR/test%2Frepo.git config zoekt.fork 0", - "git -C $TMPDIR/test%2Frepo.git config zoekt.latest_commit_date 1", + "git -C $TMPDIR/test%2Frepo.git config zoekt.latestCommitDate 1", "git -C $TMPDIR/test%2Frepo.git config zoekt.name test/repo", "git -C $TMPDIR/test%2Frepo.git config zoekt.priority 0", "git -C $TMPDIR/test%2Frepo.git config zoekt.public 0", @@ -517,7 +518,7 @@ func TestIndex(t *testing.T) { "git -C $TMPDIR/test%2Frepo.git update-ref HEAD deadbeef", "git -C $TMPDIR/test%2Frepo.git config zoekt.archived 0", "git -C $TMPDIR/test%2Frepo.git config zoekt.fork 0", - "git -C $TMPDIR/test%2Frepo.git config zoekt.latest_commit_date 1", + "git -C $TMPDIR/test%2Frepo.git config zoekt.latestCommitDate 1", "git -C $TMPDIR/test%2Frepo.git config zoekt.name test/repo", "git -C $TMPDIR/test%2Frepo.git config zoekt.priority 0", "git -C $TMPDIR/test%2Frepo.git config zoekt.public 0", @@ -549,7 +550,7 @@ func TestIndex(t *testing.T) { "git -C $TMPDIR/test%2Frepo.git update-ref refs/heads/dev feebdaed", "git -C $TMPDIR/test%2Frepo.git config zoekt.archived 0", "git -C $TMPDIR/test%2Frepo.git config zoekt.fork 0", - "git -C $TMPDIR/test%2Frepo.git config zoekt.latest_commit_date 1", + "git -C $TMPDIR/test%2Frepo.git config zoekt.latestCommitDate 1", "git -C $TMPDIR/test%2Frepo.git config zoekt.name test/repo", "git -C $TMPDIR/test%2Frepo.git config zoekt.priority 0", "git -C $TMPDIR/test%2Frepo.git config zoekt.public 0", @@ -597,7 +598,7 @@ func TestIndex(t *testing.T) { "git -C $TMPDIR/test%2Frepo.git update-ref refs/heads/release 12345678", "git -C $TMPDIR/test%2Frepo.git config zoekt.archived 0", "git -C $TMPDIR/test%2Frepo.git config zoekt.fork 0", - "git -C $TMPDIR/test%2Frepo.git config zoekt.latest_commit_date 1", + "git -C $TMPDIR/test%2Frepo.git config zoekt.latestCommitDate 1", "git -C $TMPDIR/test%2Frepo.git config zoekt.name test/repo", "git -C $TMPDIR/test%2Frepo.git config zoekt.priority 0", "git -C $TMPDIR/test%2Frepo.git config zoekt.public 0", @@ -685,3 +686,30 @@ func (m *mockGRPCClient) UpdateIndexStatus(ctx context.Context, in *proto.Update } var _ proto.ZoektConfigurationServiceClient = &mockGRPCClient{} + +// Tests whether we can set git config values without error. +func TestSetZoektConfig(t *testing.T) { + dir := t.TempDir() + + // init git dir + script := `mkdir repo +cd repo +git init -b main +` + cmd := exec.Command("/bin/sh", "-euxc", script) + cmd.Dir = dir + _, err := cmd.CombinedOutput() + require.NoError(t, err) + + var out []byte + c := gitIndexConfig{ + runCmd: func(cmd *exec.Cmd) error { + var err error + out, err = cmd.CombinedOutput() + return err + }, + } + + err = setZoektConfig(context.Background(), filepath.Join(dir, "repo"), &indexArgs{}, c) + require.NoError(t, err, string(out)) +} diff --git a/internal/e2e/e2e_rank_test.go b/internal/e2e/e2e_rank_test.go index ae70b882a..d68715f21 100644 --- a/internal/e2e/e2e_rank_test.go +++ b/internal/e2e/e2e_rank_test.go @@ -254,7 +254,7 @@ func indexURL(indexDir, u string) error { RepositoryDescription: zoekt.Repository{ // Use the latest commit date to calculate the repo rank when loading the shard. // This is the same setting we use in production. - RawConfig: map[string]string{"latest_commit_date": "1"}, + RawConfig: map[string]string{"latestCommitDate": "1"}, }, }) if err != nil {