diff options
Diffstat (limited to 'modules/git/batch_reader.go')
-rw-r--r-- | modules/git/batch_reader.go | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/modules/git/batch_reader.go b/modules/git/batch_reader.go index 8e3c23251b..71045adbc9 100644 --- a/modules/git/batch_reader.go +++ b/modules/git/batch_reader.go @@ -28,17 +28,15 @@ type WriteCloserError interface { } // CatFileBatchCheck opens git cat-file --batch-check in the provided repo and returns a stdin pipe, a stdout reader and cancel function -func CatFileBatchCheck(repoPath string) (WriteCloserError, *bufio.Reader, func()) { +func CatFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) { batchStdinReader, batchStdinWriter := io.Pipe() batchStdoutReader, batchStdoutWriter := io.Pipe() - ctx, ctxCancel := context.WithCancel(DefaultContext) + ctx, ctxCancel := context.WithCancel(ctx) closed := make(chan struct{}) cancel := func() { - _ = batchStdinReader.Close() - _ = batchStdinWriter.Close() - _ = batchStdoutReader.Close() - _ = batchStdoutWriter.Close() ctxCancel() + _ = batchStdoutReader.Close() + _ = batchStdinWriter.Close() <-closed } @@ -67,19 +65,17 @@ func CatFileBatchCheck(repoPath string) (WriteCloserError, *bufio.Reader, func() } // CatFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function -func CatFileBatch(repoPath string) (WriteCloserError, *bufio.Reader, func()) { +func CatFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) { // We often want to feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary. // so let's create a batch stdin and stdout batchStdinReader, batchStdinWriter := io.Pipe() batchStdoutReader, batchStdoutWriter := nio.Pipe(buffer.New(32 * 1024)) - ctx, ctxCancel := context.WithCancel(DefaultContext) + ctx, ctxCancel := context.WithCancel(ctx) closed := make(chan struct{}) cancel := func() { - _ = batchStdinReader.Close() + ctxCancel() _ = batchStdinWriter.Close() _ = batchStdoutReader.Close() - _ = batchStdoutWriter.Close() - ctxCancel() <-closed } |