@@ -10,7 +10,6 @@ import (
1010 "context"
1111 "fmt"
1212 "math"
13- "os"
1413 "runtime"
1514 "strconv"
1615 "strings"
@@ -36,24 +35,21 @@ func EnsureValidGitRepository(ctx context.Context, repoPath string) error {
3635}
3736
3837func returnClosedReaderWriters (err error ) (WriteCloserError , * bufio.Reader , func ()) {
39- wr := & writeCloserError {}
40- rd := & readCloserError {}
41-
42- _ = wr .CloseWithError (err )
43- _ = rd .CloseWithError (err )
44-
45- return wr , bufio .NewReader (rd ), func () {}
38+ wr := & ClosedReadWriteCloserError {err }
39+ return wr , bufio .NewReader (wr ), func () {}
4640}
4741
4842// CatFileBatchCheck opens git cat-file --batch-check in the provided repo and returns a stdin pipe, a stdout reader and cancel function
4943func CatFileBatchCheck (ctx context.Context , repoPath string ) (WriteCloserError , * bufio.Reader , func ()) {
50- batchStdinReader , batchStdinWriter , err := os . Pipe ()
44+ batchStdinReader , batchStdinWriter , err := Pipe ()
5145 if err != nil {
5246 log .Critical ("Unable to open pipe to write to: %v" , err )
5347 return returnClosedReaderWriters (err )
5448 }
55- batchStdoutReader , batchStdoutWriter , err := os . Pipe ()
49+ batchStdoutReader , batchStdoutWriter , err := Pipe ()
5650 if err != nil {
51+ _ = batchStdinReader .Close ()
52+ _ = batchStdinWriter .Close ()
5753 log .Critical ("Unable to open pipe to write to: %v" , err )
5854 return returnClosedReaderWriters (err )
5955 }
@@ -69,9 +65,6 @@ func CatFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError,
6965 _ , filename , line , _ := runtime .Caller (2 )
7066 filename = strings .TrimPrefix (filename , callerPrefix )
7167
72- wr := newWriteCloserError (batchStdinWriter )
73- rd := newReadCloserError (batchStdoutReader )
74-
7568 go func () {
7669 stderr := strings.Builder {}
7770 err := NewCommand (ctx , "cat-file" , "--batch-check" ).
@@ -84,10 +77,8 @@ func CatFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError,
8477 })
8578 if err != nil {
8679 err := ConcatenateError (err , (& stderr ).String ())
87- _ = wr .CloseWithError (err )
88- _ = rd .CloseWithError (err )
89- _ = batchStdoutWriter .Close ()
90- _ = batchStdinReader .Close ()
80+ _ = batchStdinReader .CloseWithError (err )
81+ _ = batchStdoutWriter .CloseWithError (err )
9182 } else {
9283 _ = batchStdoutWriter .Close ()
9384 _ = batchStdinReader .Close ()
@@ -96,29 +87,27 @@ func CatFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError,
9687 }()
9788
9889 // For simplicities sake we'll use a buffered reader to read from the cat-file --batch-check
99- batchReader := bufio .NewReader (rd )
100-
101- return wr , batchReader , cancel
90+ batchReader := bufio .NewReader (batchStdoutReader )
91+ return batchStdinWriter , batchReader , cancel
10292}
10393
10494// CatFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function
10595func CatFileBatch (ctx context.Context , repoPath string ) (WriteCloserError , * bufio.Reader , func ()) {
10696 // We often want to feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary.
10797 // so let's create a batch stdin and stdout
108- batchStdinReader , batchStdinWriter , err := os . Pipe ()
98+ batchStdinReader , batchStdinWriter , err := Pipe ()
10999 if err != nil {
110100 log .Critical ("Unable to open pipe to write to: %v" , err )
111101 return returnClosedReaderWriters (err )
112102 }
113- batchStdoutReader , batchStdoutWriter , err := os . Pipe ()
103+ batchStdoutReader , batchStdoutWriter , err := Pipe ()
114104 if err != nil {
105+ _ = batchStdinReader .Close ()
106+ _ = batchStdinWriter .Close ()
115107 log .Critical ("Unable to open pipe to write to: %v" , err )
116108 return returnClosedReaderWriters (err )
117109 }
118110
119- wr := newWriteCloserError (batchStdinWriter )
120- rd := newReadCloserError (batchStdoutReader )
121-
122111 ctx , ctxCancel := context .WithCancel (ctx )
123112 closed := make (chan struct {})
124113 cancel := func () {
@@ -143,10 +132,8 @@ func CatFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufi
143132 })
144133 if err != nil {
145134 err := ConcatenateError (err , (& stderr ).String ())
146- _ = wr .CloseWithError (err )
147- _ = rd .CloseWithError (err )
148- _ = batchStdoutWriter .Close ()
149- _ = batchStdinReader .Close ()
135+ _ = batchStdinReader .CloseWithError (err )
136+ _ = batchStdoutWriter .CloseWithError (err )
150137 } else {
151138 _ = batchStdoutWriter .Close ()
152139 _ = batchStdinReader .Close ()
@@ -155,9 +142,9 @@ func CatFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufi
155142 }()
156143
157144 // For simplicities sake we'll us a buffered reader to read from the cat-file --batch
158- batchReader := bufio .NewReaderSize (rd , 32 * 1024 )
145+ batchReader := bufio .NewReaderSize (batchStdoutReader , 32 * 1024 )
159146
160- return wr , batchReader , cancel
147+ return batchStdinWriter , batchReader , cancel
161148}
162149
163150// ReadBatchLine reads the header line from cat-file --batch
0 commit comments