fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

indexserver: create empty repos with proper ID (#206)

So far we called zoekt-archive-index to create empty repos. However,
zoekt-archive-index doesn't set the ID which causes trouble to decide
whether we should reindex or not.

With this change we don't call zoekt-archive-index anymore, but instead
created an empty shard directly from indexserver.

+45 -15
+2 -2
cmd/zoekt-sourcegraph-indexserver/cleanup_test.go
··· 130 130 fs = append(fs, f) 131 131 } 132 132 for _, f := range fs { 133 - createEmptyShard(t, f.RepoName, f.Path) 133 + createTestShard(t, f.RepoName, f.Path) 134 134 if err := os.Chtimes(f.Path, f.ModTime, f.ModTime); err != nil { 135 135 t.Fatal(err) 136 136 } ··· 171 171 } 172 172 } 173 173 174 - func createEmptyShard(t *testing.T, repo, path string) { 174 + func createTestShard(t *testing.T, repo, path string) { 175 175 t.Helper() 176 176 177 177 if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
+15 -13
cmd/zoekt-sourcegraph-indexserver/main.go
··· 416 416 tr.LazyPrintf("branches: %v", args.Branches) 417 417 418 418 if len(args.Branches) == 0 { 419 - return indexStateEmpty, s.createEmptyShard(tr, args.Name) 419 + return indexStateEmpty, createEmptyShard(args) 420 420 } 421 421 422 422 reason := "forced" ··· 480 480 } 481 481 } 482 482 483 - func (s *Server) createEmptyShard(tr trace.Trace, name string) error { 484 - cmd := exec.Command("zoekt-archive-index", 485 - "-index", s.IndexDir, 486 - "-incremental", 487 - "-branch", "HEAD", 488 - // dummy commit 489 - "-commit", "404aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 490 - "-name", name, 491 - "-") 492 - // Empty archive 493 - cmd.Stdin = bytes.NewBuffer(bytes.Repeat([]byte{0}, 1024)) 494 - return s.loggedRun(tr, cmd) 483 + func createEmptyShard(args *indexArgs) error { 484 + bo := args.BuildOptions() 485 + bo.SetDefaults() 486 + bo.RepositoryDescription.Branches = []zoekt.RepositoryBranch{{Name: "HEAD", Version: "404aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}} 487 + 488 + if args.Incremental && bo.IncrementalSkipIndexing() { 489 + return nil 490 + } 491 + 492 + builder, err := build.NewBuilder(*bo) 493 + if err != nil { 494 + return err 495 + } 496 + return builder.Finish() 495 497 } 496 498 497 499 var repoTmpl = template.Must(template.New("name").Parse(`
+28
cmd/zoekt-sourcegraph-indexserver/main_test.go
··· 12 12 "testing" 13 13 14 14 "github.com/google/go-cmp/cmp" 15 + "github.com/google/zoekt" 15 16 "github.com/hashicorp/go-retryablehttp" 16 17 ) 17 18 ··· 97 98 } 98 99 os.Exit(m.Run()) 99 100 } 101 + 102 + func TestCreateEmptyShard(t *testing.T) { 103 + dir := t.TempDir() 104 + 105 + args := &indexArgs{ 106 + IndexOptions: IndexOptions{ 107 + RepoID: 7, 108 + Name: "empty-repo", 109 + CloneURL: "code/host", 110 + }, 111 + Incremental: true, 112 + IndexDir: dir, 113 + Parallelism: 1, 114 + FileLimit: 1, 115 + } 116 + 117 + if err := createEmptyShard(args); err != nil { 118 + t.Fatal(err) 119 + } 120 + 121 + bo := args.BuildOptions() 122 + bo.RepositoryDescription.Branches = []zoekt.RepositoryBranch{{Name: "HEAD", Version: "404aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}} 123 + 124 + if got := bo.IncrementalSkipIndexing(); !got { 125 + t.Fatalf("wanted %t, got %t", true, got) 126 + } 127 + }