Skip to content

Commit e4717d4

Browse files
GiteaBotlunny
andauthored
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 <[email protected]>
1 parent 16f15d2 commit e4717d4

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
@@ -401,12 +401,11 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
401401
ci.HeadRepo = ctx.Repo.Repository
402402
ci.HeadGitRepo = ctx.Repo.GitRepo
403403
} else if has {
404-
ci.HeadGitRepo, err = gitrepo.OpenRepository(ctx, ci.HeadRepo)
404+
ci.HeadGitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ci.HeadRepo)
405405
if err != nil {
406-
ctx.ServerError("OpenRepository", err)
406+
ctx.ServerError("RepositoryFromRequestContextOrOpen", err)
407407
return nil
408408
}
409-
defer ci.HeadGitRepo.Close()
410409
} else {
411410
ctx.NotFound(nil)
412411
return nil
@@ -721,11 +720,6 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor
721720
// CompareDiff show different from one commit to another commit
722721
func CompareDiff(ctx *context.Context) {
723722
ci := ParseCompareInfo(ctx)
724-
defer func() {
725-
if ci != nil && ci.HeadGitRepo != nil {
726-
ci.HeadGitRepo.Close()
727-
}
728-
}()
729723
if ctx.Written() {
730724
return
731725
}

routers/web/repo/pull.go

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

12921292
ci := ParseCompareInfo(ctx)
1293-
defer func() {
1294-
if ci != nil && ci.HeadGitRepo != nil {
1295-
ci.HeadGitRepo.Close()
1296-
}
1297-
}()
12981293
if ctx.Written() {
12991294
return
13001295
}

0 commit comments

Comments
 (0)