refactor: remove Ctx field from git.Repository (#38500)

This commit is contained in:
wxiaoguang
2026-07-17 18:44:31 +08:00
committed by GitHub
parent 2c8e99bbf7
commit 5b078f72aa
235 changed files with 1234 additions and 1258 deletions
+5 -8
View File
@@ -18,10 +18,7 @@ import (
"gitea.dev/modules/util"
)
// Repository represents a git repository which stored in a disk
type Repository interface {
RelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
}
type Repository = git.RepositoryFacade
// repoPath resolves the Repository.RelativePath (which is a unix-style path like "username/reponame.git")
// to a local filesystem path according to setting.RepoRootPath
@@ -30,8 +27,8 @@ var repoPath = func(repo Repository) string {
}
// OpenRepository opens the repository at the given relative path with the provided context.
func OpenRepository(ctx context.Context, repo Repository) (*git.Repository, error) {
return git.OpenRepository(ctx, repoPath(repo))
func OpenRepository(repo Repository) (*git.Repository, error) {
return git.OpenRepository(repoPath(repo))
}
// contextKey is a value for use with context.WithValue.
@@ -47,7 +44,7 @@ func RepositoryFromContextOrOpen(ctx context.Context, repo Repository) (*git.Rep
gitRepo, err := RepositoryFromRequestContextOrOpen(reqCtx, repo)
return gitRepo, util.NopCloser{}, err
}
gitRepo, err := OpenRepository(ctx, repo)
gitRepo, err := OpenRepository(repo)
return gitRepo, gitRepo, err
}
@@ -58,7 +55,7 @@ func RepositoryFromRequestContextOrOpen(ctx reqctx.RequestContext, repo Reposito
if gitRepo, ok := ctx.Value(ck).(*git.Repository); ok {
return gitRepo, nil
}
gitRepo, err := git.OpenRepository(ctx, ck.repoPath)
gitRepo, err := git.OpenRepository(ck.repoPath)
if err != nil {
return nil, err
}