aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2025-05-04 11:52:00 -0700
committerGitHub <noreply@github.com>2025-05-04 18:52:00 +0000
commit41f3d062a2c3bb42cbcc75f1d8a6a68246e417ff (patch)
tree9fe14f7f17630df7c3cf32bd73c6d0705b74dc2f
parent180aa00abf4a7647e46b8cd8ed35dc5be43166b9 (diff)
downloadgitea-41f3d062a2c3bb42cbcc75f1d8a6a68246e417ff.tar.gz
gitea-41f3d062a2c3bb42cbcc75f1d8a6a68246e417ff.zip
Fix bug when visiting comparation page (#34334)
The `ci.HeadGitRepo` was opened and closed in the function `ParseCompareInfo` but reused in the function `PrepareCompareDiff`.
-rw-r--r--routers/web/repo/compare.go10
-rw-r--r--routers/web/repo/pull.go5
2 files changed, 2 insertions, 13 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 34d9710acb..8b99dd95da 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -402,12 +402,11 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
ci.HeadRepo = ctx.Repo.Repository
ci.HeadGitRepo = ctx.Repo.GitRepo
} else if has {
- ci.HeadGitRepo, err = gitrepo.OpenRepository(ctx, ci.HeadRepo)
+ ci.HeadGitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ci.HeadRepo)
if err != nil {
- ctx.ServerError("OpenRepository", err)
+ ctx.ServerError("RepositoryFromRequestContextOrOpen", err)
return nil
}
- defer ci.HeadGitRepo.Close()
} else {
ctx.NotFound(nil)
return nil
@@ -726,11 +725,6 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor
// CompareDiff show different from one commit to another commit
func CompareDiff(ctx *context.Context) {
ci := ParseCompareInfo(ctx)
- defer func() {
- if ci != nil && ci.HeadGitRepo != nil {
- ci.HeadGitRepo.Close()
- }
- }()
if ctx.Written() {
return
}
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 6a63240269..43ddc265cf 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -1296,11 +1296,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
)
ci := ParseCompareInfo(ctx)
- defer func() {
- if ci != nil && ci.HeadGitRepo != nil {
- ci.HeadGitRepo.Close()
- }
- }()
if ctx.Written() {
return
}