Skip to content

Commit 21a6aad

Browse files
GustedAbdulrhmnGhanem
authored andcommitted
Simplify IsVendor (go-gitea#19626)
The changes in this file were upstreamed directly into go-enry as go-enry/go-enry#44 and therefore they are no longer needed.
1 parent 6d530be commit 21a6aad

File tree

1 file changed

+2
-58
lines changed

1 file changed

+2
-58
lines changed

modules/analyze/vendor.go

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,10 @@
55
package analyze
66

77
import (
8-
"regexp"
9-
"sort"
10-
"strings"
11-
12-
"github.com/go-enry/go-enry/v2/data"
8+
"github.com/go-enry/go-enry/v2"
139
)
1410

15-
var isVendorRegExp *regexp.Regexp
16-
17-
func init() {
18-
matchers := data.VendorMatchers
19-
20-
caretStrings := make([]string, 0, 10)
21-
caretShareStrings := make([]string, 0, 10)
22-
23-
matcherStrings := make([]string, 0, len(matchers))
24-
for _, matcher := range matchers {
25-
str := matcher.String()
26-
if str[0] == '^' {
27-
caretStrings = append(caretStrings, str[1:])
28-
} else if str[0:5] == "(^|/)" {
29-
caretShareStrings = append(caretShareStrings, str[5:])
30-
} else {
31-
matcherStrings = append(matcherStrings, str)
32-
}
33-
}
34-
35-
sort.Strings(caretShareStrings)
36-
sort.Strings(caretStrings)
37-
sort.Strings(matcherStrings)
38-
39-
sb := &strings.Builder{}
40-
sb.WriteString("(?:^(?:")
41-
sb.WriteString(caretStrings[0])
42-
for _, matcher := range caretStrings[1:] {
43-
sb.WriteString(")|(?:")
44-
sb.WriteString(matcher)
45-
}
46-
sb.WriteString("))")
47-
sb.WriteString("|")
48-
sb.WriteString("(?:(?:^|/)(?:")
49-
sb.WriteString(caretShareStrings[0])
50-
for _, matcher := range caretShareStrings[1:] {
51-
sb.WriteString(")|(?:")
52-
sb.WriteString(matcher)
53-
}
54-
sb.WriteString("))")
55-
sb.WriteString("|")
56-
sb.WriteString("(?:")
57-
sb.WriteString(matcherStrings[0])
58-
for _, matcher := range matcherStrings[1:] {
59-
sb.WriteString(")|(?:")
60-
sb.WriteString(matcher)
61-
}
62-
sb.WriteString(")")
63-
combined := sb.String()
64-
isVendorRegExp = regexp.MustCompile(combined)
65-
}
66-
6711
// IsVendor returns whether or not path is a vendor path.
6812
func IsVendor(path string) bool {
69-
return isVendorRegExp.MatchString(path)
13+
return enry.IsVendor(path)
7014
}

0 commit comments

Comments
 (0)