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>
This commit is contained in:
zeripath 2022-01-19 23:26:57 +00:00 committed by GitHub
parent 4563148a61
commit 5cb0c9aa0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
193 changed files with 1264 additions and 1154 deletions

View file

@ -42,7 +42,7 @@ type SearchResultLanguages struct {
// Indexer defines an interface to index and search code contents
type Indexer interface {
Index(repo *repo_model.Repository, sha string, changes *repoChanges) error
Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *repoChanges) error
Delete(repoID int64) error
Search(repoIDs []int64, language, keyword string, page, pageSize int, isMatch bool) (int64, []*SearchResult, []*SearchResultLanguages, error)
Close()
@ -82,7 +82,7 @@ var (
indexerQueue queue.UniqueQueue
)
func index(indexer Indexer, repoID int64) error {
func index(ctx context.Context, indexer Indexer, repoID int64) error {
repo, err := repo_model.GetRepositoryByID(repoID)
if repo_model.IsErrRepoNotExist(err) {
return indexer.Delete(repoID)
@ -91,18 +91,18 @@ func index(indexer Indexer, repoID int64) error {
return err
}
sha, err := getDefaultBranchSha(repo)
sha, err := getDefaultBranchSha(ctx, repo)
if err != nil {
return err
}
changes, err := getRepoChanges(repo, sha)
changes, err := getRepoChanges(ctx, repo, sha)
if err != nil {
return err
} else if changes == nil {
return nil
}
if err := indexer.Index(repo, sha, changes); err != nil {
if err := indexer.Index(ctx, repo, sha, changes); err != nil {
return err
}
@ -150,7 +150,7 @@ func Init() {
}
log.Trace("IndexerData Process Repo: %d", indexerData.RepoID)
if err := index(indexer, indexerData.RepoID); err != nil {
if err := index(ctx, indexer, indexerData.RepoID); err != nil {
log.Error("index: %v", err)
continue
}