need to check for --batch-check errors before closing stdin

This commit is contained in:
risk danger olson 2016-11-16 11:39:08 -07:00
parent 5f7075cac1
commit 3afd91a3f1
2 changed files with 11 additions and 5 deletions

@ -17,14 +17,14 @@ import (
// Results are parsed from STDOUT, and any elegible LFS pointers are sent to
// pointerCh. Any errors are sent to errCh. An error is returned if the 'git
// cat-file' command fails to start.
func runCatFileBatch(pointerCh chan *WrappedPointer, sha1Ch <-chan string, errCh chan error) error {
func runCatFileBatch(pointerCh chan *WrappedPointer, revs *StringChannelWrapper, errCh chan error) error {
cmd, err := startCommand("git", "cat-file", "--batch")
if err != nil {
return err
}
go catFileBatchOutput(pointerCh, cmd, errCh)
go catFileBatchInput(cmd, sha1Ch, errCh)
go catFileBatchInput(cmd, revs, errCh)
return nil
}
@ -48,10 +48,16 @@ func catFileBatchOutput(pointerCh chan *WrappedPointer, cmd *wrappedCmd, errCh c
close(errCh)
}
func catFileBatchInput(cmd *wrappedCmd, sha1Ch <-chan string, errCh chan error) {
for r := range sha1Ch {
func catFileBatchInput(cmd *wrappedCmd, revs *StringChannelWrapper, errCh chan error) {
for r := range revs.Results {
cmd.Stdin.Write([]byte(r + "\n"))
}
err := revs.Wait()
if err != nil {
// We can share errchan with other goroutine since that won't close it
// until we close the stdin below
errCh <- err
}
cmd.Stdin.Close()
}

@ -568,7 +568,7 @@ func catFileBatchCheck(revs *StringChannelWrapper) (*StringChannelWrapper, error
func catFileBatch(revs *StringChannelWrapper) (*PointerChannelWrapper, error) {
pointers := make(chan *WrappedPointer, chanBufSize)
errchan := make(chan error, 5) // shared by 2 goroutines & may add more detail errors?
if err := runCatFileBatch(pointers, revs.Results, errchan); err != nil {
if err := runCatFileBatch(pointers, revs, errchan); err != nil {
return nil, err
}