From 8e5aa8fb1e0a11a5a0815c2d759f4da80f203cb0 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Mon, 5 May 2025 03:56:47 +0800 Subject: [PATCH] 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 --- routers/web/repo/compare.go | 3 +-- routers/web/repo/pull.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 278974bec3..9d241d3b51 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -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() } }() diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index e068ac45c6..ac08bf2a4f 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -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() } }()