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

@ -7,6 +7,7 @@ package pipeline
import (
"bufio"
"bytes"
"context"
"fmt"
"io"
"strings"
@ -17,13 +18,13 @@ import (
)
// RevListAllObjects runs rev-list --objects --all and writes to a pipewriter
func RevListAllObjects(revListWriter *io.PipeWriter, wg *sync.WaitGroup, basePath string, errChan chan<- error) {
func RevListAllObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sync.WaitGroup, basePath string, errChan chan<- error) {
defer wg.Done()
defer revListWriter.Close()
stderr := new(bytes.Buffer)
var errbuf strings.Builder
cmd := git.NewCommand("rev-list", "--objects", "--all")
cmd := git.NewCommandContext(ctx, "rev-list", "--objects", "--all")
if err := cmd.RunInDirPipeline(basePath, revListWriter, stderr); err != nil {
log.Error("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String())
err = fmt.Errorf("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String())
@ -33,12 +34,12 @@ func RevListAllObjects(revListWriter *io.PipeWriter, wg *sync.WaitGroup, basePat
}
// RevListObjects run rev-list --objects from headSHA to baseSHA
func RevListObjects(revListWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath, headSHA, baseSHA string, errChan chan<- error) {
func RevListObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath, headSHA, baseSHA string, errChan chan<- error) {
defer wg.Done()
defer revListWriter.Close()
stderr := new(bytes.Buffer)
var errbuf strings.Builder
cmd := git.NewCommand("rev-list", "--objects", headSHA, "--not", baseSHA)
cmd := git.NewCommandContext(ctx, "rev-list", "--objects", headSHA, "--not", baseSHA)
if err := cmd.RunInDirPipeline(tmpBasePath, revListWriter, stderr); err != nil {
log.Error("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())
errChan <- fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())