diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-15 16:25:35 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-15 16:25:35 -0500 |
commit | 7675ebe9567bd7cae4306f484e3677bf88ba8b55 (patch) | |
tree | abe46762eb9b9a07b0daae0268148c9d76e9fb13 /read_fastimport.go | |
parent | 3744c70711bce0ab92cc47d7fa9a58f7882cc1e5 (diff) |
rename files
Diffstat (limited to 'read_fastimport.go')
-rw-r--r-- | read_fastimport.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/read_fastimport.go b/read_fastimport.go new file mode 100644 index 0000000..ea10885 --- /dev/null +++ b/read_fastimport.go @@ -0,0 +1,59 @@ +package libfastimport + +type UnsupportedCommand string + +func (e UnsupportedCommand) Error() string { + return "Unsupported command: "+string(e) +} + +type Parser struct { + fir *FIReader + + cmd chan Cmd +} + +func (p *Parser) GetCmd() (Cmd, error) { + for p.cmd == nil { + slice, err := p.fir.ReadSlice() + if err != nil { + return nil, err + } + err = p.putSlice(slice) + if err != nil { + return nil, err + } + } + return <-p.cmd, nil +} + +func (p *Parser) putSlice(slice []byte) error { + if len(slice) < 1 { + return UnsupportedCommand(slice) + } + switch slice[0] { + case '#': // comment + case 'b': // blob + case 'c': + if len(slice) < 2 { + return UnsupportedCommand(slice) + } + switch slice[1] { + case 'o': // commit + case 'h': // checkpoint + case 'a': // cat-blob + default: + return UnsupportedCommand(slice) + } + case 'd': // done + case 'f': // feature + case 'g': // get-mark + case 'l': // ls + case 'o': // option + case 'p': // progress + case 'r': // reset + case 't': // tag + default: + return UnsupportedCommand(slice) + } + return nil // TODO +} |