From 3afd91a3f1640b18be817b028b394d244a9cd909 Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Wed, 16 Nov 2016 11:39:08 -0700 Subject: [PATCH] need to check for --batch-check errors before closing stdin --- lfs/gitscanner_catfilebatch.go | 14 ++++++++++---- lfs/scanner.go | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lfs/gitscanner_catfilebatch.go b/lfs/gitscanner_catfilebatch.go index 52451158..6e235c67 100644 --- a/lfs/gitscanner_catfilebatch.go +++ b/lfs/gitscanner_catfilebatch.go @@ -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() } diff --git a/lfs/scanner.go b/lfs/scanner.go index 62295fd8..e5e135f7 100644 --- a/lfs/scanner.go +++ b/lfs/scanner.go @@ -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 }