aboutsummaryrefslogtreecommitdiffstats
path: root/modules/context/repo.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-05-06 00:30:25 +0100
committerGitHub <noreply@github.com>2021-05-06 01:30:25 +0200
commiteedc0c8324820817f4c06603ec3195a1d3513542 (patch)
treead14f7d5baf7ffe8fe73d8704dd84193d8f84e4b /modules/context/repo.go
parente071b53686572c6a31c17655fbfa0035945cfb59 (diff)
downloadgitea-eedc0c8324820817f4c06603ec3195a1d3513542.tar.gz
gitea-eedc0c8324820817f4c06603ec3195a1d3513542.zip
Defer closing the gitrepo until the end of the wrapped context functions (#15653)
There was a mistake in #15372 where deferral of gitrepo close occurs before it should. This PR fixes this. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r--modules/context/repo.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 5ce31e9e35..8fc948b509 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -6,6 +6,7 @@
package context
import (
+ "context"
"fmt"
"io/ioutil"
"net/url"
@@ -393,7 +394,7 @@ func RepoIDAssignment() func(ctx *Context) {
}
// RepoAssignment returns a middleware to handle repository assignment
-func RepoAssignment(ctx *Context) {
+func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
var (
owner *models.User
err error
@@ -529,12 +530,12 @@ func RepoAssignment(ctx *Context) {
ctx.Repo.GitRepo = gitRepo
// We opened it, we should close it
- defer func() {
+ cancel = func() {
// If it's been set to nil then assume someone else has closed it.
if ctx.Repo.GitRepo != nil {
ctx.Repo.GitRepo.Close()
}
- }()
+ }
// Stop at this point when the repo is empty.
if ctx.Repo.Repository.IsEmpty {
@@ -619,6 +620,7 @@ func RepoAssignment(ctx *Context) {
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
}
+ return
}
// RepoRefType type of repo reference
@@ -643,7 +645,7 @@ const (
// RepoRef handles repository reference names when the ref name is not
// explicitly given
-func RepoRef() func(*Context) {
+func RepoRef() func(*Context) context.CancelFunc {
// since no ref name is explicitly specified, ok to just use branch
return RepoRefByType(RepoRefBranch)
}
@@ -722,8 +724,8 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
// RepoRefByType handles repository reference name for a specific type
// of repository reference
-func RepoRefByType(refType RepoRefType) func(*Context) {
- return func(ctx *Context) {
+func RepoRefByType(refType RepoRefType) func(*Context) context.CancelFunc {
+ return func(ctx *Context) (cancel context.CancelFunc) {
// Empty repository does not have reference information.
if ctx.Repo.Repository.IsEmpty {
return
@@ -742,12 +744,12 @@ func RepoRefByType(refType RepoRefType) func(*Context) {
return
}
// We opened it, we should close it
- defer func() {
+ cancel = func() {
// If it's been set to nil then assume someone else has closed it.
if ctx.Repo.GitRepo != nil {
ctx.Repo.GitRepo.Close()
}
- }()
+ }
}
// Get default branch.
@@ -841,6 +843,7 @@ func RepoRefByType(refType RepoRefType) func(*Context) {
return
}
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
+ return
}
}