aboutsummaryrefslogtreecommitdiffstats
path: root/modules/indexer/code/bleve.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-01-19 23:26:57 +0000
committerGitHub <noreply@github.com>2022-01-19 23:26:57 +0000
commit5cb0c9aa0d7eed087055b1efca79628957207d36 (patch)
treed117a514e1f17e5f6bfcda1be273f6a971112663 /modules/indexer/code/bleve.go
parent4563148a61ba892e8f2bb66342f00a950bcd5315 (diff)
downloadgitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz
gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip
Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git commands run within the request context. This now means that the if there is a git repo already open in the context it will be used instead of reopening it. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/indexer/code/bleve.go')
-rw-r--r--modules/indexer/code/bleve.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/modules/indexer/code/bleve.go b/modules/indexer/code/bleve.go
index 3a44a8dc05..64e974dc18 100644
--- a/modules/indexer/code/bleve.go
+++ b/modules/indexer/code/bleve.go
@@ -6,6 +6,7 @@ package code
import (
"bufio"
+ "context"
"fmt"
"io"
"os"
@@ -180,7 +181,7 @@ func NewBleveIndexer(indexDir string) (*BleveIndexer, bool, error) {
return indexer, created, err
}
-func (b *BleveIndexer) addUpdate(batchWriter git.WriteCloserError, batchReader *bufio.Reader, commitSha string,
+func (b *BleveIndexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserError, batchReader *bufio.Reader, commitSha string,
update fileUpdate, repo *repo_model.Repository, batch *gitea_bleve.FlushingBatch) error {
// Ignore vendored files in code search
if setting.Indexer.ExcludeVendored && analyze.IsVendor(update.Filename) {
@@ -190,7 +191,7 @@ func (b *BleveIndexer) addUpdate(batchWriter git.WriteCloserError, batchReader *
size := update.Size
if !update.Sized {
- stdout, err := git.NewCommand("cat-file", "-s", update.BlobSha).
+ stdout, err := git.NewCommandContext(ctx, "cat-file", "-s", update.BlobSha).
RunInDir(repo.RepoPath())
if err != nil {
return err
@@ -271,21 +272,21 @@ func (b *BleveIndexer) Close() {
}
// Index indexes the data
-func (b *BleveIndexer) Index(repo *repo_model.Repository, sha string, changes *repoChanges) error {
+func (b *BleveIndexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *repoChanges) error {
batch := gitea_bleve.NewFlushingBatch(b.indexer, maxBatchSize)
if len(changes.Updates) > 0 {
// 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!
- if err := git.EnsureValidGitRepository(git.DefaultContext, repo.RepoPath()); err != nil {
+ if err := git.EnsureValidGitRepository(ctx, repo.RepoPath()); err != nil {
log.Error("Unable to open git repo: %s for %-v: %v", repo.RepoPath(), repo, err)
return err
}
- batchWriter, batchReader, cancel := git.CatFileBatch(git.DefaultContext, repo.RepoPath())
+ batchWriter, batchReader, cancel := git.CatFileBatch(ctx, repo.RepoPath())
defer cancel()
for _, update := range changes.Updates {
- if err := b.addUpdate(batchWriter, batchReader, sha, update, repo, batch); err != nil {
+ if err := b.addUpdate(ctx, batchWriter, batchReader, sha, update, repo, batch); err != nil {
return err
}
}