From 01ed9a06b20d32b148446d715d6e1beb3050d069 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 1 Feb 2021 15:55:03 -0700 Subject: Tidy up cmdClass --- parse_fastimport.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'parse_fastimport.go') 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 +// Copyright (C) 2017-2018, 2020-2021 Luke Shumaker // // 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 -- cgit v1.2.3