Fix bug when visiting comparation page (#34334) (#34364)

Backport #34334 by @lunny

The `ci.HeadGitRepo` was opened and closed in the function
`ParseCompareInfo` but reused in the function `PrepareCompareDiff`.

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Giteabot 2025-05-05 03:56:47 +08:00 committed by GitHub
parent 046fc8684c
commit 8e5aa8fb1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 3 deletions

View File

@ -405,7 +405,6 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
ctx.ServerError("OpenRepository", err)
return nil
}
defer ci.HeadGitRepo.Close()
} else {
ctx.NotFound("ParseCompareInfo", nil)
return nil
@ -708,7 +707,7 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor
func CompareDiff(ctx *context.Context) {
ci := ParseCompareInfo(ctx)
defer func() {
if ci != nil && ci.HeadGitRepo != nil {
if !ctx.Repo.PullRequest.SameRepo && ci != nil && ci.HeadGitRepo != nil {
ci.HeadGitRepo.Close()
}
}()

View File

@ -1263,7 +1263,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
ci := ParseCompareInfo(ctx)
defer func() {
if ci != nil && ci.HeadGitRepo != nil {
if !ctx.Repo.PullRequest.SameRepo && ci != nil && ci.HeadGitRepo != nil {
ci.HeadGitRepo.Close()
}
}()