Store commit.Action as an enum instead of a string

The main reason for doing this (besides the reasons given for Status in the
previous commit) is that it allows us to easily convert from TodoCommand to
Action and back. This will be needed later in the branch. Fortunately,
TodoCommand is one-based, so this allows us to add an ActionNone constant with
the value 0.
This commit is contained in:
Stefan Haller 2023-04-03 12:42:29 +02:00
parent 188773511e
commit c53c5e47ef
7 changed files with 57 additions and 45 deletions

View file

@ -3,6 +3,7 @@ package models
import (
"fmt"
"github.com/fsmiamoto/git-todo-parser/todo"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -21,12 +22,18 @@ const (
StatusReflog
)
const (
// Conveniently for us, the todo package starts the enum at 1, and given
// that it doesn't have a "none" value, we're setting ours to 0
ActionNone todo.TodoCommand = 0
)
// Commit : A git commit
type Commit struct {
Sha string
Name string
Status CommitStatus
Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
Action todo.TodoCommand
Tags []string
ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2'
AuthorName string // something like 'Jesse Duffield'
@ -75,7 +82,7 @@ func (c *Commit) IsMerge() bool {
// returns true if this commit is not actually in the git log but instead
// is from a TODO file for an interactive rebase.
func (c *Commit) IsTODO() bool {
return c.Action != ""
return c.Action != ActionNone
}
func IsHeadCommit(commits []*Commit, index int) bool {