summaryrefslogtreecommitdiff
path: root/backend.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-11-22 14:47:56 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-11-22 14:47:56 -0500
commitf13250e6a926640c4d0ee858f84fcf8036d612aa (patch)
treed50dceaca4c048f7efde241d1af85afccfe406b5 /backend.go
parentdb24f3cbd10603f852032a95b5983335b6b5aff2 (diff)
ahhh
Diffstat (limited to 'backend.go')
-rw-r--r--backend.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/backend.go b/backend.go
index fc67d82..72242a1 100644
--- a/backend.go
+++ b/backend.go
@@ -2,6 +2,7 @@ package libfastimport
import (
"bufio"
+ "fmt"
"io"
"git.lukeshu.com/go/libfastimport/textproto"
@@ -15,6 +16,8 @@ type Backend struct {
fiw *textproto.FIWriter
cbr *textproto.CatBlobReader
+ inCommit bool
+
err error
onErr func(error) error
}
@@ -45,12 +48,27 @@ func NewBackend(fastImport io.WriteCloser, catBlob io.Reader, onErr func(error)
return ret
}
+// will panic if Cmd is a type that may only be used in a commit but
+// we aren't in a commit.
func (b *Backend) Do(cmd Cmd) error {
if b.err == nil {
return b.err
}
- err := cmd.fiWriteCmd(b.fiw)
+ switch cmd.fiCmdClass() {
+ case cmdClassCommand:
+ _, b.inCommit = cmd.(CmdCommit)
+ case cmdClassCommit:
+ if !b.inCommit {
+ panic(fmt.Errorf("Cannot issue commit sub-command outside of a commit: %[1]T(%#[1]v)", cmd))
+ }
+ case cmdClassComment:
+ /* do nothing */
+ default:
+ panic(fmt.Errorf("invalid cmdClass: %d", cmd.fiCmdClass()))
+ }
+
+ err := cmd.fiCmdWrite(b.fiw)
if err != nil {
return b.onErr(err)
}
@@ -59,7 +77,7 @@ func (b *Backend) Do(cmd Cmd) error {
return b.onErr(err)
}
- if _, ok := cmd.(CmdDone); ok {
+ if _, isDone := cmd.(CmdDone); isDone {
return b.onErr(nil)
}