mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-28 14:29:42 +09:00
refactor: remove Ctx field from git.Repository (#38500)
This commit is contained in:
@@ -306,11 +306,11 @@ func RepoRefForAPI(next http.Handler) http.Handler {
|
||||
var err error
|
||||
switch refType {
|
||||
case git.RefTypeBranch:
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, refName)
|
||||
case git.RefTypeTag:
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(ctx, refName)
|
||||
case git.RefTypeCommit:
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(ctx, refName)
|
||||
}
|
||||
if ctx.Repo.Commit == nil || errors.Is(err, util.ErrNotExist) {
|
||||
ctx.APIErrorNotFound("unable to find a git ref")
|
||||
|
||||
+16
-12
@@ -301,7 +301,7 @@ func (r *Repository) GetEditorconfig(ctx context.Context, optCommit ...*git.Comm
|
||||
if len(optCommit) != 0 {
|
||||
commit = optCommit[0]
|
||||
} else {
|
||||
commit, err = r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch)
|
||||
commit, err = r.GitRepo.GetBranchCommit(ctx, r.Repository.DefaultBranch)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -310,10 +310,10 @@ func (r *Repository) GetEditorconfig(ctx context.Context, optCommit ...*git.Comm
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if treeEntry.Blob(r.GitRepo).Size() >= setting.UI.MaxDisplayFileSize {
|
||||
if treeEntry.Blob(r.GitRepo).Size(ctx) >= setting.UI.MaxDisplayFileSize {
|
||||
return nil, nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"}
|
||||
}
|
||||
reader, err := treeEntry.Blob(r.GitRepo).DataAsync()
|
||||
reader, err := treeEntry.Blob(r.GitRepo).DataAsync(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -830,7 +830,9 @@ func getRefNameLegacy(ctx *Base, repo *Repository, reqPath, extraRef string) (re
|
||||
func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) string {
|
||||
switch refType {
|
||||
case git.RefTypeBranch:
|
||||
ref := getRefNameFromPath(repo, path, repo.GitRepo.IsBranchExist)
|
||||
ref := getRefNameFromPath(repo, path, func(s string) bool {
|
||||
return repo.GitRepo.IsBranchExist(ctx, s)
|
||||
})
|
||||
if len(ref) == 0 {
|
||||
// check if ref is HEAD
|
||||
parts := strings.Split(path, "/")
|
||||
@@ -860,7 +862,9 @@ func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) s
|
||||
|
||||
return ref
|
||||
case git.RefTypeTag:
|
||||
return getRefNameFromPath(repo, path, repo.GitRepo.IsTagExist)
|
||||
return getRefNameFromPath(repo, path, func(s string) bool {
|
||||
return repo.GitRepo.IsTagExist(ctx, s)
|
||||
})
|
||||
case git.RefTypeCommit:
|
||||
parts := strings.Split(path, "/")
|
||||
if git.IsStringLikelyCommitID(repo.GetObjectFormat(), parts[0], 7) {
|
||||
@@ -871,7 +875,7 @@ func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) s
|
||||
|
||||
if parts[0] == headRefName {
|
||||
// HEAD ref points to last default branch commit
|
||||
commit, err := repo.GitRepo.GetBranchCommit(repo.Repository.DefaultBranch)
|
||||
commit, err := repo.GitRepo.GetBranchCommit(ctx, repo.Repository.DefaultBranch)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
@@ -902,7 +906,7 @@ func RepoRefByDefaultBranch() func(*Context) {
|
||||
return func(ctx *Context) {
|
||||
ctx.Repo.RefFullName = git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch)
|
||||
ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
|
||||
ctx.Repo.Commit, _ = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName)
|
||||
ctx.Repo.Commit, _ = ctx.Repo.GitRepo.GetBranchCommit(ctx, ctx.Repo.BranchName)
|
||||
ctx.Repo.CommitsCount, _ = ctx.Repo.GetCommitsCount(ctx)
|
||||
ctx.Data["RefFullName"] = ctx.Repo.RefFullName
|
||||
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
||||
@@ -936,7 +940,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
if reqPath == "" {
|
||||
refShortName = ctx.Repo.Repository.DefaultBranch
|
||||
if !gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, refShortName) {
|
||||
brs, _, err := ctx.Repo.GitRepo.GetBranchNames(0, 1)
|
||||
brs, _, err := ctx.Repo.GitRepo.GetBranchNames(ctx, 0, 1)
|
||||
if err == nil && len(brs) != 0 {
|
||||
refShortName = brs[0]
|
||||
} else if len(brs) == 0 {
|
||||
@@ -947,7 +951,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
}
|
||||
ctx.Repo.RefFullName = git.RefNameFromBranch(refShortName)
|
||||
ctx.Repo.BranchName = refShortName
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refShortName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, refShortName)
|
||||
if err == nil {
|
||||
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
|
||||
} else {
|
||||
@@ -976,7 +980,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
ctx.Repo.BranchName = refShortName
|
||||
ctx.Repo.RefFullName = git.RefNameFromBranch(refShortName)
|
||||
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refShortName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx, refShortName)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetBranchCommit", err)
|
||||
return
|
||||
@@ -985,7 +989,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
} else if refType == git.RefTypeTag && gitrepo.IsTagExist(ctx, ctx.Repo.Repository, refShortName) {
|
||||
ctx.Repo.RefFullName = git.RefNameFromTag(refShortName)
|
||||
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refShortName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(ctx, refShortName)
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound(err)
|
||||
@@ -999,7 +1003,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
|
||||
ctx.Repo.RefFullName = git.RefNameFromCommit(refShortName)
|
||||
ctx.Repo.CommitID = refShortName
|
||||
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refShortName)
|
||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(ctx, refShortName)
|
||||
if err != nil {
|
||||
ctx.NotFound(err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user