mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-15 02:41:48 +03:00
1dd83dbb91
The `GetAllCommits` endpoint can be pretty slow, especially in repos with a lot of commits. The issue is that it spends a lot of time calculating information that may not be useful/needed by the user. The `stat` param was previously added in #21337 to address this, by allowing the user to disable the calculating stats for each commit. But this has two issues: 1. The name `stat` is rather misleading, because disabling `stat` disables the Stat **and** Files. This should be separated out into two different params, because getting a list of affected files is much less expensive than calculating the stats 2. There's still other costly information provided that the user may not need, such as `Verification` This PR, adds two parameters to the endpoint, `files` and `verification` to allow the user to explicitly disable this information when listing commits. The default behavior is true.
88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
"code.gitea.io/gitea/modules/git"
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
"code.gitea.io/gitea/services/convert"
|
|
)
|
|
|
|
// GetNote Get a note corresponding to a single commit from a repository
|
|
func GetNote(ctx *context.APIContext) {
|
|
// swagger:operation GET /repos/{owner}/{repo}/git/notes/{sha} repository repoGetNote
|
|
// ---
|
|
// summary: Get a note corresponding to a single commit from a repository
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: owner
|
|
// in: path
|
|
// description: owner of the repo
|
|
// type: string
|
|
// required: true
|
|
// - name: repo
|
|
// in: path
|
|
// description: name of the repo
|
|
// type: string
|
|
// required: true
|
|
// - name: sha
|
|
// in: path
|
|
// description: a git ref or commit sha
|
|
// type: string
|
|
// required: true
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/Note"
|
|
// "422":
|
|
// "$ref": "#/responses/validationError"
|
|
// "404":
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
sha := ctx.Params(":sha")
|
|
if !git.IsValidRefPattern(sha) {
|
|
ctx.Error(http.StatusUnprocessableEntity, "no valid ref or sha", fmt.Sprintf("no valid ref or sha: %s", sha))
|
|
return
|
|
}
|
|
getNote(ctx, sha)
|
|
}
|
|
|
|
func getNote(ctx *context.APIContext, identifier string) {
|
|
if ctx.Repo.GitRepo == nil {
|
|
ctx.InternalServerError(fmt.Errorf("no open git repo"))
|
|
return
|
|
}
|
|
|
|
commitSHA, err := ctx.Repo.GitRepo.ConvertToSHA1(identifier)
|
|
if err != nil {
|
|
if git.IsErrNotExist(err) {
|
|
ctx.NotFound(err)
|
|
} else {
|
|
ctx.Error(http.StatusInternalServerError, "ConvertToSHA1", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
var note git.Note
|
|
if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitSHA.String(), ¬e); err != nil {
|
|
if git.IsErrNotExist(err) {
|
|
ctx.NotFound(identifier)
|
|
return
|
|
}
|
|
ctx.Error(http.StatusInternalServerError, "GetNote", err)
|
|
return
|
|
}
|
|
|
|
cmt, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, note.Commit, nil, convert.ToCommitOptions{Stat: true})
|
|
if err != nil {
|
|
ctx.Error(http.StatusInternalServerError, "ToCommit", err)
|
|
return
|
|
}
|
|
apiNote := api.Note{Message: string(note.Message), Commit: cmt}
|
|
ctx.JSON(http.StatusOK, apiNote)
|
|
}
|