mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-05 06:15:45 +02:00
fix: git cache (#38763)
1. always use "last commit cache" 2. correctly build the cache key for any input (SafeCacheKey) 3. fix the git note "last commit cache FIXME" and avoid OOM
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"gitea.dev/modules/git"
|
||||
@@ -60,32 +59,23 @@ func GetNote(ctx *context.APIContext) {
|
||||
getNote(ctx, sha)
|
||||
}
|
||||
|
||||
func getNote(ctx *context.APIContext, identifier string) {
|
||||
if ctx.Repo.GitRepo == nil {
|
||||
ctx.APIErrorInternal(errors.New("no open git repo"))
|
||||
return
|
||||
}
|
||||
|
||||
commitID, err := ctx.Repo.GitRepo.ConvertToGitID(ctx, identifier)
|
||||
func getNote(ctx *context.APIContext, ref string) {
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ctx, ref)
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
return
|
||||
}
|
||||
|
||||
var note git.Note
|
||||
if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitID.String(), ¬e); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.APIErrorNotFound("commit doesn't exist: " + identifier)
|
||||
return
|
||||
}
|
||||
ctx.APIErrorInternal(err)
|
||||
note, lastCommit, err := git.GetNoteWithLastCommit(ctx, ctx.Repo.GitRepo, commit.ID.String())
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
return
|
||||
}
|
||||
|
||||
verification := ctx.FormString("verification") == "" || ctx.FormBool("verification")
|
||||
files := ctx.FormString("files") == "" || ctx.FormBool("files")
|
||||
|
||||
cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil,
|
||||
cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, lastCommit, nil,
|
||||
convert.ToCommitOptions{
|
||||
Stat: true,
|
||||
Verification: verification,
|
||||
@@ -95,6 +85,6 @@ func getNote(ctx *context.APIContext, identifier string) {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
apiNote := api.Note{Message: string(note.Message), Commit: cmt}
|
||||
apiNote := api.Note{Message: note.BlobMessage.MessageUTF8(), Commit: cmt}
|
||||
ctx.JSON(http.StatusOK, apiNote)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ package repo
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -21,9 +20,9 @@ import (
|
||||
unit_model "gitea.dev/models/unit"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/base"
|
||||
"gitea.dev/modules/charset"
|
||||
"gitea.dev/modules/fileicon"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/htmlutil"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/markup"
|
||||
"gitea.dev/modules/setting"
|
||||
@@ -406,13 +405,12 @@ func Diff(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
note := &git.Note{}
|
||||
err = git.GetNote(ctx, gitRepo, commitID, note)
|
||||
note, noteLastCommit, err := git.GetNoteWithLastCommit(ctx, gitRepo, commitID)
|
||||
if err == nil {
|
||||
ctx.Data["NoteCommit"] = note.Commit
|
||||
ctx.Data["NoteAuthor"] = user_model.GetUserByGitAuthor(ctx, note.Commit)
|
||||
ctx.Data["NoteCommit"] = noteLastCommit
|
||||
ctx.Data["NoteAuthor"] = user_model.GetUserByGitAuthor(ctx, noteLastCommit)
|
||||
rctx := renderhelper.NewRenderContextRepoComment(ctx, ctx.Repo.Repository, renderhelper.RepoCommentOptions{CurrentRefSubURL: "commit/" + util.PathEscapeSegments(commitID)})
|
||||
htmlMessage := template.HTML(template.HTMLEscapeString(string(charset.ToUTF8WithFallback(note.Message, charset.ConvertOpts{}))))
|
||||
htmlMessage := htmlutil.EscapeString(note.BlobMessage.MessageUTF8())
|
||||
ctx.Data["NoteRendered"] = markup.PostProcessCommitMessage(rctx, htmlMessage)
|
||||
} else if !git.IsErrNotExist(err) {
|
||||
log.Error("GetNote: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user