1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

RepoAssignment ensure to close before overwrite (#19449)

* check if GitRepo already open and close if

* only run RepoAssignment once

* refactor context helper for api to open GitRepo
This commit is contained in:
6543
2022-04-21 17:17:57 +02:00
committed by GitHub
parent 225044e656
commit c764355676
11 changed files with 121 additions and 96 deletions

View File

@@ -45,7 +45,8 @@ func GetBlob(ctx *context.APIContext) {
ctx.Error(http.StatusBadRequest, "", "sha not provided")
return
}
if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, sha); err != nil {
if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha); err != nil {
ctx.Error(http.StatusBadRequest, "", err)
} else {
ctx.JSON(http.StatusOK, blob)

View File

@@ -269,6 +269,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
// TODO: use gitRepo from context
if err := git.GetRawDiff(
ctx,
repoPath,

View File

@@ -62,22 +62,7 @@ func GetRawFile(ctx *context.APIContext) {
return
}
commit := ctx.Repo.Commit
if ref := ctx.FormTrim("ref"); len(ref) > 0 {
var err error
commit, err = ctx.Repo.GitRepo.GetCommit(ref)
if err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetBlobByPath", err)
}
return
}
}
blob, err := commit.GetBlobByPath(ctx.Repo.TreePath)
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound()
@@ -157,13 +142,18 @@ func GetEditorconfig(ctx *context.APIContext) {
// description: filepath of file to get
// type: string
// required: true
// - name: ref
// in: query
// description: "The name of the commit/branch/tag. Default the repositorys default branch (usually master)"
// type: string
// required: false
// responses:
// 200:
// description: success
// "404":
// "$ref": "#/responses/notFound"
ec, err := ctx.Repo.GetEditorconfig()
ec, err := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
if err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound(err)

View File

@@ -138,6 +138,11 @@ func TestHook(ctx *context.APIContext) {
// type: integer
// format: int64
// required: true
// - name: ref
// in: query
// description: "The name of the commit/branch/tag. Default the repositorys default branch (usually master)"
// type: string
// required: false
// responses:
// "204":
// "$ref": "#/responses/empty"

View File

@@ -55,15 +55,13 @@ func GetNote(ctx *context.APIContext) {
}
func getNote(ctx *context.APIContext, identifier string) {
gitRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
if ctx.Repo.GitRepo == nil {
ctx.InternalServerError(fmt.Errorf("no open git repo"))
return
}
defer gitRepo.Close()
var note git.Note
err = git.GetNote(ctx, gitRepo, identifier, &note)
if err != nil {
if err := git.GetNote(ctx, ctx.Repo.GitRepo, identifier, &note); err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound(identifier)
return
@@ -72,7 +70,7 @@ func getNote(ctx *context.APIContext, identifier string) {
return
}
cmt, err := convert.ToCommit(ctx.Repo.Repository, gitRepo, note.Commit, nil)
cmt, err := convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ToCommit", err)
return