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

Configure Feed

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

all: use BranchesRepos instead of RepoSet in tests (#165)

Want to move away from supporting RepoSet and try unify on
BranchesRepos. There is one use case left of RepoSet in List that is
still needed, otherwise we are close to removing support for it.

+18 -8
+1 -1
README.md
··· 18 18 - We have exposed the API via 19 19 [keegancsmith/rpc](https://github.com/keegancsmith/rpc) (a fork of `net/rpc` 20 20 which supports cancellation). 21 - - Query primitive `RepoSet` to efficiently specify a set of repositories to 21 + - Query primitive `BranchesRepos` to efficiently specify a set of repositories to 22 22 search. 23 23 - Allow empty shard directories on startup. Needed when starting a fresh 24 24 instance which hasn't indexed anything yet.
+9 -1
query/query.go
··· 179 179 List []BranchRepos 180 180 } 181 181 182 + // NewSingleBranchesRepos is a helper for creating a BranchesRepos which 183 + // searches a single branch. 184 + func NewSingleBranchesRepos(branch string, ids ...uint32) *BranchesRepos { 185 + return &BranchesRepos{List: []BranchRepos{ 186 + {branch, roaring.BitmapOf(ids...)}, 187 + }} 188 + } 189 + 182 190 func (q *BranchesRepos) String() string { 183 191 var sb strings.Builder 184 192 ··· 186 194 187 195 for _, br := range q.List { 188 196 if size := br.Repos.GetCardinality(); size > 1 { 189 - sb.WriteString(" " + br.Branch + ":" + strconv.FormatUint(size, 64)) 197 + sb.WriteString(" " + br.Branch + ":" + strconv.FormatUint(size, 10)) 190 198 } else { 191 199 sb.WriteString(" " + br.Branch + "=" + br.Repos.String()) 192 200 }
+2 -1
rpc/rpc_test.go
··· 15 15 16 16 func TestClientServer(t *testing.T) { 17 17 mock := &mockSearcher.MockSearcher{ 18 - WantSearch: query.NewAnd(mustParse("hello world|universe"), query.NewRepoSet("foo/bar", "baz/bam")), 18 + WantSearch: query.NewAnd(mustParse("hello world|universe"), query.NewSingleBranchesRepos("HEAD", 1, 2)), 19 19 SearchResult: &zoekt.SearchResult{ 20 20 Files: []zoekt.FileMatch{ 21 21 {FileName: "bin.go"}, ··· 27 27 Repos: []*zoekt.RepoListEntry{ 28 28 { 29 29 Repository: zoekt.Repository{ 30 + ID: 2, 30 31 Name: "foo/bar", 31 32 }, 32 33 },
+6 -5
shards/shards_test.go
··· 440 440 func reposForTest(n int) (result []*zoekt.Repository) { 441 441 for i := 0; i < n; i++ { 442 442 result = append(result, &zoekt.Repository{ 443 + ID: uint32(i + 1), 443 444 Name: fmt.Sprintf("test-repository-%d", i), 444 445 }) 445 446 } ··· 469 470 470 471 filesPerRepo := 300 471 472 repos := reposForTest(3000) 472 - repoSetNames := make([]string, 0, len(repos)/2) 473 + var repoSetIDs []uint32 473 474 474 475 for i, r := range repos { 475 476 searcher := testSearcherForRepo(b, r, filesPerRepo) 476 477 ss.replace(r.Name, searcher) 477 478 if i%2 == 0 { 478 - repoSetNames = append(repoSetNames, r.Name) 479 + repoSetIDs = append(repoSetIDs, r.ID) 479 480 } 480 481 } 481 482 ··· 488 489 489 490 setAnd := func(q query.Q) func() query.Q { 490 491 return func() query.Q { 491 - return query.NewAnd(query.NewRepoSet(repoSetNames...), q) 492 + return query.NewAnd(query.NewSingleBranchesRepos("head", repoSetIDs...), q) 492 493 } 493 494 } 494 495 ··· 513 514 {"substring no results", func() query.Q { return helloworldSub }, 0}, 514 515 {"substring some results", func() query.Q { return needleSub }, len(repos)}, 515 516 516 - {"substring all results and repo set", setAnd(haystackSub), len(repoSetNames) * filesPerRepo}, 517 - {"substring some results and repo set", setAnd(needleSub), len(repoSetNames)}, 517 + {"substring all results and repo set", setAnd(haystackSub), len(repoSetIDs) * filesPerRepo}, 518 + {"substring some results and repo set", setAnd(needleSub), len(repoSetIDs)}, 518 519 {"substring no results and repo set", setAnd(helloworldSub), 0}, 519 520 } 520 521