Skip to content

Commit 8822c40

Browse files
committed
split reflog commits into ReflogCommits and FilteredReflogCommits
1 parent aa750c0 commit 8822c40

File tree

6 files changed

+50
-27
lines changed

6 files changed

+50
-27
lines changed

pkg/gui/branches_panel.go

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

pkg/gui/gui.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,17 @@ const (
186186
)
187187

188188
type guiState struct {
189-
Files []*commands.File
190-
Branches []*commands.Branch
191-
Commits []*commands.Commit
192-
StashEntries []*commands.StashEntry
193-
CommitFiles []*commands.CommitFile
189+
Files []*commands.File
190+
Branches []*commands.Branch
191+
Commits []*commands.Commit
192+
StashEntries []*commands.StashEntry
193+
CommitFiles []*commands.CommitFile
194+
// FilteredReflogCommits are the ones that appear in the reflog panel.
195+
// when in filtering mode we only include the ones that match the given path
196+
FilteredReflogCommits []*commands.Commit
197+
// ReflogCommits are the ones used by the branches panel to obtain recency values
198+
// if we're not in filtering mode, CommitFiles and FilteredReflogCommits will be
199+
// one and the same
194200
ReflogCommits []*commands.Commit
195201
DiffEntries []*commands.Commit
196202
Remotes []*commands.Remote
@@ -226,13 +232,14 @@ func (gui *Gui) resetState() {
226232
}
227233

228234
gui.State = &guiState{
229-
Files: make([]*commands.File, 0),
230-
PreviousView: "files",
231-
Commits: make([]*commands.Commit, 0),
232-
ReflogCommits: make([]*commands.Commit, 0),
233-
CherryPickedCommits: make([]*commands.Commit, 0),
234-
StashEntries: make([]*commands.StashEntry, 0),
235-
DiffEntries: make([]*commands.Commit, 0),
235+
Files: make([]*commands.File, 0),
236+
PreviousView: "files",
237+
Commits: make([]*commands.Commit, 0),
238+
FilteredReflogCommits: make([]*commands.Commit, 0),
239+
ReflogCommits: make([]*commands.Commit, 0),
240+
CherryPickedCommits: make([]*commands.Commit, 0),
241+
StashEntries: make([]*commands.StashEntry, 0),
242+
DiffEntries: make([]*commands.Commit, 0),
236243
Panels: &panelStates{
237244
Files: &filePanelState{SelectedLine: -1},
238245
Branches: &branchPanelState{SelectedLine: 0},

pkg/gui/layout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
468468
{view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes)},
469469
{view: branchesView, context: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes)},
470470
{view: commitsView, context: "branch-commits", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits)},
471-
{view: commitsView, context: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.ReflogCommits)},
471+
{view: commitsView, context: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.FilteredReflogCommits)},
472472
{view: stashView, context: "", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries)},
473473
}
474474

pkg/gui/list_view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (gui *Gui) getListViews() []*listView {
183183
{
184184
viewName: "commits",
185185
context: "reflog-commits",
186-
getItemsLength: func() int { return len(gui.State.ReflogCommits) },
186+
getItemsLength: func() int { return len(gui.State.FilteredReflogCommits) },
187187
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine },
188188
handleFocus: gui.handleReflogCommitSelect,
189189
handleItemSelect: gui.handleReflogCommitSelect,

pkg/gui/reflog_panel.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func (gui *Gui) getSelectedReflogCommit() *commands.Commit {
1212
selectedLine := gui.State.Panels.ReflogCommits.SelectedLine
13-
reflogComits := gui.State.ReflogCommits
13+
reflogComits := gui.State.FilteredReflogCommits
1414
if selectedLine == -1 || len(reflogComits) == 0 {
1515
return nil
1616
}
@@ -51,6 +51,9 @@ func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error {
5151
// load entries that have been created since we last ran the call. This means
5252
// we need to be more careful with how we use this, and to ensure we're emptying
5353
// the reflogs array when changing contexts.
54+
// This method also manages two things: ReflogCommits and FilteredReflogCommits.
55+
// FilteredReflogCommits are rendered in the reflogs panel, and ReflogCommits
56+
// are used by the branches panel to obtain recency values for sorting.
5457
func (gui *Gui) refreshReflogCommits() error {
5558
// pulling state into its own variable incase it gets swapped out for another state
5659
// and we get an out of bounds exception
@@ -60,17 +63,30 @@ func (gui *Gui) refreshReflogCommits() error {
6063
lastReflogCommit = state.ReflogCommits[0]
6164
}
6265

63-
commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, state.FilterPath)
64-
if err != nil {
65-
return gui.surfaceError(err)
66+
refresh := func(stateCommits *[]*commands.Commit, filterPath string) error {
67+
commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, filterPath)
68+
if err != nil {
69+
return gui.surfaceError(err)
70+
}
71+
72+
if onlyObtainedNewReflogCommits {
73+
*stateCommits = append(commits, *stateCommits...)
74+
} else {
75+
*stateCommits = commits
76+
}
77+
return nil
6678
}
6779

68-
if onlyObtainedNewReflogCommits {
69-
state.ReflogCommits = append(commits, state.ReflogCommits...)
80+
if err := refresh(&state.ReflogCommits, ""); err != nil {
81+
return err
82+
}
83+
84+
if gui.inFilterMode() {
85+
if err := refresh(&state.FilteredReflogCommits, state.FilterPath); err != nil {
86+
return err
87+
}
7088
} else {
71-
// if we haven't found it we're probably in a new repo so we don't want to
72-
// retain the old reflog commits
73-
state.ReflogCommits = commits
89+
state.FilteredReflogCommits = state.ReflogCommits
7490
}
7591

7692
if gui.getCommitsView().Context == "reflog-commits" {
@@ -83,8 +99,8 @@ func (gui *Gui) refreshReflogCommits() error {
8399
func (gui *Gui) renderReflogCommitsWithSelection() error {
84100
commitsView := gui.getCommitsView()
85101

86-
gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.ReflogCommits))
87-
displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.ReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL)
102+
gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.FilteredReflogCommits))
103+
displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL)
88104
gui.renderDisplayStrings(commitsView, displayStrings)
89105
if gui.g.CurrentView() == commitsView && commitsView.Context == "reflog-commits" {
90106
if err := gui.handleReflogCommitSelect(gui.g, commitsView); err != nil {

pkg/gui/undoing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type reflogAction struct {
3737
// Though we might support this later, hence the use of the CURRENT_REBASE action kind.
3838
func (gui *Gui) parseReflogForActions(onUserAction func(counter int, action reflogAction) (bool, error)) error {
3939
counter := 0
40-
reflogCommits := gui.State.ReflogCommits
40+
reflogCommits := gui.State.FilteredReflogCommits
4141
rebaseFinishCommitSha := ""
4242
var action *reflogAction
4343
for reflogCommitIdx, reflogCommit := range reflogCommits {

0 commit comments

Comments
 (0)