Skip to content

Commit

Permalink
query: simplify empty BranchesRepos and RepoIDs
Browse files Browse the repository at this point in the history
We recently had an incident where this was accidently unset and lead to
lots of work done by zoekt which just got thrown away.

Test Plan: added unit test
  • Loading branch information
keegancsmith committed Nov 1, 2024
1 parent 27429a1 commit 56d3035
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,17 @@ func evalConstants(q Q) Q {
if s.Pattern == "" {
return &Const{true}
}
case *BranchesRepos:
for _, br := range s.List {
if !br.Repos.IsEmpty() {
return q
}
}
return &Const{false}
case *RepoIDs:
if s.Repos.IsEmpty() {
return &Const{false}
}
case *RepoSet:
if len(s.Set) == 0 {
return &Const{false}
Expand Down
14 changes: 14 additions & 0 deletions query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ func TestSimplify(t *testing.T) {
&Substring{Pattern: "byte"},
&Not{&Substring{Pattern: "byte"}}),
},
{
in: NewAnd(
NewSingleBranchesRepos("HEAD"), // Empty list matches nothing
&Not{&Type{Type: TypeRepo, Child: &Substring{Pattern: "hi"}}}),
want: &Const{false},
},
{
in: NewAnd(
NewSingleBranchesRepos("HEAD", 1),
&Not{&Type{Type: TypeRepo, Child: &Substring{Pattern: "hi"}}}),
want: NewAnd(
NewSingleBranchesRepos("HEAD", 1),
&Not{&Type{Type: TypeRepo, Child: &Substring{Pattern: "hi"}}}),
},
}

for _, c := range cases {
Expand Down

0 comments on commit 56d3035

Please sign in to comment.