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

Configure Feed

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

build: respect order in compareBranches (#304)

For non-delta we don't treat branches as a set, but rather as a slice
where order is significant. Relying on this makes it easier to reason
about and implement. It also avoids the footgun we had around accidently
mutating repobranches on the read path when sorting. The order is
significant in the shard since each document records which branches it
is part of by the index.

Note we had to remove the IndexStateCorrupt test. We may want a way to
check this invariant somewhere else since this feels like a bug we could
introduce with delta.

Test Plan: unit tests.

+6 -20
+6 -12
build/builder.go
··· 690 690 } 691 691 692 692 func compareBranches(a, b []zoekt.RepositoryBranch) IndexState { 693 - set := make(map[string]string, len(a)) 694 - for _, branch := range a { 695 - if _, ok := set[branch.Name]; ok { // Duplicate branch 696 - return IndexStateCorrupt 697 - } 698 - set[branch.Name] = branch.Version 699 - } 700 - 701 - if len(set) != len(b) { 693 + if len(a) != len(b) { 702 694 return IndexStateBranchSet 703 695 } 704 696 705 - for _, branch := range b { 706 - if version, ok := set[branch.Name]; !ok { 697 + for i := range a { 698 + x, y := a[i], b[i] 699 + if x.Name != y.Name { 707 700 return IndexStateBranchSet 708 - } else if version != branch.Version { 701 + } 702 + if x.Version != y.Version { 709 703 return IndexStateBranchVersion 710 704 } 711 705 }
-8
build/builder_test.go
··· 411 411 newBranches: []zoekt.RepositoryBranch{{Name: "main", Version: "v1"}}, 412 412 expectedState: IndexStateBranchSet, 413 413 }, 414 - { 415 - oldBranches: []zoekt.RepositoryBranch{ 416 - {Name: "main", Version: "v1"}, 417 - {Name: "main", Version: "v2"}, 418 - }, 419 - newBranches: []zoekt.RepositoryBranch{{Name: "main", Version: "v3"}}, 420 - expectedState: IndexStateCorrupt, 421 - }, 422 414 } { 423 415 t.Run(strconv.Itoa(i), func(t *testing.T) { 424 416 indexDir := t.TempDir()