This repository was archived by the owner on Sep 9, 2020. It is now read-only.
File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -950,7 +950,15 @@ func uniq(a []string) []string {
950
950
func CreateIgnorePrefixTree (ig map [string ]bool ) * radix.Tree {
951
951
var xt * radix.Tree
952
952
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 {
954
962
// Skip global ignore.
955
963
if i == "*" {
956
964
continue
@@ -962,6 +970,12 @@ func CreateIgnorePrefixTree(ig map[string]bool) *radix.Tree {
962
970
if xt == nil {
963
971
xt = radix .New ()
964
972
}
973
+ // Check if it is ineffectual.
974
+ _ , _ , ok := xt .LongestPrefix (i )
975
+ if ok {
976
+ // Skip ineffectual wildcard ignore.
977
+ continue
978
+ }
965
979
// Create the ignore prefix and insert in the radix tree.
966
980
xt .Insert (i [:len (i )- len (wcIgnoreSuffix )], true )
967
981
}
Original file line number Diff line number Diff line change @@ -2028,6 +2028,17 @@ func TestCreateIgnorePrefixTree(t *testing.T) {
2028
2028
wantInTree : []string {"gophers" , "x/y/z" },
2029
2029
notWantInTree : []string {"*" , "a/b/c" },
2030
2030
},
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
+ },
2031
2042
}
2032
2043
2033
2044
for _ , c := range cases {
You can’t perform that action at this time.
0 commit comments