mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-03 12:34:34 +00:00
refactor: remove Ctx field from git.Repository (#38500)
This commit is contained in:
@@ -47,7 +47,7 @@ func GetBlob(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if blob, err := files_service.GetBlobBySHA(ctx.Repo.Repository, ctx.Repo.GitRepo, sha); err != nil {
|
||||
if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha); err != nil {
|
||||
ctx.APIError(http.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
ctx.JSON(http.StatusOK, blob)
|
||||
|
||||
@@ -68,7 +68,7 @@ func GetBranch(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
c, err := ctx.Repo.GitRepo.GetBranchCommit(branchName)
|
||||
c, err := ctx.Repo.GitRepo.GetBranchCommit(ctx, branchName)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -219,14 +219,14 @@ func CreateBranch(ctx *context.APIContext) {
|
||||
var err error
|
||||
|
||||
if len(opt.OldRefName) > 0 {
|
||||
oldCommit, err = ctx.Repo.GitRepo.GetCommit(opt.OldRefName)
|
||||
oldCommit, err = ctx.Repo.GitRepo.GetCommit(ctx, opt.OldRefName)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
} else if len(opt.OldBranchName) > 0 { //nolint:staticcheck // deprecated field
|
||||
if exist, _ := git_model.IsBranchExist(ctx, ctx.Repo.Repository.ID, opt.OldBranchName); exist { //nolint:staticcheck // deprecated field
|
||||
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(opt.OldBranchName) //nolint:staticcheck // deprecated field
|
||||
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, opt.OldBranchName) //nolint:staticcheck // deprecated field
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -236,14 +236,14 @@ func CreateBranch(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
|
||||
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, ctx.Repo.Repository.DefaultBranch)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, oldCommit.ID.String(), opt.BranchName)
|
||||
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, oldCommit.ID.String(), opt.BranchName)
|
||||
if err != nil {
|
||||
if git_model.IsErrBranchNotExist(err) {
|
||||
ctx.APIError(http.StatusNotFound, "The old branch does not exist")
|
||||
@@ -259,7 +259,7 @@ func CreateBranch(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
commit, err := ctx.Repo.GitRepo.GetBranchCommit(opt.BranchName)
|
||||
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx, opt.BranchName)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -360,7 +360,7 @@ func ListBranches(ctx *context.APIContext) {
|
||||
|
||||
apiBranches = make([]*api.Branch, 0, len(branches))
|
||||
for i := range branches {
|
||||
c, err := ctx.Repo.GitRepo.GetBranchCommit(branches[i].Name)
|
||||
c, err := ctx.Repo.GitRepo.GetBranchCommit(ctx, branches[i].Name)
|
||||
if err != nil {
|
||||
// Skip if this branch doesn't exist anymore.
|
||||
if git.IsErrNotExist(err) {
|
||||
|
||||
@@ -74,7 +74,7 @@ func GetSingleCommit(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
func getCommit(ctx *context.APIContext, identifier string, toCommitOpts convert.ToCommitOptions) {
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(identifier)
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ctx, identifier)
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.APIErrorNotFound("commit doesn't exist: " + identifier)
|
||||
@@ -208,14 +208,14 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||
var baseCommit *git.Commit
|
||||
if len(sha) == 0 {
|
||||
// no sha supplied - use default branch
|
||||
baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
|
||||
baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, ctx.Repo.Repository.DefaultBranch)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// get commit specified by sha
|
||||
baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha)
|
||||
baseCommit, err = ctx.Repo.GitRepo.GetCommit(ctx, sha)
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
return
|
||||
@@ -235,7 +235,7 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// Query commits
|
||||
commits, err = baseCommit.CommitsByRange(ctx.Repo.GitRepo, listOptions.Page, listOptions.PageSize, not, since, until)
|
||||
commits, err = baseCommit.CommitsByRange(ctx, ctx.Repo.GitRepo, listOptions.Page, listOptions.PageSize, not, since, until)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -281,7 +281,7 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||
}
|
||||
}
|
||||
|
||||
commits, _, err = ctx.Repo.GitRepo.CommitsByFileAndRange(
|
||||
commits, _, err = ctx.Repo.GitRepo.CommitsByFileAndRange(ctx,
|
||||
git.CommitsByFileAndRangeOptions{
|
||||
Revision: sha,
|
||||
File: path,
|
||||
@@ -360,7 +360,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
|
||||
sha := ctx.PathParam("sha")
|
||||
diffType := git.RawDiffType(ctx.PathParam("diffType"))
|
||||
|
||||
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil {
|
||||
if err := git.GetRawDiff(ctx, ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.APIErrorNotFound("commit doesn't exist: " + sha)
|
||||
return
|
||||
|
||||
@@ -120,9 +120,9 @@ func downloadCompareDiffOrPatch(ctx *context.APIContext, compareInfo *git_servic
|
||||
|
||||
var err error
|
||||
if patch {
|
||||
err = compareInfo.HeadGitRepo.GetPatch(compareArg, ctx.Resp)
|
||||
err = compareInfo.HeadGitRepo.GetPatch(ctx, compareArg, ctx.Resp)
|
||||
} else {
|
||||
err = compareInfo.HeadGitRepo.GetDiff(compareArg, ctx.Resp)
|
||||
err = compareInfo.HeadGitRepo.GetDiff(ctx, compareArg, ctx.Resp)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func serveRepoArchive(ctx *context.APIContext, reqFileName string, paths []string) {
|
||||
aReq, err := archiver_service.NewRequest(ctx.Repo.Repository, ctx.Repo.GitRepo, reqFileName, paths)
|
||||
aReq, err := archiver_service.NewRequest(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, reqFileName, paths)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrInvalidArgument) {
|
||||
ctx.APIError(http.StatusBadRequest, err.Error())
|
||||
|
||||
@@ -136,7 +136,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
||||
|
||||
// LFS Pointer files are at most 1024 bytes - so any blob greater than 1024 bytes cannot be an LFS file
|
||||
if blob.Size() > lfs.MetaFileMaxSize {
|
||||
if blob.Size(ctx) > lfs.MetaFileMaxSize {
|
||||
// First handle caching for the blob
|
||||
if httpcache.HandleGenericETagPrivateCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
||||
return
|
||||
@@ -151,7 +151,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||
|
||||
// OK, now the blob is known to have at most 1024 (lfs pointer max size) bytes,
|
||||
// we can simply read this in one go (This saves reading it twice)
|
||||
lfsPointerBuf, err := blob.GetBlobBytes(lfs.MetaFileMaxSize)
|
||||
lfsPointerBuf, err := blob.GetBlobBytes(ctx, lfs.MetaFileMaxSize)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -217,7 +217,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
|
||||
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx, ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return nil, nil, nil
|
||||
|
||||
@@ -66,7 +66,7 @@ func getNote(ctx *context.APIContext, identifier string) {
|
||||
return
|
||||
}
|
||||
|
||||
commitID, err := ctx.Repo.GitRepo.ConvertToGitID(identifier)
|
||||
commitID, err := ctx.Repo.GitRepo.ConvertToGitID(ctx, identifier)
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
return
|
||||
|
||||
@@ -1107,7 +1107,7 @@ func parseCompareInfo(ctx *context.APIContext, compareParam string) (result *git
|
||||
headGitRepo = ctx.Repo.GitRepo
|
||||
closer = func() {} // no need to close the head repo because it shares the base repo
|
||||
} else {
|
||||
headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo)
|
||||
headGitRepo, err = gitrepo.OpenRepository(headRepo)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return nil, nil
|
||||
@@ -1146,12 +1146,12 @@ func parseCompareInfo(ctx *context.APIContext, compareParam string) (result *git
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
baseRef, err := common.ResolveRefWithSuffix(ctx.Repo.GitRepo, util.IfZero(compareReq.BaseOriRef, baseRepo.GetPullRequestTargetBranch(ctx)), compareReq.BaseOriRefSuffix)
|
||||
baseRef, err := common.ResolveRefWithSuffix(ctx, ctx.Repo.GitRepo, util.IfZero(compareReq.BaseOriRef, baseRepo.GetPullRequestTargetBranch(ctx)), compareReq.BaseOriRefSuffix)
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
return nil, nil
|
||||
}
|
||||
headRef, err := common.ResolveRefWithSuffix(headGitRepo, util.IfZero(compareReq.HeadOriRef, headRepo.DefaultBranch), compareReq.HeadOriRefSuffix)
|
||||
headRef, err := common.ResolveRefWithSuffix(ctx, headGitRepo, util.IfZero(compareReq.HeadOriRef, headRepo.DefaultBranch), compareReq.HeadOriRefSuffix)
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
return nil, nil
|
||||
@@ -1570,7 +1570,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
headCommitID, err := baseGitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
|
||||
@@ -526,7 +526,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
headCommitID, err := gitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -645,7 +645,7 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(ctx, pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
|
||||
@@ -269,7 +269,7 @@ func CreateRelease(ctx *context.APIContext) {
|
||||
}
|
||||
// GitHub doesn't have "tag_message", GitLab has: https://docs.gitlab.com/api/releases/#create-a-release
|
||||
// It doesn't need to be the same as the "release note"
|
||||
if err := release_service.CreateRelease(ctx.Repo.GitRepo, rel, nil, form.TagMessage); err != nil {
|
||||
if err := release_service.CreateRelease(ctx, ctx.Repo.GitRepo, rel, nil, form.TagMessage); err != nil {
|
||||
if repo_model.IsErrReleaseAlreadyExist(err) {
|
||||
ctx.APIError(http.StatusConflict, err.Error())
|
||||
} else if release_service.IsErrProtectedTagName(err) {
|
||||
|
||||
@@ -55,7 +55,7 @@ func ListTags(ctx *context.APIContext) {
|
||||
|
||||
listOpts := utils.GetListOptions(ctx)
|
||||
|
||||
tags, total, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize)
|
||||
tags, total, err := ctx.Repo.GitRepo.GetTagInfos(ctx, listOpts.Page, listOpts.PageSize)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -107,13 +107,13 @@ func GetAnnotatedTag(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha)
|
||||
tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(ctx, sha)
|
||||
if err != nil {
|
||||
ctx.APIError(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
commit, err := ctx.Repo.GitRepo.GetTagCommit(tag.Name)
|
||||
commit, err := ctx.Repo.GitRepo.GetTagCommit(ctx, tag.Name)
|
||||
if err != nil {
|
||||
ctx.APIError(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
@@ -151,7 +151,7 @@ func GetTag(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
tagName := ctx.PathParam("*")
|
||||
|
||||
tag, err := ctx.Repo.GitRepo.GetTag(tagName)
|
||||
tag, err := ctx.Repo.GitRepo.GetTag(ctx, tagName)
|
||||
if err != nil {
|
||||
ctx.APIErrorNotFound("tag doesn't exist: " + tagName)
|
||||
return
|
||||
@@ -201,7 +201,7 @@ func CreateTag(ctx *context.APIContext) {
|
||||
form.Target = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(form.Target)
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ctx, form.Target)
|
||||
if err != nil {
|
||||
ctx.APIError(http.StatusNotFound, fmt.Sprintf("target not found: %v", err))
|
||||
return
|
||||
@@ -221,7 +221,7 @@ func CreateTag(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
tag, err := ctx.Repo.GitRepo.GetTag(form.TagName)
|
||||
tag, err := ctx.Repo.GitRepo.GetTag(ctx, form.TagName)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
|
||||
@@ -196,7 +196,7 @@ func getWikiPage(ctx *context.APIContext, wikiName wiki_service.WebPath) *api.Wi
|
||||
commitsCount, _ := gitrepo.FileCommitsCount(ctx, ctx.Repo.Repository.WikiStorageRepo(), ctx.Repo.Repository.DefaultWikiBranch, pageFilename)
|
||||
|
||||
// Get last change information.
|
||||
lastCommit, err := wikiRepo.GetCommitByPath(pageFilename)
|
||||
lastCommit, err := wikiRepo.GetCommitByPath(ctx, pageFilename)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return nil
|
||||
@@ -313,7 +313,7 @@ func ListWikiPages(ctx *context.APIContext) {
|
||||
if i < skip || i >= maxNum || !entry.IsRegular() {
|
||||
continue
|
||||
}
|
||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||
c, err := wikiRepo.GetCommitByPath(ctx, entry.Name())
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -431,7 +431,7 @@ func ListPageRevisions(ctx *context.APIContext) {
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
// get Commit Count
|
||||
commitsHistory, _, err := wikiRepo.CommitsByFileAndRange(
|
||||
commitsHistory, _, err := wikiRepo.CommitsByFileAndRange(ctx,
|
||||
git.CommitsByFileAndRangeOptions{
|
||||
Revision: ctx.Repo.Repository.DefaultWikiBranch,
|
||||
File: pageFilename,
|
||||
@@ -468,13 +468,13 @@ func findEntryForFile(ctx *context.APIContext, wikiRepo *git.Repository, commit
|
||||
// findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error.
|
||||
// The caller is responsible for closing the returned repo again
|
||||
func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) {
|
||||
wikiRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository.WikiStorageRepo())
|
||||
wikiRepo, err := gitrepo.OpenRepository(ctx.Repo.Repository.WikiStorageRepo())
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
commit, err := wikiRepo.GetBranchCommit(ctx.Repo.Repository.DefaultWikiBranch)
|
||||
commit, err := wikiRepo.GetBranchCommit(ctx, ctx.Repo.Repository.DefaultWikiBranch)
|
||||
if err != nil {
|
||||
ctx.APIErrorAuto(err)
|
||||
return wikiRepo, nil
|
||||
@@ -486,10 +486,10 @@ func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit)
|
||||
// given tree entry, encoded with base64. Writes to ctx if an error occurs.
|
||||
func wikiContentsByEntry(ctx *context.APIContext, wikiRepo *git.Repository, entry *git.TreeEntry) string {
|
||||
blob := entry.Blob(wikiRepo)
|
||||
if blob.Size() > setting.API.DefaultMaxBlobSize {
|
||||
if blob.Size(ctx) > setting.API.DefaultMaxBlobSize {
|
||||
return ""
|
||||
}
|
||||
content, err := blob.GetBlobContentBase64(nil)
|
||||
content, err := blob.GetBlobContentBase64(ctx, nil)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return ""
|
||||
|
||||
@@ -38,7 +38,7 @@ func ResolveRefCommit(ctx reqctx.RequestContext, repo *repo_model.Repository, in
|
||||
if refCommit.RefName == "" {
|
||||
return nil, git.ErrNotExist{ID: inputRef}
|
||||
}
|
||||
if refCommit.Commit, err = gitRepo.GetCommit(refCommit.RefName.String()); err != nil {
|
||||
if refCommit.Commit, err = gitRepo.GetCommit(ctx, refCommit.RefName.String()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
refCommit.CommitID = refCommit.Commit.ID.String()
|
||||
@@ -57,6 +57,6 @@ func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, strin
|
||||
if len(filter) > 0 {
|
||||
filter = "refs/" + filter
|
||||
}
|
||||
refs, err := ctx.Repo.GitRepo.GetRefsFiltered(filter)
|
||||
refs, err := ctx.Repo.GitRepo.GetRefsFiltered(ctx, filter)
|
||||
return refs, "GetRefsFiltered", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user