Skip to content

Commit 41f3d06

Browse files
authored
Fix bug when visiting comparation page (#34334)
The `ci.HeadGitRepo` was opened and closed in the function `ParseCompareInfo` but reused in the function `PrepareCompareDiff`.
1 parent 180aa00 commit 41f3d06

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

routers/web/repo/compare.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,11 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
402402
ci.HeadRepo = ctx.Repo.Repository
403403
ci.HeadGitRepo = ctx.Repo.GitRepo
404404
} else if has {
405-
ci.HeadGitRepo, err = gitrepo.OpenRepository(ctx, ci.HeadRepo)
405+
ci.HeadGitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ci.HeadRepo)
406406
if err != nil {
407-
ctx.ServerError("OpenRepository", err)
407+
ctx.ServerError("RepositoryFromRequestContextOrOpen", err)
408408
return nil
409409
}
410-
defer ci.HeadGitRepo.Close()
411410
} else {
412411
ctx.NotFound(nil)
413412
return nil
@@ -726,11 +725,6 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor
726725
// CompareDiff show different from one commit to another commit
727726
func CompareDiff(ctx *context.Context) {
728727
ci := ParseCompareInfo(ctx)
729-
defer func() {
730-
if ci != nil && ci.HeadGitRepo != nil {
731-
ci.HeadGitRepo.Close()
732-
}
733-
}()
734728
if ctx.Written() {
735729
return
736730
}

routers/web/repo/pull.go

-5
Original file line numberDiff line numberDiff line change
@@ -1296,11 +1296,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
12961296
)
12971297

12981298
ci := ParseCompareInfo(ctx)
1299-
defer func() {
1300-
if ci != nil && ci.HeadGitRepo != nil {
1301-
ci.HeadGitRepo.Close()
1302-
}
1303-
}()
13041299
if ctx.Written() {
13051300
return
13061301
}

0 commit comments

Comments
 (0)