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

Commit 62401a7

Browse files
committed
gps: wildcard ignore skip ineffectual ignores
1 parent 3b24449 commit 62401a7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

internal/gps/pkgtree/pkgtree.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,15 @@ func uniq(a []string) []string {
950950
func CreateIgnorePrefixTree(ig map[string]bool) *radix.Tree {
951951
var xt *radix.Tree
952952

953-
for i := range ig {
953+
// Create a sorted list of all the ignores to have a proper order in
954+
// ignores parsing.
955+
sortedIgnores := make([]string, len(ig))
956+
for k := range ig {
957+
sortedIgnores = append(sortedIgnores, k)
958+
}
959+
sort.Strings(sortedIgnores)
960+
961+
for _, i := range sortedIgnores {
954962
// Skip global ignore.
955963
if i == "*" {
956964
continue
@@ -962,6 +970,12 @@ func CreateIgnorePrefixTree(ig map[string]bool) *radix.Tree {
962970
if xt == nil {
963971
xt = radix.New()
964972
}
973+
// Check if it is ineffectual.
974+
_, _, ok := xt.LongestPrefix(i)
975+
if ok {
976+
// Skip ineffectual wildcard ignore.
977+
continue
978+
}
965979
// Create the ignore prefix and insert in the radix tree.
966980
xt.Insert(i[:len(i)-len(wcIgnoreSuffix)], true)
967981
}

internal/gps/pkgtree/pkgtree_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,17 @@ func TestCreateIgnorePrefixTree(t *testing.T) {
20282028
wantInTree: []string{"gophers", "x/y/z"},
20292029
notWantInTree: []string{"*", "a/b/c"},
20302030
},
2031+
{
2032+
name: "ineffectual ignore with wildcard",
2033+
ignoreMap: map[string]bool{
2034+
"a/b*": true,
2035+
"a/b/c*": true,
2036+
"a/b/x/y": true,
2037+
"a/c*": true,
2038+
},
2039+
wantInTree: []string{"a/b", "a/c"},
2040+
notWantInTree: []string{"a/b/c", "a/b/x/y"},
2041+
},
20312042
}
20322043

20332044
for _, c := range cases {

0 commit comments

Comments
 (0)