From 9e6e1dc950f06bbd000d5b6438f39113e8902082 Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 8 Dec 2021 19:08:16 +0000 Subject: 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 --- modules/git/repo_branch.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'modules/git/repo_branch.go') 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, } } -- cgit v1.2.3