summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-11-17 16:35:46 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-11-17 16:35:46 -0500
commitc8665e658eeab995b26c57aaa95e1d5f08955155 (patch)
treed99a7e5d2da7fd71202600c2588454013050a8cb
parentd9498148b860252c6f80eb6cd5acbd9fe07b2b8b (diff)
backend: only call onErr once
-rw-r--r--backend.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/backend.go b/backend.go
index b91ee88..ff40f5b 100644
--- a/backend.go
+++ b/backend.go
@@ -14,6 +14,7 @@ type Backend struct {
fiw *textproto.FIWriter
cbr *textproto.CatBlobReader
+ err error
onErr func(error) error
}
@@ -24,11 +25,21 @@ func NewBackend(fastImport io.Writer, catBlob io.Reader, onErr func(error) error
if catBlob != nil {
ret.cbr = textproto.NewCatBlobReader(catBlob)
}
- ret.onErr = onErr
+ ret.onErr = func(err error) error {
+ ret.err = err
+ if onErr != nil {
+ ret.err = onErr(ret.err)
+ }
+ return ret.err
+ }
return ret
}
func (b *Backend) Do(cmd Cmd) error {
+ if b.err == nil {
+ return b.err
+ }
+
err := cmd.fiWriteCmd(b.fiw)
if err != nil {
return b.onErr(err)
@@ -37,6 +48,7 @@ func (b *Backend) Do(cmd Cmd) error {
if err != nil {
return b.onErr(err)
}
+
return nil
}