From e4717d426e9b12c6d8d3ddf66ce9bd9889eea584 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Mon, 5 May 2025 04:43:42 +0800 Subject: [PATCH] Fix bug when visiting comparation page (#34334) (#34365) 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 | 10 ++-------- routers/web/repo/pull.go | 5 ----- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 13fbac981c..15200ff997 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -401,12 +401,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 @@ -721,11 +720,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 15c9658fa8..58c052db9e 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1290,11 +1290,6 @@ func CompareAndPullRequestPost(ctx *context.Context) { ) ci := ParseCompareInfo(ctx) - defer func() { - if ci != nil && ci.HeadGitRepo != nil { - ci.HeadGitRepo.Close() - } - }() if ctx.Written() { return }