diff options
Diffstat (limited to 'models/git/protected_branch_list.go')
-rw-r--r-- | models/git/protected_branch_list.go | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/models/git/protected_branch_list.go b/models/git/protected_branch_list.go index 17fe6d701f..eeb307e245 100644 --- a/models/git/protected_branch_list.go +++ b/models/git/protected_branch_list.go @@ -8,7 +8,7 @@ import ( "sort" "code.gitea.io/gitea/models/db" - "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/util" "github.com/gobwas/glob" ) @@ -47,19 +47,32 @@ func FindRepoProtectedBranchRules(ctx context.Context, repoID int64) (ProtectedB } // FindAllMatchedBranches find all matched branches -func FindAllMatchedBranches(ctx context.Context, gitRepo *git.Repository, ruleName string) ([]string, error) { - // FIXME: how many should we get? - branches, _, err := gitRepo.GetBranchNames(0, 9999999) - if err != nil { - return nil, err - } - rule := glob.MustCompile(ruleName) - results := make([]string, 0, len(branches)) - for _, branch := range branches { - if rule.Match(branch) { - results = append(results, branch) +func FindAllMatchedBranches(ctx context.Context, repoID int64, ruleName string) ([]string, error) { + results := make([]string, 0, 10) + for page := 1; ; page++ { + brancheNames, err := FindBranchNames(ctx, FindBranchOptions{ + ListOptions: db.ListOptions{ + PageSize: 100, + Page: page, + }, + RepoID: repoID, + IsDeletedBranch: util.OptionalBoolFalse, + }) + if err != nil { + return nil, err + } + rule := glob.MustCompile(ruleName) + + for _, branch := range brancheNames { + if rule.Match(branch) { + results = append(results, branch) + } + } + if len(brancheNames) < 100 { + break } } + return results, nil } |