0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-25 04:22:46 +01:00

optimize loadGlob for protectedBranch

This commit is contained in:
6543 2024-10-16 23:07:58 +02:00
parent cbde69f6ee
commit ccb2e12189

View file

@ -83,14 +83,18 @@ func IsRuleNameSpecial(ruleName string) bool {
}
func (protectBranch *ProtectedBranch) loadGlob() {
if protectBranch.globRule == nil {
if protectBranch.globRule == nil && !protectBranch.isPlainName {
// detect if it is not glob
if !IsRuleNameSpecial(protectBranch.RuleName) {
protectBranch.isPlainName = true
return
}
var err error
protectBranch.globRule, err = glob.Compile(protectBranch.RuleName, '/')
if err != nil {
log.Warn("Invalid glob rule for ProtectedBranch[%d]: %s %v", protectBranch.ID, protectBranch.RuleName, err)
protectBranch.globRule = glob.MustCompile(glob.QuoteMeta(protectBranch.RuleName), '/')
}
protectBranch.isPlainName = !IsRuleNameSpecial(protectBranch.RuleName)
}
}