Skip to content

Commit

Permalink
gps: wildcard ignore skip ineffectual ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Oct 7, 2017
1 parent fbfbad5 commit 9c4acd4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/gps/pkgtree/pkgtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,15 @@ func uniq(a []string) []string {
func CreateIgnorePrefixTree(ig map[string]bool) *radix.Tree {
var xt *radix.Tree

for i := range ig {
// Create a sorted list of all the ignores to have a proper order in
// ignores parsing.
sortedIgnores := make([]string, len(ig))
for k := range ig {
sortedIgnores = append(sortedIgnores, k)
}
sort.Strings(sortedIgnores)

for _, i := range sortedIgnores {
// Skip global ignore.
if i == "*" {
continue
Expand All @@ -1060,6 +1068,12 @@ func CreateIgnorePrefixTree(ig map[string]bool) *radix.Tree {
if xt == nil {
xt = radix.New()
}
// Check if it is ineffectual.
_, _, ok := xt.LongestPrefix(i)
if ok {
// Skip ineffectual wildcard ignore.
continue
}
// Create the ignore prefix and insert in the radix tree.
xt.Insert(i[:len(i)-len(wcIgnoreSuffix)], true)
}
Expand Down
11 changes: 11 additions & 0 deletions internal/gps/pkgtree/pkgtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,17 @@ func TestCreateIgnorePrefixTree(t *testing.T) {
wantInTree: []string{"gophers", "x/y/z"},
notWantInTree: []string{"*", "a/b/c"},
},
{
name: "ineffectual ignore with wildcard",
ignoreMap: map[string]bool{
"a/b*": true,
"a/b/c*": true,
"a/b/x/y": true,
"a/c*": true,
},
wantInTree: []string{"a/b", "a/c"},
notWantInTree: []string{"a/b/c", "a/b/x/y"},
},
}

for _, c := range cases {
Expand Down

0 comments on commit 9c4acd4

Please sign in to comment.