Skip to content

Commit 5c1352c

Browse files
authored
fix empty branch names getting returned by using uint64 id (#926)
The gatherBranches() function shifts a mask of type uint64 until it is 0, but uses an id for accessing a map of type uint32. This results in empty branch names getting returned from this function. It can be fixed by changing the type of id to also be uint64.
1 parent 36d2419 commit 5c1352c

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

index/eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ func (d *indexData) gatherBranches(docID uint32, mt matchTree, known map[matchTr
498498
}
499499

500500
var branches []string
501-
id := uint32(1)
501+
id := uint64(1)
502502
branchNames := d.branchNames[d.repos[docID]]
503503
for mask != 0 {
504504
if mask&0x1 != 0 {

index/eval_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"hash/fnv"
2020
"reflect"
2121
"regexp/syntax"
22+
"strconv"
2223
"strings"
2324
"testing"
2425

@@ -417,3 +418,47 @@ func TestGatherBranches(t *testing.T) {
417418
}
418419
}
419420
}
421+
422+
func TestGatherBranchesMany(t *testing.T) {
423+
content := []byte("dummy")
424+
manyBranchNames := []string{}
425+
manyBranches := []zoekt.RepositoryBranch{}
426+
for i := range 64 {
427+
branchName := "branch-" + strconv.Itoa(i)
428+
manyBranchNames = append(manyBranchNames, branchName)
429+
manyBranches = append(manyBranches, zoekt.RepositoryBranch{
430+
Name: branchName,
431+
Version: "v1"})
432+
}
433+
b := testShardBuilder(t, &zoekt.Repository{
434+
Branches: manyBranches,
435+
}, Document{Name: "f1", Content: content, Branches: manyBranchNames})
436+
437+
d := searcherForTest(t, b).(*indexData)
438+
439+
sr, err := d.Search(
440+
context.Background(),
441+
&query.Substring{
442+
Pattern: "dummy",
443+
CaseSensitive: false,
444+
},
445+
&zoekt.SearchOptions{},
446+
)
447+
if err != nil {
448+
t.Fatal(err)
449+
}
450+
451+
want := map[string][]string{
452+
"f1": manyBranchNames,
453+
}
454+
455+
if len(sr.Files) != 1 {
456+
t.Fatalf("len(sr.Files): want %d, got %d", 1, len(sr.Files))
457+
}
458+
459+
for _, f := range sr.Files {
460+
if d := cmp.Diff(want[f.FileName], f.Branches); d != "" {
461+
t.Fatalf("-want,+got:\n%s", d)
462+
}
463+
}
464+
}

0 commit comments

Comments
 (0)