diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-05-06 09:12:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-06 10:12:30 +0100 |
commit | 3ece9d5794420f9f11b2d0628dfe1ca83d24a357 (patch) | |
tree | e145520635595c28d4625e3a8e9496b66ce1486c /modules | |
parent | a7f52684cb7eeb746adf7a6609adbd4d42ae2815 (diff) | |
download | gitea-3ece9d5794420f9f11b2d0628dfe1ca83d24a357.tar.gz gitea-3ece9d5794420f9f11b2d0628dfe1ca83d24a357.zip |
Simplify `IsVendor` (#19626)
The changes in this file were upstreamed directly into go-enry as https://github.com/go-enry/go-enry/pull/44
and therefore they are no longer needed.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/analyze/vendor.go | 60 |
1 files changed, 2 insertions, 58 deletions
diff --git a/modules/analyze/vendor.go b/modules/analyze/vendor.go index 12ae8dbd80..976a6ddc7b 100644 --- a/modules/analyze/vendor.go +++ b/modules/analyze/vendor.go @@ -5,66 +5,10 @@ package analyze import ( - "regexp" - "sort" - "strings" - - "github.com/go-enry/go-enry/v2/data" + "github.com/go-enry/go-enry/v2" ) -var isVendorRegExp *regexp.Regexp - -func init() { - matchers := data.VendorMatchers - - caretStrings := make([]string, 0, 10) - caretShareStrings := make([]string, 0, 10) - - matcherStrings := make([]string, 0, len(matchers)) - for _, matcher := range matchers { - str := matcher.String() - if str[0] == '^' { - caretStrings = append(caretStrings, str[1:]) - } else if str[0:5] == "(^|/)" { - caretShareStrings = append(caretShareStrings, str[5:]) - } else { - matcherStrings = append(matcherStrings, str) - } - } - - sort.Strings(caretShareStrings) - sort.Strings(caretStrings) - sort.Strings(matcherStrings) - - sb := &strings.Builder{} - sb.WriteString("(?:^(?:") - sb.WriteString(caretStrings[0]) - for _, matcher := range caretStrings[1:] { - sb.WriteString(")|(?:") - sb.WriteString(matcher) - } - sb.WriteString("))") - sb.WriteString("|") - sb.WriteString("(?:(?:^|/)(?:") - sb.WriteString(caretShareStrings[0]) - for _, matcher := range caretShareStrings[1:] { - sb.WriteString(")|(?:") - sb.WriteString(matcher) - } - sb.WriteString("))") - sb.WriteString("|") - sb.WriteString("(?:") - sb.WriteString(matcherStrings[0]) - for _, matcher := range matcherStrings[1:] { - sb.WriteString(")|(?:") - sb.WriteString(matcher) - } - sb.WriteString(")") - combined := sb.String() - isVendorRegExp = regexp.MustCompile(combined) -} - // IsVendor returns whether or not path is a vendor path. func IsVendor(path string) bool { - return isVendorRegExp.MatchString(path) + return enry.IsVendor(path) } |