mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-19 05:13:57 +00:00
refactor: remove Ctx field from git.Repository (#38500)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user