@@ -7,6 +7,7 @@ package git
77import (
88 "bufio"
99 "bytes"
10+ "context"
1011 "io"
1112 "math"
1213 "strconv"
@@ -28,23 +29,28 @@ type WriteCloserError interface {
2829func CatFileBatchCheck (repoPath string ) (WriteCloserError , * bufio.Reader , func ()) {
2930 batchStdinReader , batchStdinWriter := io .Pipe ()
3031 batchStdoutReader , batchStdoutWriter := io .Pipe ()
32+ ctx , ctxCancel := context .WithCancel (DefaultContext )
33+ closed := make (chan struct {})
3134 cancel := func () {
3235 _ = batchStdinReader .Close ()
3336 _ = batchStdinWriter .Close ()
3437 _ = batchStdoutReader .Close ()
3538 _ = batchStdoutWriter .Close ()
39+ ctxCancel ()
40+ <- closed
3641 }
3742
3843 go func () {
3944 stderr := strings.Builder {}
40- err := NewCommand ( "cat-file" , "--batch-check" ).RunInDirFullPipeline (repoPath , batchStdoutWriter , & stderr , batchStdinReader )
45+ err := NewCommandContext ( ctx , "cat-file" , "--batch-check" ).RunInDirFullPipeline (repoPath , batchStdoutWriter , & stderr , batchStdinReader )
4146 if err != nil {
4247 _ = batchStdoutWriter .CloseWithError (ConcatenateError (err , (& stderr ).String ()))
4348 _ = batchStdinReader .CloseWithError (ConcatenateError (err , (& stderr ).String ()))
4449 } else {
4550 _ = batchStdoutWriter .Close ()
4651 _ = batchStdinReader .Close ()
4752 }
53+ close (closed )
4854 }()
4955
5056 // For simplicities sake we'll use a buffered reader to read from the cat-file --batch-check
@@ -59,23 +65,28 @@ func CatFileBatch(repoPath string) (WriteCloserError, *bufio.Reader, func()) {
5965 // so let's create a batch stdin and stdout
6066 batchStdinReader , batchStdinWriter := io .Pipe ()
6167 batchStdoutReader , batchStdoutWriter := nio .Pipe (buffer .New (32 * 1024 ))
68+ ctx , ctxCancel := context .WithCancel (DefaultContext )
69+ closed := make (chan struct {})
6270 cancel := func () {
6371 _ = batchStdinReader .Close ()
6472 _ = batchStdinWriter .Close ()
6573 _ = batchStdoutReader .Close ()
6674 _ = batchStdoutWriter .Close ()
75+ ctxCancel ()
76+ <- closed
6777 }
6878
6979 go func () {
7080 stderr := strings.Builder {}
71- err := NewCommand ( "cat-file" , "--batch" ).RunInDirFullPipeline (repoPath , batchStdoutWriter , & stderr , batchStdinReader )
81+ err := NewCommandContext ( ctx , "cat-file" , "--batch" ).RunInDirFullPipeline (repoPath , batchStdoutWriter , & stderr , batchStdinReader )
7282 if err != nil {
7383 _ = batchStdoutWriter .CloseWithError (ConcatenateError (err , (& stderr ).String ()))
7484 _ = batchStdinReader .CloseWithError (ConcatenateError (err , (& stderr ).String ()))
7585 } else {
7686 _ = batchStdoutWriter .Close ()
7787 _ = batchStdinReader .Close ()
7888 }
89+ close (closed )
7990 }()
8091
8192 // For simplicities sake we'll us a buffered reader to read from the cat-file --batch
0 commit comments