Move catfile batch to a sub package of git module (#36232)

This commit is contained in:
Lunny Xiao
2025-12-29 10:19:42 -08:00
committed by GitHub
parent d0cb198c89
commit 0ad94dfc70
17 changed files with 500 additions and 412 deletions
+17 -17
View File
@@ -7,10 +7,10 @@
package git
import (
"bufio"
"context"
"path/filepath"
"code.gitea.io/gitea/modules/git/catfile"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
)
@@ -24,10 +24,10 @@ type Repository struct {
tagCache *ObjectCache[*Tag]
batchInUse bool
batch *Batch
batch catfile.Batch
checkInUse bool
check *Batch
check catfile.Batch
Ctx context.Context
LastCommitCache *LastCommitCache
@@ -57,53 +57,53 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
}
// CatFileBatch obtains a CatFileBatch for this repository
func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) {
func (repo *Repository) CatFileBatch(ctx context.Context) (catfile.Batch, func(), error) {
if repo.batch == nil {
var err error
repo.batch, err = NewBatch(ctx, repo.Path)
repo.batch, err = catfile.NewBatch(ctx, repo.Path)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
}
if !repo.batchInUse {
repo.batchInUse = true
return repo.batch.Writer, repo.batch.Reader, func() {
return repo.batch, func() {
repo.batchInUse = false
}, nil
}
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
tempBatch, err := NewBatch(ctx, repo.Path)
tempBatch, err := catfile.NewBatch(ctx, repo.Path)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
return tempBatch.Writer, tempBatch.Reader, tempBatch.Close, nil
return tempBatch, tempBatch.Close, nil
}
// CatFileBatchCheck obtains a CatFileBatchCheck for this repository
func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) {
func (repo *Repository) CatFileBatchCheck(ctx context.Context) (catfile.Batch, func(), error) {
if repo.check == nil {
var err error
repo.check, err = NewBatchCheck(ctx, repo.Path)
repo.check, err = catfile.NewBatchCheck(ctx, repo.Path)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
}
if !repo.checkInUse {
repo.checkInUse = true
return repo.check.Writer, repo.check.Reader, func() {
return repo.check, func() {
repo.checkInUse = false
}, nil
}
log.Debug("Opening temporary cat file batch-check for: %s", repo.Path)
tempBatchCheck, err := NewBatchCheck(ctx, repo.Path)
tempBatchCheck, err := catfile.NewBatchCheck(ctx, repo.Path)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
return tempBatchCheck.Writer, tempBatchCheck.Reader, tempBatchCheck.Close, nil
return tempBatchCheck, tempBatchCheck.Close, nil
}
func (repo *Repository) Close() error {