mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-20 16:10:50 +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:
parent
225044e656
commit
c764355676
11 changed files with 121 additions and 96 deletions
|
@ -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, ¬e)
|
||||
if err != nil {
|
||||
if err := git.GetNote(ctx, ctx.Repo.GitRepo, identifier, ¬e); 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue