1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

move commits model into models package

This commit is contained in:
Jesse Duffield
2020-09-29 18:36:54 +10:00
parent 44248d9ab0
commit 630e446989
14 changed files with 79 additions and 77 deletions

View File

@ -24,11 +24,11 @@ import (
type BranchListBuilder struct { type BranchListBuilder struct {
Log *logrus.Entry Log *logrus.Entry
GitCommand *GitCommand GitCommand *GitCommand
ReflogCommits []*Commit ReflogCommits []*models.Commit
} }
// NewBranchListBuilder builds a new branch list builder // NewBranchListBuilder builds a new branch list builder
func NewBranchListBuilder(log *logrus.Entry, gitCommand *GitCommand, reflogCommits []*Commit) (*BranchListBuilder, error) { func NewBranchListBuilder(log *logrus.Entry, gitCommand *GitCommand, reflogCommits []*models.Commit) (*BranchListBuilder, error) {
return &BranchListBuilder{ return &BranchListBuilder{
Log: log, Log: log,
GitCommand: gitCommand, GitCommand: gitCommand,

View File

@ -12,6 +12,7 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/models"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -48,7 +49,7 @@ func NewCommitListBuilder(log *logrus.Entry, gitCommand *GitCommand, osCommand *
// then puts them into a commit object // then puts them into a commit object
// example input: // example input:
// 8ad01fe32fcc20f07bc6693f87aa4977c327f1e1|10 hours ago|Jesse Duffield| (HEAD -> master, tag: v0.15.2)|refresh commits when adding a tag // 8ad01fe32fcc20f07bc6693f87aa4977c327f1e1|10 hours ago|Jesse Duffield| (HEAD -> master, tag: v0.15.2)|refresh commits when adding a tag
func (c *CommitListBuilder) extractCommitFromLine(line string) *Commit { func (c *CommitListBuilder) extractCommitFromLine(line string) *models.Commit {
split := strings.Split(line, SEPARATION_CHAR) split := strings.Split(line, SEPARATION_CHAR)
sha := split[0] sha := split[0]
@ -74,7 +75,7 @@ func (c *CommitListBuilder) extractCommitFromLine(line string) *Commit {
// If there's a space then it means there must be more than one parent hash // If there's a space then it means there must be more than one parent hash
isMerge := strings.Contains(parentHashes, " ") isMerge := strings.Contains(parentHashes, " ")
return &Commit{ return &models.Commit{
Sha: sha, Sha: sha,
Name: message, Name: message,
Tags: tags, Tags: tags,
@ -92,9 +93,9 @@ type GetCommitsOptions struct {
RefName string // e.g. "HEAD" or "my_branch" RefName string // e.g. "HEAD" or "my_branch"
} }
func (c *CommitListBuilder) MergeRebasingCommits(commits []*Commit) ([]*Commit, error) { func (c *CommitListBuilder) MergeRebasingCommits(commits []*models.Commit) ([]*models.Commit, error) {
// chances are we have as many commits as last time so we'll set the capacity to be the old length // chances are we have as many commits as last time so we'll set the capacity to be the old length
result := make([]*Commit, 0, len(commits)) result := make([]*models.Commit, 0, len(commits))
for i, commit := range commits { for i, commit := range commits {
if commit.Status != "rebasing" { // removing the existing rebase commits so we can add the refreshed ones if commit.Status != "rebasing" { // removing the existing rebase commits so we can add the refreshed ones
result = append(result, commits[i:]...) result = append(result, commits[i:]...)
@ -124,9 +125,9 @@ func (c *CommitListBuilder) MergeRebasingCommits(commits []*Commit) ([]*Commit,
} }
// GetCommits obtains the commits of the current branch // GetCommits obtains the commits of the current branch
func (c *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*Commit, error) { func (c *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*models.Commit, error) {
commits := []*Commit{} commits := []*models.Commit{}
var rebasingCommits []*Commit var rebasingCommits []*models.Commit
rebaseMode, err := c.GitCommand.RebaseMode() rebaseMode, err := c.GitCommand.RebaseMode()
if err != nil { if err != nil {
return nil, err return nil, err
@ -181,7 +182,7 @@ func (c *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*Commit, error
} }
// getRebasingCommits obtains the commits that we're in the process of rebasing // getRebasingCommits obtains the commits that we're in the process of rebasing
func (c *CommitListBuilder) getRebasingCommits(rebaseMode string) ([]*Commit, error) { func (c *CommitListBuilder) getRebasingCommits(rebaseMode string) ([]*models.Commit, error) {
switch rebaseMode { switch rebaseMode {
case "normal": case "normal":
return c.getNormalRebasingCommits() return c.getNormalRebasingCommits()
@ -192,7 +193,7 @@ func (c *CommitListBuilder) getRebasingCommits(rebaseMode string) ([]*Commit, er
} }
} }
func (c *CommitListBuilder) getNormalRebasingCommits() ([]*Commit, error) { func (c *CommitListBuilder) getNormalRebasingCommits() ([]*models.Commit, error) {
rewrittenCount := 0 rewrittenCount := 0
bytesContent, err := ioutil.ReadFile(filepath.Join(c.GitCommand.DotGitDir, "rebase-apply/rewritten")) bytesContent, err := ioutil.ReadFile(filepath.Join(c.GitCommand.DotGitDir, "rebase-apply/rewritten"))
if err == nil { if err == nil {
@ -201,7 +202,7 @@ func (c *CommitListBuilder) getNormalRebasingCommits() ([]*Commit, error) {
} }
// we know we're rebasing, so lets get all the files whose names have numbers // we know we're rebasing, so lets get all the files whose names have numbers
commits := []*Commit{} commits := []*models.Commit{}
err = filepath.Walk(filepath.Join(c.GitCommand.DotGitDir, "rebase-apply"), func(path string, f os.FileInfo, err error) error { err = filepath.Walk(filepath.Join(c.GitCommand.DotGitDir, "rebase-apply"), func(path string, f os.FileInfo, err error) error {
if rewrittenCount > 0 { if rewrittenCount > 0 {
rewrittenCount-- rewrittenCount--
@ -223,7 +224,7 @@ func (c *CommitListBuilder) getNormalRebasingCommits() ([]*Commit, error) {
if err != nil { if err != nil {
return err return err
} }
commits = append([]*Commit{commit}, commits...) commits = append([]*models.Commit{commit}, commits...)
return nil return nil
}) })
if err != nil { if err != nil {
@ -245,7 +246,7 @@ func (c *CommitListBuilder) getNormalRebasingCommits() ([]*Commit, error) {
// getInteractiveRebasingCommits takes our git-rebase-todo and our git-rebase-todo.backup files // getInteractiveRebasingCommits takes our git-rebase-todo and our git-rebase-todo.backup files
// and extracts out the sha and names of commits that we still have to go // and extracts out the sha and names of commits that we still have to go
// in the rebase: // in the rebase:
func (c *CommitListBuilder) getInteractiveRebasingCommits() ([]*Commit, error) { func (c *CommitListBuilder) getInteractiveRebasingCommits() ([]*models.Commit, error) {
bytesContent, err := ioutil.ReadFile(filepath.Join(c.GitCommand.DotGitDir, "rebase-merge/git-rebase-todo")) bytesContent, err := ioutil.ReadFile(filepath.Join(c.GitCommand.DotGitDir, "rebase-merge/git-rebase-todo"))
if err != nil { if err != nil {
c.Log.Error(fmt.Sprintf("error occurred reading git-rebase-todo: %s", err.Error())) c.Log.Error(fmt.Sprintf("error occurred reading git-rebase-todo: %s", err.Error()))
@ -253,7 +254,7 @@ func (c *CommitListBuilder) getInteractiveRebasingCommits() ([]*Commit, error) {
return nil, nil return nil, nil
} }
commits := []*Commit{} commits := []*models.Commit{}
lines := strings.Split(string(bytesContent), "\n") lines := strings.Split(string(bytesContent), "\n")
for _, line := range lines { for _, line := range lines {
if line == "" || line == "noop" { if line == "" || line == "noop" {
@ -263,7 +264,7 @@ func (c *CommitListBuilder) getInteractiveRebasingCommits() ([]*Commit, error) {
continue continue
} }
splitLine := strings.Split(line, " ") splitLine := strings.Split(line, " ")
commits = append([]*Commit{{ commits = append([]*models.Commit{{
Sha: splitLine[1], Sha: splitLine[1],
Name: strings.Join(splitLine[2:], " "), Name: strings.Join(splitLine[2:], " "),
Status: "rebasing", Status: "rebasing",
@ -279,18 +280,18 @@ func (c *CommitListBuilder) getInteractiveRebasingCommits() ([]*Commit, error) {
// From: Lazygit Tester <test@example.com> // From: Lazygit Tester <test@example.com>
// Date: Wed, 5 Dec 2018 21:03:23 +1100 // Date: Wed, 5 Dec 2018 21:03:23 +1100
// Subject: second commit on master // Subject: second commit on master
func (c *CommitListBuilder) commitFromPatch(content string) (*Commit, error) { func (c *CommitListBuilder) commitFromPatch(content string) (*models.Commit, error) {
lines := strings.Split(content, "\n") lines := strings.Split(content, "\n")
sha := strings.Split(lines[0], " ")[1] sha := strings.Split(lines[0], " ")[1]
name := strings.TrimPrefix(lines[3], "Subject: ") name := strings.TrimPrefix(lines[3], "Subject: ")
return &Commit{ return &models.Commit{
Sha: sha, Sha: sha,
Name: name, Name: name,
Status: "rebasing", Status: "rebasing",
}, nil }, nil
} }
func (c *CommitListBuilder) setCommitMergedStatuses(refName string, commits []*Commit) ([]*Commit, error) { func (c *CommitListBuilder) setCommitMergedStatuses(refName string, commits []*models.Commit) ([]*models.Commit, error) {
ancestor, err := c.getMergeBase(refName) ancestor, err := c.getMergeBase(refName)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -913,7 +913,7 @@ func (c *GitCommand) GenericMerge(commandType string, command string) error {
return nil return nil
} }
func (c *GitCommand) RewordCommit(commits []*Commit, index int) (*exec.Cmd, error) { func (c *GitCommand) RewordCommit(commits []*models.Commit, index int) (*exec.Cmd, error) {
todo, sha, err := c.GenerateGenericRebaseTodo(commits, index, "reword") todo, sha, err := c.GenerateGenericRebaseTodo(commits, index, "reword")
if err != nil { if err != nil {
return nil, err return nil, err
@ -922,7 +922,7 @@ func (c *GitCommand) RewordCommit(commits []*Commit, index int) (*exec.Cmd, erro
return c.PrepareInteractiveRebaseCommand(sha, todo, false) return c.PrepareInteractiveRebaseCommand(sha, todo, false)
} }
func (c *GitCommand) MoveCommitDown(commits []*Commit, index int) error { func (c *GitCommand) MoveCommitDown(commits []*models.Commit, index int) error {
// we must ensure that we have at least two commits after the selected one // we must ensure that we have at least two commits after the selected one
if len(commits) <= index+2 { if len(commits) <= index+2 {
// assuming they aren't picking the bottom commit // assuming they aren't picking the bottom commit
@ -943,7 +943,7 @@ func (c *GitCommand) MoveCommitDown(commits []*Commit, index int) error {
return c.OSCommand.RunPreparedCommand(cmd) return c.OSCommand.RunPreparedCommand(cmd)
} }
func (c *GitCommand) InteractiveRebase(commits []*Commit, index int, action string) error { func (c *GitCommand) InteractiveRebase(commits []*models.Commit, index int, action string) error {
todo, sha, err := c.GenerateGenericRebaseTodo(commits, index, action) todo, sha, err := c.GenerateGenericRebaseTodo(commits, index, action)
if err != nil { if err != nil {
return err return err
@ -1005,7 +1005,7 @@ func (c *GitCommand) SoftReset(baseSha string) error {
return c.OSCommand.RunCommand("git reset --soft " + baseSha) return c.OSCommand.RunCommand("git reset --soft " + baseSha)
} }
func (c *GitCommand) GenerateGenericRebaseTodo(commits []*Commit, actionIndex int, action string) (string, string, error) { func (c *GitCommand) GenerateGenericRebaseTodo(commits []*models.Commit, actionIndex int, action string) (string, string, error) {
baseIndex := actionIndex + 1 baseIndex := actionIndex + 1
if len(commits) <= baseIndex { if len(commits) <= baseIndex {
@ -1105,7 +1105,7 @@ func (c *GitCommand) Revert(sha string) error {
} }
// CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD // CherryPickCommits begins an interactive rebase with the given shas being cherry picked onto HEAD
func (c *GitCommand) CherryPickCommits(commits []*Commit) error { func (c *GitCommand) CherryPickCommits(commits []*models.Commit) error {
todo := "" todo := ""
for _, commit := range commits { for _, commit := range commits {
todo = "pick " + commit.Sha + " " + commit.Name + "\n" + todo todo = "pick " + commit.Sha + " " + commit.Name + "\n" + todo
@ -1188,7 +1188,7 @@ func (c *GitCommand) CheckoutFile(commitSha, fileName string) error {
} }
// DiscardOldFileChanges discards changes to a file from an old commit // DiscardOldFileChanges discards changes to a file from an old commit
func (c *GitCommand) DiscardOldFileChanges(commits []*Commit, commitIndex int, fileName string) error { func (c *GitCommand) DiscardOldFileChanges(commits []*models.Commit, commitIndex int, fileName string) error {
if err := c.BeginInteractiveRebaseForCommit(commits, commitIndex); err != nil { if err := c.BeginInteractiveRebaseForCommit(commits, commitIndex); err != nil {
return err return err
} }
@ -1299,7 +1299,7 @@ func (c *GitCommand) StashSaveStagedChanges(message string) error {
// BeginInteractiveRebaseForCommit starts an interactive rebase to edit the current // BeginInteractiveRebaseForCommit starts an interactive rebase to edit the current
// commit and pick all others. After this you'll want to call `c.GenericMerge("rebase", "continue")` // commit and pick all others. After this you'll want to call `c.GenericMerge("rebase", "continue")`
func (c *GitCommand) BeginInteractiveRebaseForCommit(commits []*Commit, commitIndex int) error { func (c *GitCommand) BeginInteractiveRebaseForCommit(commits []*models.Commit, commitIndex int) error {
if len(commits)-1 < commitIndex { if len(commits)-1 < commitIndex {
return errors.New("index outside of range of commits") return errors.New("index outside of range of commits")
} }
@ -1380,8 +1380,8 @@ func (c *GitCommand) FetchRemote(remoteName string) error {
// GetReflogCommits only returns the new reflog commits since the given lastReflogCommit // GetReflogCommits only returns the new reflog commits since the given lastReflogCommit
// if none is passed (i.e. it's value is nil) then we get all the reflog commits // if none is passed (i.e. it's value is nil) then we get all the reflog commits
func (c *GitCommand) GetReflogCommits(lastReflogCommit *Commit, filterPath string) ([]*Commit, bool, error) { func (c *GitCommand) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string) ([]*models.Commit, bool, error) {
commits := make([]*Commit, 0) commits := make([]*models.Commit, 0)
re := regexp.MustCompile(`(\w+).*HEAD@\{([^\}]+)\}: (.*)`) re := regexp.MustCompile(`(\w+).*HEAD@\{([^\}]+)\}: (.*)`)
filterPathArg := "" filterPathArg := ""
@ -1399,7 +1399,7 @@ func (c *GitCommand) GetReflogCommits(lastReflogCommit *Commit, filterPath strin
unixTimestamp, _ := strconv.Atoi(match[2]) unixTimestamp, _ := strconv.Atoi(match[2])
commit := &Commit{ commit := &models.Commit{
Sha: match[1], Sha: match[1],
Name: match[3], Name: match[3],
UnixTimestamp: int64(unixTimestamp), UnixTimestamp: int64(unixTimestamp),

View File

@ -1716,7 +1716,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
type scenario struct { type scenario struct {
testName string testName string
getLocalGitConfig func(string) (string, error) getLocalGitConfig func(string) (string, error)
commits []*Commit commits []*models.Commit
commitIndex int commitIndex int
fileName string fileName string
command func(string, ...string) *exec.Cmd command func(string, ...string) *exec.Cmd
@ -1729,7 +1729,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
func(string) (string, error) { func(string) (string, error) {
return "", nil return "", nil
}, },
[]*Commit{}, []*models.Commit{},
0, 0,
"test999.txt", "test999.txt",
nil, nil,
@ -1742,7 +1742,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
func(string) (string, error) { func(string) (string, error) {
return "true", nil return "true", nil
}, },
[]*Commit{{Name: "commit", Sha: "123456"}}, []*models.Commit{{Name: "commit", Sha: "123456"}},
0, 0,
"test999.txt", "test999.txt",
nil, nil,
@ -1755,7 +1755,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
func(string) (string, error) { func(string) (string, error) {
return "", nil return "", nil
}, },
[]*Commit{ []*models.Commit{
{Name: "commit", Sha: "123456"}, {Name: "commit", Sha: "123456"},
{Name: "commit2", Sha: "abcdef"}, {Name: "commit2", Sha: "abcdef"},
}, },

View File

@ -5,10 +5,11 @@ import (
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/models"
) )
// DeletePatchesFromCommit applies a patch in reverse for a commit // DeletePatchesFromCommit applies a patch in reverse for a commit
func (c *GitCommand) DeletePatchesFromCommit(commits []*Commit, commitIndex int, p *patch.PatchManager) error { func (c *GitCommand) DeletePatchesFromCommit(commits []*models.Commit, commitIndex int, p *patch.PatchManager) error {
if err := c.BeginInteractiveRebaseForCommit(commits, commitIndex); err != nil { if err := c.BeginInteractiveRebaseForCommit(commits, commitIndex); err != nil {
return err return err
} }
@ -35,7 +36,7 @@ func (c *GitCommand) DeletePatchesFromCommit(commits []*Commit, commitIndex int,
return c.GenericMerge("rebase", "continue") return c.GenericMerge("rebase", "continue")
} }
func (c *GitCommand) MovePatchToSelectedCommit(commits []*Commit, sourceCommitIdx int, destinationCommitIdx int, p *patch.PatchManager) error { func (c *GitCommand) MovePatchToSelectedCommit(commits []*models.Commit, sourceCommitIdx int, destinationCommitIdx int, p *patch.PatchManager) error {
if sourceCommitIdx < destinationCommitIdx { if sourceCommitIdx < destinationCommitIdx {
if err := c.BeginInteractiveRebaseForCommit(commits, destinationCommitIdx); err != nil { if err := c.BeginInteractiveRebaseForCommit(commits, destinationCommitIdx); err != nil {
return err return err
@ -136,7 +137,7 @@ func (c *GitCommand) MovePatchToSelectedCommit(commits []*Commit, sourceCommitId
return c.GenericMerge("rebase", "continue") return c.GenericMerge("rebase", "continue")
} }
func (c *GitCommand) PullPatchIntoIndex(commits []*Commit, commitIdx int, p *patch.PatchManager, stash bool) error { func (c *GitCommand) PullPatchIntoIndex(commits []*models.Commit, commitIdx int, p *patch.PatchManager, stash bool) error {
if stash { if stash {
if err := c.StashSave(c.Tr.SLocalize("StashPrefix") + commits[commitIdx].Sha); err != nil { if err := c.StashSave(c.Tr.SLocalize("StashPrefix") + commits[commitIdx].Sha); err != nil {
return err return err
@ -189,7 +190,7 @@ func (c *GitCommand) PullPatchIntoIndex(commits []*Commit, commitIdx int, p *pat
return c.GenericMerge("rebase", "continue") return c.GenericMerge("rebase", "continue")
} }
func (c *GitCommand) PullPatchIntoNewCommit(commits []*Commit, commitIdx int, p *patch.PatchManager) error { func (c *GitCommand) PullPatchIntoNewCommit(commits []*models.Commit, commitIdx int, p *patch.PatchManager) error {
if err := c.BeginInteractiveRebaseForCommit(commits, commitIdx); err != nil { if err := c.BeginInteractiveRebaseForCommit(commits, commitIdx); err != nil {
return err return err
} }

View File

@ -1,8 +1,6 @@
package gui package gui
import ( import "github.com/jesseduffield/lazygit/pkg/models"
"github.com/jesseduffield/lazygit/pkg/commands"
)
// you can only copy from one context at a time, because the order and position of commits matter // you can only copy from one context at a time, because the order and position of commits matter
@ -12,7 +10,7 @@ func (gui *Gui) resetCherryPickingIfNecessary(context Context) error {
if oldContextKey != context.GetKey() { if oldContextKey != context.GetKey() {
// need to reset the cherry picking mode // need to reset the cherry picking mode
gui.State.Modes.CherryPicking.ContextKey = context.GetKey() gui.State.Modes.CherryPicking.ContextKey = context.GetKey()
gui.State.Modes.CherryPicking.CherryPickedCommits = make([]*commands.Commit, 0) gui.State.Modes.CherryPicking.CherryPickedCommits = make([]*models.Commit, 0)
return gui.rerenderContextViewIfPresent(oldContextKey) return gui.rerenderContextViewIfPresent(oldContextKey)
} }
@ -39,7 +37,7 @@ func (gui *Gui) handleCopyCommit() error {
if !ok { if !ok {
return nil return nil
} }
commit, ok := item.(*commands.Commit) commit, ok := item.(*models.Commit)
if !ok { if !ok {
return nil return nil
} }
@ -64,7 +62,7 @@ func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
return commitShaMap return commitShaMap
} }
func (gui *Gui) commitsListForContext() []*commands.Commit { func (gui *Gui) commitsListForContext() []*models.Commit {
context := gui.currentSideContext() context := gui.currentSideContext()
if context == nil { if context == nil {
return nil return nil
@ -89,11 +87,11 @@ func (gui *Gui) addCommitToCherryPickedCommits(index int) {
commitsList := gui.commitsListForContext() commitsList := gui.commitsListForContext()
commitShaMap[commitsList[index].Sha] = true commitShaMap[commitsList[index].Sha] = true
newCommits := []*commands.Commit{} newCommits := []*models.Commit{}
for _, commit := range commitsList { for _, commit := range commitsList {
if commitShaMap[commit.Sha] { if commitShaMap[commit.Sha] {
// duplicating just the things we need to put in the rebase TODO list // duplicating just the things we need to put in the rebase TODO list
newCommits = append(newCommits, &commands.Commit{Name: commit.Name, Sha: commit.Sha}) newCommits = append(newCommits, &models.Commit{Name: commit.Name, Sha: commit.Sha})
} }
} }

View File

@ -5,11 +5,12 @@ import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/models"
) )
// list panel functions // list panel functions
func (gui *Gui) getSelectedLocalCommit() *commands.Commit { func (gui *Gui) getSelectedLocalCommit() *models.Commit {
selectedLine := gui.State.Panels.Commits.SelectedLineIdx selectedLine := gui.State.Panels.Commits.SelectedLineIdx
if selectedLine == -1 { if selectedLine == -1 {
return nil return nil
@ -443,7 +444,7 @@ func (gui *Gui) handleViewCommitFiles() error {
return gui.switchToCommitFilesContext(commit.Sha, true, gui.Contexts.BranchCommits.Context, "commits") return gui.switchToCommitFilesContext(commit.Sha, true, gui.Contexts.BranchCommits.Context, "commits")
} }
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) { func (gui *Gui) hasCommit(commits []*models.Commit, target string) (int, bool) {
for idx, commit := range commits { for idx, commit := range commits {
if commit.Sha == target { if commit.Sha == target {
return idx, true return idx, true
@ -452,7 +453,7 @@ func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool)
return -1, false return -1, false
} }
func (gui *Gui) unchooseCommit(commits []*commands.Commit, i int) []*commands.Commit { func (gui *Gui) unchooseCommit(commits []*models.Commit, i int) []*models.Commit {
return append(commits[:i], commits[i+1:]...) return append(commits[:i], commits[i+1:]...)
} }

View File

@ -14,9 +14,9 @@ import (
) )
type CustomCommandObjects struct { type CustomCommandObjects struct {
SelectedLocalCommit *commands.Commit SelectedLocalCommit *models.Commit
SelectedReflogCommit *commands.Commit SelectedReflogCommit *models.Commit
SelectedSubCommit *commands.Commit SelectedSubCommit *models.Commit
SelectedFile *commands.File SelectedFile *commands.File
SelectedLocalBranch *models.Branch SelectedLocalBranch *models.Branch
SelectedRemoteBranch *commands.RemoteBranch SelectedRemoteBranch *commands.RemoteBranch

View File

@ -255,7 +255,7 @@ func (m *Filtering) Active() bool {
} }
type CherryPicking struct { type CherryPicking struct {
CherryPickedCommits []*commands.Commit CherryPickedCommits []*models.Commit
// we only allow cherry picking from one context at a time, so you can't copy a commit from the local commits context and then also copy a commit in the reflog context // we only allow cherry picking from one context at a time, so you can't copy a commit from the local commits context and then also copy a commit in the reflog context
ContextKey string ContextKey string
@ -275,17 +275,17 @@ type guiState struct {
Files []*commands.File Files []*commands.File
SubmoduleConfigs []*commands.SubmoduleConfig SubmoduleConfigs []*commands.SubmoduleConfig
Branches []*models.Branch Branches []*models.Branch
Commits []*commands.Commit Commits []*models.Commit
StashEntries []*commands.StashEntry StashEntries []*commands.StashEntry
CommitFiles []*commands.CommitFile CommitFiles []*commands.CommitFile
// FilteredReflogCommits are the ones that appear in the reflog panel. // FilteredReflogCommits are the ones that appear in the reflog panel.
// when in filtering mode we only include the ones that match the given path // when in filtering mode we only include the ones that match the given path
FilteredReflogCommits []*commands.Commit FilteredReflogCommits []*models.Commit
// ReflogCommits are the ones used by the branches panel to obtain recency values // ReflogCommits are the ones used by the branches panel to obtain recency values
// if we're not in filtering mode, CommitFiles and FilteredReflogCommits will be // if we're not in filtering mode, CommitFiles and FilteredReflogCommits will be
// one and the same // one and the same
ReflogCommits []*commands.Commit ReflogCommits []*models.Commit
SubCommits []*commands.Commit SubCommits []*models.Commit
Remotes []*commands.Remote Remotes []*commands.Remote
RemoteBranches []*commands.RemoteBranch RemoteBranches []*commands.RemoteBranch
Tags []*commands.Tag Tags []*commands.Tag
@ -331,7 +331,7 @@ func (gui *Gui) resetState() {
} }
prevDiff := Diffing{} prevDiff := Diffing{}
prevCherryPicking := CherryPicking{ prevCherryPicking := CherryPicking{
CherryPickedCommits: make([]*commands.Commit, 0), CherryPickedCommits: make([]*models.Commit, 0),
ContextKey: "", ContextKey: "",
} }
prevRepoPathStack := []string{} prevRepoPathStack := []string{}
@ -350,9 +350,9 @@ func (gui *Gui) resetState() {
gui.State = &guiState{ gui.State = &guiState{
Files: make([]*commands.File, 0), Files: make([]*commands.File, 0),
Commits: make([]*commands.Commit, 0), Commits: make([]*models.Commit, 0),
FilteredReflogCommits: make([]*commands.Commit, 0), FilteredReflogCommits: make([]*models.Commit, 0),
ReflogCommits: make([]*commands.Commit, 0), ReflogCommits: make([]*models.Commit, 0),
StashEntries: make([]*commands.StashEntry, 0), StashEntries: make([]*commands.StashEntry, 0),
Panels: &panelStates{ Panels: &panelStates{
// TODO: work out why some of these are -1 and some are 0. Last time I checked there was a good reason but I'm less certain now // TODO: work out why some of these are -1 and some are 0. Last time I checked there was a good reason but I'm less certain now

View File

@ -4,15 +4,15 @@ import (
"strings" "strings"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/models"
"github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string) [][]string { func GetCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string) [][]string {
lines := make([][]string, len(commits)) lines := make([][]string, len(commits))
var displayFunc func(*commands.Commit, map[string]bool, bool) []string var displayFunc func(*models.Commit, map[string]bool, bool) []string
if fullDescription { if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForCommit displayFunc = getFullDescriptionDisplayStringsForCommit
} else { } else {
@ -27,7 +27,7 @@ func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription boo
return lines return lines
} }
func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string { func getFullDescriptionDisplayStringsForCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
red := color.New(color.FgRed) red := color.New(color.FgRed)
yellow := color.New(color.FgYellow) yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen) green := color.New(color.FgGreen)
@ -76,7 +76,7 @@ func getFullDescriptionDisplayStringsForCommit(c *commands.Commit, cherryPickedC
return []string{shaColor.Sprint(c.ShortSha()), secondColumnString, yellow.Sprint(truncatedAuthor), tagString + defaultColor.Sprint(c.Name)} return []string{shaColor.Sprint(c.ShortSha()), secondColumnString, yellow.Sprint(truncatedAuthor), tagString + defaultColor.Sprint(c.Name)}
} }
func getDisplayStringsForCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string { func getDisplayStringsForCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
red := color.New(color.FgRed) red := color.New(color.FgRed)
yellow := color.New(color.FgYellow) yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen) green := color.New(color.FgGreen)

View File

@ -2,15 +2,15 @@ package presentation
import ( import (
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/models"
"github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
func GetReflogCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string) [][]string { func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string) [][]string {
lines := make([][]string, len(commits)) lines := make([][]string, len(commits))
var displayFunc func(*commands.Commit, map[string]bool, bool) []string var displayFunc func(*models.Commit, map[string]bool, bool) []string
if fullDescription { if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForReflogCommit displayFunc = getFullDescriptionDisplayStringsForReflogCommit
} else { } else {
@ -25,7 +25,7 @@ func GetReflogCommitListDisplayStrings(commits []*commands.Commit, fullDescripti
return lines return lines
} }
func coloredReflogSha(c *commands.Commit, cherryPickedCommitShaMap map[string]bool) string { func coloredReflogSha(c *models.Commit, cherryPickedCommitShaMap map[string]bool) string {
var shaColor *color.Color var shaColor *color.Color
if cherryPickedCommitShaMap[c.Sha] { if cherryPickedCommitShaMap[c.Sha] {
shaColor = color.New(color.FgCyan, color.BgBlue) shaColor = color.New(color.FgCyan, color.BgBlue)
@ -36,7 +36,7 @@ func coloredReflogSha(c *commands.Commit, cherryPickedCommitShaMap map[string]bo
return shaColor.Sprint(c.ShortSha()) return shaColor.Sprint(c.ShortSha())
} }
func getFullDescriptionDisplayStringsForReflogCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string { func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
colorAttr := theme.DefaultTextColor colorAttr := theme.DefaultTextColor
if diffed { if diffed {
colorAttr = theme.DiffTerminalColor colorAttr = theme.DiffTerminalColor
@ -49,7 +49,7 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *commands.Commit, cherryP
} }
} }
func getDisplayStringsForReflogCommit(c *commands.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string { func getDisplayStringsForReflogCommit(c *models.Commit, cherryPickedCommitShaMap map[string]bool, diffed bool) []string {
defaultColor := color.New(theme.DefaultTextColor) defaultColor := color.New(theme.DefaultTextColor)
return []string{ return []string{

View File

@ -2,12 +2,12 @@ package gui
import ( import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/models"
) )
// list panel functions // list panel functions
func (gui *Gui) getSelectedReflogCommit() *commands.Commit { func (gui *Gui) getSelectedReflogCommit() *models.Commit {
selectedLine := gui.State.Panels.ReflogCommits.SelectedLineIdx selectedLine := gui.State.Panels.ReflogCommits.SelectedLineIdx
reflogComits := gui.State.FilteredReflogCommits reflogComits := gui.State.FilteredReflogCommits
if selectedLine == -1 || len(reflogComits) == 0 { if selectedLine == -1 || len(reflogComits) == 0 {
@ -49,12 +49,12 @@ func (gui *Gui) refreshReflogCommits() error {
// pulling state into its own variable incase it gets swapped out for another state // pulling state into its own variable incase it gets swapped out for another state
// and we get an out of bounds exception // and we get an out of bounds exception
state := gui.State state := gui.State
var lastReflogCommit *commands.Commit var lastReflogCommit *models.Commit
if len(state.ReflogCommits) > 0 { if len(state.ReflogCommits) > 0 {
lastReflogCommit = state.ReflogCommits[0] lastReflogCommit = state.ReflogCommits[0]
} }
refresh := func(stateCommits *[]*commands.Commit, filterPath string) error { refresh := func(stateCommits *[]*models.Commit, filterPath string) error {
commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, filterPath) commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, filterPath)
if err != nil { if err != nil {
return gui.surfaceError(err) return gui.surfaceError(err)

View File

@ -3,11 +3,12 @@ package gui
import ( import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/models"
) )
// list panel functions // list panel functions
func (gui *Gui) getSelectedSubCommit() *commands.Commit { func (gui *Gui) getSelectedSubCommit() *models.Commit {
selectedLine := gui.State.Panels.SubCommits.SelectedLineIdx selectedLine := gui.State.Panels.SubCommits.SelectedLineIdx
commits := gui.State.SubCommits commits := gui.State.SubCommits
if selectedLine == -1 || len(commits) == 0 { if selectedLine == -1 || len(commits) == 0 {

View File

@ -1,4 +1,4 @@
package commands package models
import "fmt" import "fmt"