Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Wildcard ignores #1156

Merged
merged 12 commits into from
Oct 12, 2017
Prev Previous commit
Next Next commit
gps: wildcard ignore skip ineffectual ignores
  • Loading branch information
darkowlzz committed Oct 7, 2017
commit 9c4acd4f4047b2219579df682a14a36bc0de83ff
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not initialize a new tree here instead of checking for nil later on?

Copy link
Collaborator Author

@darkowlzz darkowlzz Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had that earlier but then we decided to allocate memory only when we get a wildcard suffix. Refer #1156 (comment)


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