summaryrefslogtreecommitdiffstats
path: root/modules/git/repo_branch.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-12-08 19:08:16 +0000
committerGitHub <noreply@github.com>2021-12-08 19:08:16 +0000
commit9e6e1dc950f06bbd000d5b6438f39113e8902082 (patch)
tree204f359885c2bda09603de7de90b93f61c8e6922 /modules/git/repo_branch.go
parentb59875aa123f2cc3a5026d30ac557e99c05603a6 (diff)
downloadgitea-9e6e1dc950f06bbd000d5b6438f39113e8902082.tar.gz
gitea-9e6e1dc950f06bbd000d5b6438f39113e8902082.zip
Improve checkBranchName (#17901)
The current implementation of checkBranchName is highly inefficient involving opening the repository, the listing all of the branch names checking them individually before then using using opened repo to get the tags. This PR avoids this by simply walking the references from show-ref instead of opening the repository (in the nogogit case). Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/git/repo_branch.go')
-rw-r--r--modules/git/repo_branch.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go
index 98b1bc8ae7..01933d7ade 100644
--- a/modules/git/repo_branch.go
+++ b/modules/git/repo_branch.go
@@ -95,7 +95,12 @@ func GetBranchesByPath(path string, skip, limit int) ([]*Branch, int, error) {
}
defer gitRepo.Close()
- brs, countAll, err := gitRepo.GetBranches(skip, limit)
+ return gitRepo.GetBranches(skip, limit)
+}
+
+// GetBranches returns a slice of *git.Branch
+func (repo *Repository) GetBranches(skip, limit int) ([]*Branch, int, error) {
+ brs, countAll, err := repo.GetBranchNames(skip, limit)
if err != nil {
return nil, 0, err
}
@@ -103,9 +108,9 @@ func GetBranchesByPath(path string, skip, limit int) ([]*Branch, int, error) {
branches := make([]*Branch, len(brs))
for i := range brs {
branches[i] = &Branch{
- Path: path,
+ Path: repo.Path,
Name: brs[i],
- gitRepo: gitRepo,
+ gitRepo: repo,
}
}