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
+13 -17
View File
@@ -12,29 +12,21 @@ import (
"sync"
"gitea.dev/modules/log"
"gitea.dev/modules/setting"
"gitea.dev/modules/util"
)
const isGogit = false
// Repository represents a Git repository.
type Repository struct {
Path string
tagCache *ObjectCache[*Tag]
RepositoryBase
mu sync.Mutex
catFileBatchCloser CatFileBatchCloser
catFileBatchInUse bool
Ctx context.Context
LastCommitCache *LastCommitCache
objectFormat ObjectFormat
}
// OpenRepository opens the repository at the given path with the provided context.
func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
func OpenRepository(repoPath string) (*Repository, error) {
repoPath, err := filepath.Abs(repoPath)
if err != nil {
return nil, err
@@ -46,12 +38,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
if !exist {
return nil, util.NewNotExistErrorf("no such file or directory")
}
return &Repository{
Path: repoPath,
tagCache: newObjectCache[*Tag](),
Ctx: ctx,
}, nil
return &Repository{RepositoryBase: prepareRepositoryBase(repoPath)}, nil
}
// CatFileBatch obtains a "batch object provider" for this repository.
@@ -60,6 +47,14 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, close
repo.mu.Lock()
defer repo.mu.Unlock()
if repo.catFileBatchCloser != nil && !repo.catFileBatchInUse {
if ctx != repo.catFileBatchCloser.Context() {
repo.catFileBatchCloser.Close()
repo.catFileBatchCloser = nil
repo.catFileBatchInUse = false
}
}
if repo.catFileBatchCloser == nil {
repo.catFileBatchCloser, err = NewBatch(ctx, repo.Path)
if err != nil {
@@ -87,6 +82,7 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, close
func (repo *Repository) Close() error {
if repo == nil {
setting.PanicInDevOrTesting("don't close a nil repository")
return nil
}
repo.mu.Lock()