@@ -27,23 +27,23 @@ type catFileBatchCommunicator struct {
2727}
2828
2929func (b * catFileBatchCommunicator ) Close (err ... error ) {
30- if fn := b .closeFunc .Load ( ); fn != nil {
30+ if fn := b .closeFunc .Swap ( nil ); fn != nil {
3131 (* fn )(util .OptionalArg (err ))
32- b .closeFunc .Store (nil )
3332 }
3433}
3534
3635func (b * catFileBatchCommunicator ) debugKill () (ret struct {
3736 beforeClose chan struct {}
3837 blockClose chan struct {}
3938 afterClose chan struct {}
40- }) {
39+ },
40+ ) {
4141 ret .beforeClose = make (chan struct {})
4242 ret .blockClose = make (chan struct {})
4343 ret .afterClose = make (chan struct {})
4444 oldCloseFunc := b .closeFunc .Load ()
4545 b .closeFunc .Store (new (func (err error ) {
46- b.closeFunc .Store (oldCloseFunc )
46+ b.closeFunc .Store (nil )
4747 close (ret .beforeClose )
4848 < - ret .blockClose
4949 (* oldCloseFunc )(err )
@@ -53,28 +53,19 @@ func (b *catFileBatchCommunicator) debugKill() (ret struct {
5353 return ret
5454}
5555
56- // newCatFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function
57- func newCatFileBatch (ctx context.Context , repoPath string , cmdCatFile * gitcmd.Command ) ( ret * catFileBatchCommunicator ) {
56+ // newCatFileBatch opens git cat-file --batch/--batch-check/--batch-command command and prepares the stdin/ stdout pipes for communication.
57+ func newCatFileBatch (ctx context.Context , repoPath string , cmdCatFile * gitcmd.Command ) * catFileBatchCommunicator {
5858 ctx , ctxCancel := context .WithCancelCause (ctx )
59-
60- // We often want to feed the commits in order into cat-file --batch, followed by their trees and subtrees as necessary.
6159 stdinWriter , stdoutReader , stdPipeClose := cmdCatFile .MakeStdinStdoutPipe ()
62- closeFunc := func (err error ) {
63- ctxCancel (err )
64- stdPipeClose ()
65- }
66- return newCatFileBatchWithCloseFunc (ctx , repoPath , cmdCatFile , stdinWriter , stdoutReader , closeFunc )
67- }
68-
69- func newCatFileBatchWithCloseFunc (ctx context.Context , repoPath string , cmdCatFile * gitcmd.Command ,
70- stdinWriter gitcmd.PipeWriter , stdoutReader gitcmd.PipeReader , closeFunc func (err error ),
71- ) * catFileBatchCommunicator {
7260 ret := & catFileBatchCommunicator {
7361 debugGitCmd : cmdCatFile ,
7462 reqWriter : stdinWriter ,
7563 respReader : bufio .NewReaderSize (stdoutReader , 32 * 1024 ), // use a buffered reader for rich operations
7664 }
77- ret .closeFunc .Store (& closeFunc )
65+ ret .closeFunc .Store (new (func (err error ) {
66+ ctxCancel (err )
67+ stdPipeClose ()
68+ }))
7869
7970 err := cmdCatFile .WithDir (repoPath ).StartWithStderr (ctx )
8071 if err != nil {
0 commit comments