Skip to content

Commit f67cd16

Browse files
committed
hide catfile functions in git module
1 parent ca988f3 commit f67cd16

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

modules/git/batch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ func (repo *Repository) NewBatch(ctx context.Context) *Batch {
1919
batch := Batch{
2020
repo: repo,
2121
}
22-
batch.Writer, batch.Reader, batch.cancel = CatFileBatch(ctx, repo.Path)
22+
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repo.Path)
2323
return &batch
2424
}
2525

2626
func (repo *Repository) NewBatchCheck(ctx context.Context) *Batch {
2727
check := Batch{
2828
repo: repo,
2929
}
30-
check.Writer, check.Reader, check.cancel = CatFileBatchCheck(ctx, repo.Path)
30+
check.Writer, check.Reader, check.cancel = catFileBatchCheck(ctx, repo.Path)
3131
return &check
3232
}
3333

modules/git/batch_reader.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func EnsureValidGitRepository(ctx context.Context, repoPath string) error {
4343
return nil
4444
}
4545

46-
// CatFileBatchCheck opens git cat-file --batch-check in the provided repo and returns a stdin pipe, a stdout reader and cancel function
47-
func CatFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) {
46+
// catFileBatchCheck opens git cat-file --batch-check in the provided repo and returns a stdin pipe, a stdout reader and cancel function
47+
func catFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) {
4848
batchStdinReader, batchStdinWriter := io.Pipe()
4949
batchStdoutReader, batchStdoutWriter := io.Pipe()
5050
ctx, ctxCancel := context.WithCancel(ctx)
@@ -93,8 +93,8 @@ func CatFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError,
9393
return batchStdinWriter, batchReader, cancel
9494
}
9595

96-
// CatFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function
97-
func CatFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) {
96+
// catFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function
97+
func catFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) {
9898
// We often want to feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary.
9999
// so let's create a batch stdin and stdout
100100
batchStdinReader, batchStdinWriter := io.Pipe()

modules/indexer/code/bleve/bleve.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
"code.gitea.io/gitea/modules/analyze"
1717
"code.gitea.io/gitea/modules/charset"
1818
"code.gitea.io/gitea/modules/git"
19+
"code.gitea.io/gitea/modules/gitrepo"
1920
"code.gitea.io/gitea/modules/indexer/code/internal"
2021
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
2122
inner_bleve "code.gitea.io/gitea/modules/indexer/internal/bleve"
22-
"code.gitea.io/gitea/modules/log"
2323
"code.gitea.io/gitea/modules/setting"
2424
"code.gitea.io/gitea/modules/timeutil"
2525
"code.gitea.io/gitea/modules/typesniffer"
@@ -189,21 +189,20 @@ func (b *Indexer) addDelete(filename string, repo *repo_model.Repository, batch
189189
func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *internal.RepoChanges) error {
190190
batch := inner_bleve.NewFlushingBatch(b.inner.Indexer, maxBatchSize)
191191
if len(changes.Updates) > 0 {
192-
// Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!
193-
if err := git.EnsureValidGitRepository(ctx, repo.RepoPath()); err != nil {
194-
log.Error("Unable to open git repo: %s for %-v: %v", repo.RepoPath(), repo, err)
192+
r, err := gitrepo.OpenRepository(ctx, repo)
193+
if err != nil {
195194
return err
196195
}
197-
198-
batchWriter, batchReader, cancel := git.CatFileBatch(ctx, repo.RepoPath())
199-
defer cancel()
196+
defer r.Close()
197+
gitBatch := r.NewBatch(ctx)
198+
defer gitBatch.Close()
200199

201200
for _, update := range changes.Updates {
202-
if err := b.addUpdate(ctx, batchWriter, batchReader, sha, update, repo, batch); err != nil {
201+
if err := b.addUpdate(ctx, gitBatch.Writer, gitBatch.Reader, sha, update, repo, batch); err != nil {
203202
return err
204203
}
205204
}
206-
cancel()
205+
gitBatch.Close()
207206
}
208207
for _, filename := range changes.RemovedFilenames {
209208
if err := b.addDelete(filename, repo, batch); err != nil {

0 commit comments

Comments
 (0)