Skip to content

Commit 2f07898

Browse files
lunnyGiteaBot
authored andcommitted
Fix bug when visiting comparation page (go-gitea#34334)
The `ci.HeadGitRepo` was opened and closed in the function `ParseCompareInfo` but reused in the function `PrepareCompareDiff`.
1 parent 046fc86 commit 2f07898

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

routers/web/repo/compare.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,11 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
400400
ci.HeadRepo = ctx.Repo.Repository
401401
ci.HeadGitRepo = ctx.Repo.GitRepo
402402
} else if has {
403-
ci.HeadGitRepo, err = gitrepo.OpenRepository(ctx, ci.HeadRepo)
403+
ci.HeadGitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ci.HeadRepo)
404404
if err != nil {
405-
ctx.ServerError("OpenRepository", err)
405+
ctx.ServerError("RepositoryFromRequestContextOrOpen", err)
406406
return nil
407407
}
408-
defer ci.HeadGitRepo.Close()
409408
} else {
410409
ctx.NotFound("ParseCompareInfo", nil)
411410
return nil
@@ -707,11 +706,6 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor
707706
// CompareDiff show different from one commit to another commit
708707
func CompareDiff(ctx *context.Context) {
709708
ci := ParseCompareInfo(ctx)
710-
defer func() {
711-
if ci != nil && ci.HeadGitRepo != nil {
712-
ci.HeadGitRepo.Close()
713-
}
714-
}()
715709
if ctx.Written() {
716710
return
717711
}

routers/web/repo/pull.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,11 +1262,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
12621262
)
12631263

12641264
ci := ParseCompareInfo(ctx)
1265-
defer func() {
1266-
if ci != nil && ci.HeadGitRepo != nil {
1267-
ci.HeadGitRepo.Close()
1268-
}
1269-
}()
12701265
if ctx.Written() {
12711266
return
12721267
}

0 commit comments

Comments
 (0)