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