aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/notes.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-04-21 17:17:57 +0200
committerGitHub <noreply@github.com>2022-04-21 17:17:57 +0200
commitc764355676eb6d67674d095f92576a85688fe6cb (patch)
treea72d604c29b704744a8e5bac38b4fa47afa430c5 /routers/api/v1/repo/notes.go
parent225044e6563e4ed2b41d1aed8b3967755c064fbb (diff)
downloadgitea-c764355676eb6d67674d095f92576a85688fe6cb.tar.gz
gitea-c764355676eb6d67674d095f92576a85688fe6cb.zip
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
Diffstat (limited to 'routers/api/v1/repo/notes.go')
-rw-r--r--routers/api/v1/repo/notes.go12
1 files changed, 5 insertions, 7 deletions
diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go
index f85883566f..bd8e27e40b 100644
--- a/routers/api/v1/repo/notes.go
+++ b/routers/api/v1/repo/notes.go
@@ -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