summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-11-13 07:01:19 +0000
committerGitHub <noreply@github.com>2019-11-13 07:01:19 +0000
commit722a7c902dd39bd3d4328345ca969220640774d7 (patch)
tree7fb83b70fd9df55fd7d3a805adf38238d6a9bca8 /routers/api/v1/repo
parent7b97e045557788efee6803261cf612eaf975c6be (diff)
downloadgitea-722a7c902dd39bd3d4328345ca969220640774d7.tar.gz
gitea-722a7c902dd39bd3d4328345ca969220640774d7.zip
Add Close() method to gogitRepository (#8901)
In investigating #7947 it has become clear that the storage component of go-git repositories needs closing. This PR adds this Close function and adds the Close functions as necessary. In TransferOwnership the ctx.Repo.GitRepo is closed if it is open to help prevent the risk of multiple open files. Fixes #7947
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r--routers/api/v1/repo/commits.go2
-rw-r--r--routers/api/v1/repo/file.go1
-rw-r--r--routers/api/v1/repo/git_ref.go2
-rw-r--r--routers/api/v1/repo/pull.go7
-rw-r--r--routers/api/v1/repo/tag.go2
5 files changed, 13 insertions, 1 deletions
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go
index 0156aaaa05..163a06a95e 100644
--- a/routers/api/v1/repo/commits.go
+++ b/routers/api/v1/repo/commits.go
@@ -51,6 +51,7 @@ func GetSingleCommit(ctx *context.APIContext) {
ctx.ServerError("OpenRepository", err)
return
}
+ defer gitRepo.Close()
commit, err := gitRepo.GetCommit(ctx.Params(":sha"))
if err != nil {
ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err)
@@ -113,6 +114,7 @@ func GetAllCommits(ctx *context.APIContext) {
ctx.ServerError("OpenRepository", err)
return
}
+ defer gitRepo.Close()
page := ctx.QueryInt("page")
if page <= 0 {
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index f1a61bb0be..175235c5ef 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -95,6 +95,7 @@ func GetArchive(ctx *context.APIContext) {
return
}
ctx.Repo.GitRepo = gitRepo
+ defer gitRepo.Close()
repo.Download(ctx.Context)
}
diff --git a/routers/api/v1/repo/git_ref.go b/routers/api/v1/repo/git_ref.go
index d7acc139f0..c2bcbb3603 100644
--- a/routers/api/v1/repo/git_ref.go
+++ b/routers/api/v1/repo/git_ref.go
@@ -76,6 +76,8 @@ func getGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, strin
if err != nil {
return nil, "OpenRepository", err
}
+ defer gitRepo.Close()
+
if len(filter) > 0 {
filter = "refs/" + filter
}
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 6af1ba1b04..9abcaa0496 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -195,6 +195,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
if ctx.Written() {
return
}
+ defer headGitRepo.Close()
// Check if another PR exists with the same targets
existingPr, err := models.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch)
@@ -722,6 +723,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
if err != nil {
+ headGitRepo.Close()
ctx.ServerError("GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
@@ -732,6 +734,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
baseRepo,
permBase)
}
+ headGitRepo.Close()
ctx.NotFound("Can't read pulls or can't read UnitTypeCode")
return nil, nil, nil, nil, "", ""
}
@@ -739,6 +742,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
// user should have permission to read headrepo's codes
permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
if err != nil {
+ headGitRepo.Close()
ctx.ServerError("GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
@@ -749,18 +753,21 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headRepo,
permHead)
}
+ headGitRepo.Close()
ctx.NotFound("Can't read headRepo UnitTypeCode")
return nil, nil, nil, nil, "", ""
}
// Check if head branch is valid.
if !headGitRepo.IsBranchExist(headBranch) {
+ headGitRepo.Close()
ctx.NotFound()
return nil, nil, nil, nil, "", ""
}
compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch)
if err != nil {
+ headGitRepo.Close()
ctx.Error(500, "GetCompareInfo", err)
return nil, nil, nil, nil, "", ""
}
diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go
index 6cfdb461ee..0a764113ab 100644
--- a/routers/api/v1/repo/tag.go
+++ b/routers/api/v1/repo/tag.go
@@ -33,7 +33,7 @@ func ListTags(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/TagList"
- tags, err := ctx.Repo.Repository.GetTags()
+ tags, err := ctx.Repo.GitRepo.GetTagInfos()
if err != nil {
ctx.Error(500, "GetTags", err)
return