diff options
Diffstat (limited to 'parse_fastimport.go')
-rw-r--r-- | parse_fastimport.go | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/parse_fastimport.go b/parse_fastimport.go index 7f84dfd..422f261 100644 --- a/parse_fastimport.go +++ b/parse_fastimport.go @@ -27,7 +27,7 @@ var parser_regularCmds = make(map[string]Cmd) var parser_commentCmds = make(map[string]Cmd) func parser_registerCmd(prefix string, cmd Cmd) { - if cmdIs(cmd, cmdClassInCommand) { + if cmdIs(noopReaderState{}, cmd, cmdClassInCommand) { parser_commentCmds[prefix] = cmd } else { parser_regularCmds[prefix] = cmd @@ -76,7 +76,8 @@ func parser_compile(cmds map[string]Cmd) func(line string) func(fiReader) (Cmd, type parser struct { fir *textproto.FIReader - inCommit bool + inCommit bool + commandMark int buf_line *string buf_err error @@ -130,15 +131,23 @@ func (p *parser) parse() error { return err } + // I've tried many times to rewrite this to be more + // readable. I have failed each time. switch { - case !cmdIs(cmd, cmdClassInCommit): - if p.inCommit { - p.ret_cmd <- CmdCommitEnd{} - } - _, p.inCommit = cmd.(CmdCommit) - case !p.inCommit && !cmdIs(cmd, cmdClassCommand): + case p.inCommit && !cmdIs(p, cmd, cmdClassInCommit): + p.ret_cmd <- CmdCommitEnd{} + p.inCommit = false + case !p.inCommit && !cmdIs(p, cmd, cmdClassCommand): return errors.Errorf("Got in-commit-only command outside of a commit: %[1]T(%#[1]v)", cmd) } + if _, newCommit := cmd.(CmdCommit); newCommit { + p.inCommit = true + // DO NOT reset p.commandMark; cmd.fiCmdRead + // already did that. + } + if !p.inCommit { + p.commandMark = 0 + } p.ret_cmd <- cmd } @@ -171,3 +180,11 @@ func (p *parser) ReadLine() (string, error) { p.buf_err = nil return line, err } + +func (p *parser) SetCommandMark(mark int) { + p.commandMark = mark +} + +func (p *parser) GetCommandMark() int { + return p.commandMark +} |