blob: abafa4bbb58e70c26554bef3078fea816ab123b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package libfastimport
import (
"git.lukeshu.com/go/libfastimport/textproto"
)
type UnsupportedCommand string
func (e UnsupportedCommand) Error() string {
return "Unsupported command: "+string(e)
}
type Parser struct {
fir *textproto.FIReader
cmd chan Cmd
}
func (p *Parser) GetCmd() (Cmd, error) {
for p.cmd == nil {
line, err := p.fir.ReadLine()
if err != nil {
return nil, err
}
err = p.putLine(line)
if err != nil {
return nil, err
}
}
return <-p.cmd, nil
}
func (p *Parser) putLine(line string) error {
if len(line) < 1 {
return UnsupportedCommand(line)
}
switch line[0] {
case '#': // comment
case 'b': // blob
case 'c':
if len(line) < 2 {
return UnsupportedCommand(line)
}
switch line[1] {
case 'o': // commit
case 'h': // checkpoint
case 'a': // cat-blob
default:
return UnsupportedCommand(line)
}
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(line)
}
return nil // TODO
}
|