diff options
author | zeripath <art27@cantab.net> | 2022-01-19 23:26:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-19 23:26:57 +0000 |
commit | 5cb0c9aa0d7eed087055b1efca79628957207d36 (patch) | |
tree | d117a514e1f17e5f6bfcda1be273f6a971112663 /modules/git/pipeline/revlist.go | |
parent | 4563148a61ba892e8f2bb66342f00a950bcd5315 (diff) | |
download | gitea-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/git/pipeline/revlist.go')
-rw-r--r-- | modules/git/pipeline/revlist.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/modules/git/pipeline/revlist.go b/modules/git/pipeline/revlist.go index 4e13e19444..373ceea1fb 100644 --- a/modules/git/pipeline/revlist.go +++ b/modules/git/pipeline/revlist.go @@ -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()) |