From c8665e658eeab995b26c57aaa95e1d5f08955155 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 17 Nov 2017 16:35:46 -0500 Subject: backend: only call onErr once --- backend.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 } -- cgit v1.2.3-54-g00ecf