summaryrefslogtreecommitdiffstats
path: root/routers/web/repo
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 /routers/web/repo
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 'routers/web/repo')
-rw-r--r--routers/web/repo/branch.go4
-rw-r--r--routers/web/repo/compare.go4
-rw-r--r--routers/web/repo/issue.go2
3 files changed, 5 insertions, 5 deletions
diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go
index 05b45eba4b..9c25180596 100644
--- a/routers/web/repo/branch.go
+++ b/routers/web/repo/branch.go
@@ -165,14 +165,14 @@ func redirect(ctx *context.Context) {
// loadBranches loads branches from the repository limited by page & pageSize.
// NOTE: May write to context on error.
func loadBranches(ctx *context.Context, skip, limit int) ([]*Branch, int) {
- defaultBranch, err := repo_service.GetBranch(ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch)
+ defaultBranch, err := ctx.Repo.GitRepo.GetBranch(ctx.Repo.Repository.DefaultBranch)
if err != nil {
log.Error("loadBranches: get default branch: %v", err)
ctx.ServerError("GetDefaultBranch", err)
return nil, 0
}
- rawBranches, totalNumOfBranches, err := repo_service.GetBranches(ctx.Repo.Repository, skip, limit)
+ rawBranches, totalNumOfBranches, err := ctx.Repo.GitRepo.GetBranches(skip, limit)
if err != nil {
log.Error("GetBranches: %v", err)
ctx.ServerError("GetBranches", err)
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 54d7e77f2d..4cd817a399 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -660,7 +660,7 @@ func getBranchesAndTagsForRepo(repo *models.Repository) (branches, tags []string
}
defer gitRepo.Close()
- branches, _, err = gitRepo.GetBranches(0, 0)
+ branches, _, err = gitRepo.GetBranchNames(0, 0)
if err != nil {
return nil, nil, err
}
@@ -711,7 +711,7 @@ func CompareDiff(ctx *context.Context) {
return
}
- headBranches, _, err := ci.HeadGitRepo.GetBranches(0, 0)
+ headBranches, _, err := ci.HeadGitRepo.GetBranchNames(0, 0)
if err != nil {
ctx.ServerError("GetBranches", err)
return
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index f0857b18c0..398aa26cc4 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -690,7 +690,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull boo
return nil
}
- brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0)
+ brs, _, err := ctx.Repo.GitRepo.GetBranchNames(0, 0)
if err != nil {
ctx.ServerError("GetBranches", err)
return nil