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

Configure Feed

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

indexserver: allow faking ID in FS based discovery (#243)

This is useful when manually testing. I used this commit when testing
behaviour around repository renames.

+16 -3
+16 -3
cmd/zoekt-sourcegraph-indexserver/sg.go
··· 17 17 "path" 18 18 "path/filepath" 19 19 "strconv" 20 + "strings" 20 21 "time" 21 22 22 23 "github.com/google/zoekt" ··· 359 360 360 361 items := make([]indexOptionsItem, len(repos)) 361 362 err := sf.visitRepos(func(name string) { 362 - idx, ok := reposIdx[fakeID(name)] 363 + idx, ok := reposIdx[sf.id(name)] 363 364 if !ok { 364 365 return 365 366 } ··· 392 393 } 393 394 394 395 opts := IndexOptions{ 395 - RepoID: fakeID(name), 396 + RepoID: sf.id(name), 396 397 Name: name, 397 398 CloneURL: sf.getCloneURL(name), 398 399 Symbols: true, ··· 417 418 return opts, nil 418 419 } 419 420 421 + func (sf sourcegraphFake) id(name string) uint32 { 422 + // allow overriding the ID. 423 + idPath := filepath.Join(sf.RootDir, filepath.FromSlash(name), "SG_ID") 424 + if b, _ := os.ReadFile(idPath); len(b) > 0 { 425 + id, err := strconv.Atoi(strings.TrimSpace(string(b))) 426 + if err == nil { 427 + return uint32(id) 428 + } 429 + } 430 + return fakeID(name) 431 + } 432 + 420 433 func (sf sourcegraphFake) getCloneURL(name string) string { 421 434 return filepath.Join(sf.RootDir, filepath.FromSlash(name)) 422 435 } ··· 424 437 func (sf sourcegraphFake) ListRepoIDs(ctx context.Context, indexed []uint32) ([]uint32, error) { 425 438 var repos []uint32 426 439 err := sf.visitRepos(func(name string) { 427 - repos = append(repos, fakeID(name)) 440 + repos = append(repos, sf.id(name)) 428 441 }) 429 442 return repos, err 430 443 }