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

sourcegraph: fix wrong git config #841

Merged
merged 1 commit into from
Oct 1, 2024
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
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/zoekt-sourcegraph-indexserver/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 32 additions & 4 deletions cmd/zoekt-sourcegraph-indexserver/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion internal/e2e/e2e_rank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading