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
// be sure there is a state.Branches array to pick the current branch from
func (gui *Gui) refreshBranches() {
reflogCommits := gui.State.ReflogCommits
reflogCommits := gui.State.FilteredReflogCommits
if gui.inFilterMode() {
// 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

View File

@ -191,6 +191,12 @@ type guiState struct {
Commits []*commands.Commit
StashEntries []*commands.StashEntry
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
DiffEntries []*commands.Commit
Remotes []*commands.Remote
@ -229,6 +235,7 @@ func (gui *Gui) resetState() {
Files: make([]*commands.File, 0),
PreviousView: "files",
Commits: make([]*commands.Commit, 0),
FilteredReflogCommits: make([]*commands.Commit, 0),
ReflogCommits: make([]*commands.Commit, 0),
CherryPickedCommits: make([]*commands.Commit, 0),
StashEntries: make([]*commands.StashEntry, 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: "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: "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 File

@ -183,7 +183,7 @@ func (gui *Gui) getListViews() []*listView {
{
viewName: "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 },
handleFocus: gui.handleReflogCommitSelect,
handleItemSelect: gui.handleReflogCommitSelect,

View File

@ -10,7 +10,7 @@ import (
func (gui *Gui) getSelectedReflogCommit() *commands.Commit {
selectedLine := gui.State.Panels.ReflogCommits.SelectedLine
reflogComits := gui.State.ReflogCommits
reflogComits := gui.State.FilteredReflogCommits
if selectedLine == -1 || len(reflogComits) == 0 {
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
// we need to be more careful with how we use this, and to ensure we're emptying
// 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 {
// pulling state into its own variable incase it gets swapped out for another state
// and we get an out of bounds exception
@ -60,17 +63,30 @@ func (gui *Gui) refreshReflogCommits() error {
lastReflogCommit = state.ReflogCommits[0]
}
commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, state.FilterPath)
refresh := func(stateCommits *[]*commands.Commit, filterPath string) error {
commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, filterPath)
if err != nil {
return gui.surfaceError(err)
}
if onlyObtainedNewReflogCommits {
state.ReflogCommits = append(commits, state.ReflogCommits...)
*stateCommits = append(commits, *stateCommits...)
} else {
// if we haven't found it we're probably in a new repo so we don't want to
// retain the old reflog commits
state.ReflogCommits = commits
*stateCommits = commits
}
return nil
}
if err := refresh(&state.ReflogCommits, ""); err != nil {
return err
}
if gui.inFilterMode() {
if err := refresh(&state.FilteredReflogCommits, state.FilterPath); err != nil {
return err
}
} else {
state.FilteredReflogCommits = state.ReflogCommits
}
if gui.getCommitsView().Context == "reflog-commits" {
@ -83,8 +99,8 @@ func (gui *Gui) refreshReflogCommits() error {
func (gui *Gui) renderReflogCommitsWithSelection() error {
commitsView := gui.getCommitsView()
gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.ReflogCommits))
displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.ReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL)
gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.FilteredReflogCommits))
displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL)
gui.renderDisplayStrings(commitsView, displayStrings)
if gui.g.CurrentView() == commitsView && commitsView.Context == "reflog-commits" {
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.
func (gui *Gui) parseReflogForActions(onUserAction func(counter int, action reflogAction) (bool, error)) error {
counter := 0
reflogCommits := gui.State.ReflogCommits
reflogCommits := gui.State.FilteredReflogCommits
rebaseFinishCommitSha := ""
var action *reflogAction
for reflogCommitIdx, reflogCommit := range reflogCommits {