1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

split reflog commits into ReflogCommits and FilteredReflogCommits

This commit is contained in:
Jesse Duffield
2020-03-29 11:06:46 +11:00
parent aa750c0819
commit 8822c409e2
6 changed files with 50 additions and 27 deletions

View File

@ -54,7 +54,7 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
// gui.refreshStatus is called at the end of this because that's when we can // gui.refreshStatus is called at the end of this because that's when we can
// be sure there is a state.Branches array to pick the current branch from // be sure there is a state.Branches array to pick the current branch from
func (gui *Gui) refreshBranches() { func (gui *Gui) refreshBranches() {
reflogCommits := gui.State.ReflogCommits reflogCommits := gui.State.FilteredReflogCommits
if gui.inFilterMode() { if gui.inFilterMode() {
// in filter mode we filter our reflog commits to just those containing the path // in filter mode we filter our reflog commits to just those containing the path
// however we need all the reflog entries to populate the recencies of our branches // however we need all the reflog entries to populate the recencies of our branches

View File

@ -186,11 +186,17 @@ const (
) )
type guiState struct { type guiState struct {
Files []*commands.File Files []*commands.File
Branches []*commands.Branch Branches []*commands.Branch
Commits []*commands.Commit Commits []*commands.Commit
StashEntries []*commands.StashEntry StashEntries []*commands.StashEntry
CommitFiles []*commands.CommitFile CommitFiles []*commands.CommitFile
// FilteredReflogCommits are the ones that appear in the reflog panel.
// when in filtering mode we only include the ones that match the given path
FilteredReflogCommits []*commands.Commit
// 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
// one and the same
ReflogCommits []*commands.Commit ReflogCommits []*commands.Commit
DiffEntries []*commands.Commit DiffEntries []*commands.Commit
Remotes []*commands.Remote Remotes []*commands.Remote
@ -226,13 +232,14 @@ func (gui *Gui) resetState() {
} }
gui.State = &guiState{ gui.State = &guiState{
Files: make([]*commands.File, 0), Files: make([]*commands.File, 0),
PreviousView: "files", PreviousView: "files",
Commits: make([]*commands.Commit, 0), Commits: make([]*commands.Commit, 0),
ReflogCommits: make([]*commands.Commit, 0), FilteredReflogCommits: make([]*commands.Commit, 0),
CherryPickedCommits: make([]*commands.Commit, 0), ReflogCommits: make([]*commands.Commit, 0),
StashEntries: make([]*commands.StashEntry, 0), CherryPickedCommits: make([]*commands.Commit, 0),
DiffEntries: make([]*commands.Commit, 0), StashEntries: make([]*commands.StashEntry, 0),
DiffEntries: make([]*commands.Commit, 0),
Panels: &panelStates{ Panels: &panelStates{
Files: &filePanelState{SelectedLine: -1}, Files: &filePanelState{SelectedLine: -1},
Branches: &branchPanelState{SelectedLine: 0}, Branches: &branchPanelState{SelectedLine: 0},

View File

@ -468,7 +468,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
{view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes)}, {view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes)},
{view: branchesView, context: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes)}, {view: branchesView, context: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes)},
{view: commitsView, context: "branch-commits", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits)}, {view: commitsView, context: "branch-commits", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits)},
{view: commitsView, context: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.ReflogCommits)}, {view: commitsView, context: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.FilteredReflogCommits)},
{view: stashView, context: "", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries)}, {view: stashView, context: "", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries)},
} }

View File

@ -183,7 +183,7 @@ func (gui *Gui) getListViews() []*listView {
{ {
viewName: "commits", viewName: "commits",
context: "reflog-commits", context: "reflog-commits",
getItemsLength: func() int { return len(gui.State.ReflogCommits) }, getItemsLength: func() int { return len(gui.State.FilteredReflogCommits) },
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine },
handleFocus: gui.handleReflogCommitSelect, handleFocus: gui.handleReflogCommitSelect,
handleItemSelect: gui.handleReflogCommitSelect, handleItemSelect: gui.handleReflogCommitSelect,

View File

@ -10,7 +10,7 @@ import (
func (gui *Gui) getSelectedReflogCommit() *commands.Commit { func (gui *Gui) getSelectedReflogCommit() *commands.Commit {
selectedLine := gui.State.Panels.ReflogCommits.SelectedLine selectedLine := gui.State.Panels.ReflogCommits.SelectedLine
reflogComits := gui.State.ReflogCommits reflogComits := gui.State.FilteredReflogCommits
if selectedLine == -1 || len(reflogComits) == 0 { if selectedLine == -1 || len(reflogComits) == 0 {
return nil return nil
} }
@ -51,6 +51,9 @@ func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error {
// load entries that have been created since we last ran the call. This means // load entries that have been created since we last ran the call. This means
// we need to be more careful with how we use this, and to ensure we're emptying // we need to be more careful with how we use this, and to ensure we're emptying
// the reflogs array when changing contexts. // the reflogs array when changing contexts.
// This method also manages two things: ReflogCommits and FilteredReflogCommits.
// FilteredReflogCommits are rendered in the reflogs panel, and ReflogCommits
// are used by the branches panel to obtain recency values for sorting.
func (gui *Gui) refreshReflogCommits() error { 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
@ -60,17 +63,30 @@ func (gui *Gui) refreshReflogCommits() error {
lastReflogCommit = state.ReflogCommits[0] lastReflogCommit = state.ReflogCommits[0]
} }
commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, state.FilterPath) refresh := func(stateCommits *[]*commands.Commit, filterPath string) error {
if err != nil { commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, filterPath)
return gui.surfaceError(err) if err != nil {
return gui.surfaceError(err)
}
if onlyObtainedNewReflogCommits {
*stateCommits = append(commits, *stateCommits...)
} else {
*stateCommits = commits
}
return nil
} }
if onlyObtainedNewReflogCommits { if err := refresh(&state.ReflogCommits, ""); err != nil {
state.ReflogCommits = append(commits, state.ReflogCommits...) return err
}
if gui.inFilterMode() {
if err := refresh(&state.FilteredReflogCommits, state.FilterPath); err != nil {
return err
}
} else { } else {
// if we haven't found it we're probably in a new repo so we don't want to state.FilteredReflogCommits = state.ReflogCommits
// retain the old reflog commits
state.ReflogCommits = commits
} }
if gui.getCommitsView().Context == "reflog-commits" { if gui.getCommitsView().Context == "reflog-commits" {
@ -83,8 +99,8 @@ func (gui *Gui) refreshReflogCommits() error {
func (gui *Gui) renderReflogCommitsWithSelection() error { func (gui *Gui) renderReflogCommitsWithSelection() error {
commitsView := gui.getCommitsView() commitsView := gui.getCommitsView()
gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.ReflogCommits)) gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.FilteredReflogCommits))
displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.ReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL) displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL)
gui.renderDisplayStrings(commitsView, displayStrings) gui.renderDisplayStrings(commitsView, displayStrings)
if gui.g.CurrentView() == commitsView && commitsView.Context == "reflog-commits" { if gui.g.CurrentView() == commitsView && commitsView.Context == "reflog-commits" {
if err := gui.handleReflogCommitSelect(gui.g, commitsView); err != nil { if err := gui.handleReflogCommitSelect(gui.g, commitsView); err != nil {

View File

@ -37,7 +37,7 @@ type reflogAction struct {
// Though we might support this later, hence the use of the CURRENT_REBASE action kind. // Though we might support this later, hence the use of the CURRENT_REBASE action kind.
func (gui *Gui) parseReflogForActions(onUserAction func(counter int, action reflogAction) (bool, error)) error { func (gui *Gui) parseReflogForActions(onUserAction func(counter int, action reflogAction) (bool, error)) error {
counter := 0 counter := 0
reflogCommits := gui.State.ReflogCommits reflogCommits := gui.State.FilteredReflogCommits
rebaseFinishCommitSha := "" rebaseFinishCommitSha := ""
var action *reflogAction var action *reflogAction
for reflogCommitIdx, reflogCommit := range reflogCommits { for reflogCommitIdx, reflogCommit := range reflogCommits {