diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2021-02-01 15:55:03 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2021-02-01 17:23:29 -0700 |
commit | 01ed9a06b20d32b148446d715d6e1beb3050d069 (patch) | |
tree | 8b0ef328859804e7b6bafb8f1495817fc31bb756 /parse_fastimport.go | |
parent | 328f9cc1ac0ebee9499dc8d50bd84f71897d4df7 (diff) |
Tidy up cmdClass
Diffstat (limited to 'parse_fastimport.go')
-rw-r--r-- | parse_fastimport.go | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/parse_fastimport.go b/parse_fastimport.go index 491788b..7f84dfd 100644 --- a/parse_fastimport.go +++ b/parse_fastimport.go @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2018, 2020 Luke Shumaker <lukeshu@lukeshu.com> +// Copyright (C) 2017-2018, 2020-2021 Luke Shumaker <lukeshu@lukeshu.com> // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -27,13 +27,10 @@ var parser_regularCmds = make(map[string]Cmd) var parser_commentCmds = make(map[string]Cmd) func parser_registerCmd(prefix string, cmd Cmd) { - switch cmd.fiCmdClass() { - case cmdClassCommand, cmdClassCommit: - parser_regularCmds[prefix] = cmd - case cmdClassComment: + if cmdIs(cmd, cmdClassInCommand) { parser_commentCmds[prefix] = cmd - default: - panic(errors.Errorf("invalid cmdClass: %d", cmd.fiCmdClass())) + } else { + parser_regularCmds[prefix] = cmd } } @@ -133,20 +130,14 @@ func (p *parser) parse() error { return err } - switch cmd.fiCmdClass() { - case cmdClassCommand: + switch { + case !cmdIs(cmd, cmdClassInCommit): if p.inCommit { p.ret_cmd <- CmdCommitEnd{} } _, p.inCommit = cmd.(CmdCommit) - case cmdClassCommit: - if !p.inCommit { - return errors.Errorf("Got in-commit-only command outside of a commit: %[1]T(%#[1]v)", cmd) - } - case cmdClassComment: - /* do nothing */ - default: - panic(errors.Errorf("invalid cmdClass: %d", cmd.fiCmdClass())) + case !p.inCommit && !cmdIs(cmd, cmdClassCommand): + return errors.Errorf("Got in-commit-only command outside of a commit: %[1]T(%#[1]v)", cmd) } p.ret_cmd <- cmd |