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

Configure Feed

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

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.

+46 -1
+1 -1
index/eval.go
··· 498 498 } 499 499 500 500 var branches []string 501 - id := uint32(1) 501 + id := uint64(1) 502 502 branchNames := d.branchNames[d.repos[docID]] 503 503 for mask != 0 { 504 504 if mask&0x1 != 0 {
+45
index/eval_test.go
··· 19 19 "hash/fnv" 20 20 "reflect" 21 21 "regexp/syntax" 22 + "strconv" 22 23 "strings" 23 24 "testing" 24 25 ··· 417 418 } 418 419 } 419 420 } 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 + }