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

Configure Feed

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

fix wildcards not getting expanded in delta build (#946)

Hi zoekt-Team,

when testing with our local instance I noticed that it seemed that delta builds where not correctly indexing only the delta that I expected, but much more. I looked at prepareDeltaBuild() and prepareNormalBuild() and found that prepareNormalBuild() expands the branches before processing them with expandBranches(), but prepareDeltaBuild() does not. This leads to a lot more indexing, because prepareDeltaBuild() can't find any known branches (that match the wildcard).
I added a call of expandBranches() to prepareDeltaBuild() to fix this and also added a test.

Regards,
Daniel

+32 -2
+7 -2
internal/gitindex/index.go
··· 689 689 // branch => (path, sha1) => repo. 690 690 repos = map[fileKey]BlobLocation{} 691 691 692 + branches, err := expandBranches(repository, options.Branches, options.BranchPrefix) 693 + if err != nil { 694 + return nil, nil, nil, fmt.Errorf("expandBranches: %w", err) 695 + } 696 + 692 697 // branch name -> git worktree at most current commit 693 - branchToCurrentTree := make(map[string]*object.Tree, len(options.Branches)) 698 + branchToCurrentTree := make(map[string]*object.Tree, len(branches)) 694 699 695 - for _, b := range options.Branches { 700 + for _, b := range branches { 696 701 commit, err := getCommit(repository, options.BranchPrefix, b) 697 702 if err != nil { 698 703 return nil, nil, nil, fmt.Errorf("getting last current commit for branch %q: %w", b, err)
+25
internal/gitindex/index_test.go
··· 449 449 }, 450 450 }, 451 451 { 452 + name: "should expand branches correctly when using wildcards in branch names", 453 + branches: []string{"release/1", "release/2"}, 454 + steps: []step{ 455 + { 456 + name: "setup", 457 + addedDocuments: branchToDocumentMap{ 458 + "release/1": []index.Document{fruitV1}, 459 + "release/2": []index.Document{fruitV2}, 460 + }, 461 + 462 + expectedDocuments: []index.Document{fruitV1, fruitV2}, 463 + }, 464 + { 465 + name: "try delta build with wildcard in branches", 466 + optFn: func(t *testing.T, o *Options) { 467 + // use a wildcard here 468 + o.Branches = []string{"HEAD", "release/*"} 469 + o.BuildOptions.IsDelta = true 470 + }, 471 + 472 + expectedDocuments: []index.Document{fruitV1, fruitV2}, 473 + }, 474 + }, 475 + }, 476 + { 452 477 name: "should fallback to normal build if one or more index options updates requires a full build", 453 478 branches: []string{"main"}, 454 479 steps: []step{