diff --git a/pkg/commands/commit_list_builder.go b/pkg/commands/commit_list_builder.go index 6032704c7..a467b3517 100644 --- a/pkg/commands/commit_list_builder.go +++ b/pkg/commands/commit_list_builder.go @@ -46,7 +46,7 @@ func NewCommitListBuilder(log *logrus.Entry, gitCommand *GitCommand, osCommand * } // GetCommits obtains the commits of the current branch -func (c *CommitListBuilder) GetCommits() ([]*Commit, error) { +func (c *CommitListBuilder) GetCommits(limit bool) ([]*Commit, error) { commits := []*Commit{} var rebasingCommits []*Commit rebaseMode, err := c.GitCommand.RebaseMode() @@ -65,7 +65,7 @@ func (c *CommitListBuilder) GetCommits() ([]*Commit, error) { } unpushedCommits := c.getUnpushedCommits() - log := c.getLog() + log := c.getLog(limit) // now we can split it up and turn it into commits for _, line := range utils.SplitLines(log) { @@ -281,12 +281,15 @@ func (c *CommitListBuilder) getUnpushedCommits() map[string]bool { return pushables } -// getLog gets the git log (currently limited to 30 commits for performance -// until we work out lazy loading -func (c *CommitListBuilder) getLog() string { - // currently limiting to 30 for performance reasons - // TODO: add lazyloading when you scroll down - result, err := c.OSCommand.RunCommandWithOutput("git log --oneline -30") +// getLog gets the git log. +func (c *CommitListBuilder) getLog(limit bool) string { + limitFlag := "" + if limit { + limitFlag = "-30" + } + + c.Log.Warn(fmt.Sprintf("git log --oneline %s", limitFlag)) + result, err := c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git log --oneline %s", limitFlag)) if err != nil { // assume if there is an error there are no commits yet for this branch return "" diff --git a/pkg/commands/commit_list_builder_test.go b/pkg/commands/commit_list_builder_test.go index a1f4a4da9..8b843d849 100644 --- a/pkg/commands/commit_list_builder_test.go +++ b/pkg/commands/commit_list_builder_test.go @@ -188,7 +188,7 @@ func TestCommitListBuilderGetLog(t *testing.T) { t.Run(s.testName, func(t *testing.T) { c := NewDummyCommitListBuilder() c.OSCommand.SetCommand(s.command) - s.test(c.getLog()) + s.test(c.getLog(true)) }) } } @@ -312,7 +312,7 @@ func TestCommitListBuilderGetCommits(t *testing.T) { t.Run(s.testName, func(t *testing.T) { c := NewDummyCommitListBuilder() c.OSCommand.SetCommand(s.command) - s.test(c.GetCommits()) + s.test(c.GetCommits(true)) }) } } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 67c126aea..32672a40b 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -37,6 +37,16 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { return err } + state := gui.State.Panels.Commits + if state.SelectedLine > 20 && state.LimitCommits { + state.LimitCommits = false + go func() { + if err := gui.refreshCommitsWithLimit(); err != nil { + _ = gui.createErrorPanel(gui.g, err.Error()) + } + }() + } + gui.getMainView().Title = "Patch" gui.getSecondaryView().Title = "Custom Patch" gui.State.Panels.LineByLine = nil @@ -64,15 +74,12 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) refreshCommits(g *gocui.Gui) error { g.Update(func(*gocui.Gui) error { - builder, err := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits, gui.State.DiffEntries) - if err != nil { + // I think this is here for the sake of some kind of rebasing thing + gui.refreshStatus(g) + + if err := gui.refreshCommitsWithLimit(); err != nil { return err } - commits, err := builder.GetCommits() - if err != nil { - return err - } - gui.State.Commits = commits // doing this async because it shouldn't hold anything up go func() { @@ -81,12 +88,6 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error { } }() - gui.refreshStatus(g) - if gui.getCommitsView().Context == "branch-commits" { - if err := gui.renderBranchCommitsWithSelection(); err != nil { - return err - } - } if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.MainContext == "patch-building") { return gui.refreshCommitFilesView() } @@ -95,6 +96,27 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error { return nil } +func (gui *Gui) refreshCommitsWithLimit() error { + builder, err := commands.NewCommitListBuilder(gui.Log, gui.GitCommand, gui.OSCommand, gui.Tr, gui.State.CherryPickedCommits, gui.State.DiffEntries) + if err != nil { + return err + } + + commits, err := builder.GetCommits(gui.State.Panels.Commits.LimitCommits) + if err != nil { + return err + } + gui.State.Commits = commits + + if gui.getCommitsView().Context == "branch-commits" { + if err := gui.renderBranchCommitsWithSelection(); err != nil { + return err + } + } + + return nil +} + // specific functions func (gui *Gui) handleResetToCommit(g *gocui.Gui, commitView *gocui.View) error { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 9bfeae6c4..2bdb66e0f 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -128,6 +128,7 @@ type tagsPanelState struct { type commitPanelState struct { SelectedLine int SpecificDiffMode bool + LimitCommits bool } type reflogCommitPanelState struct { @@ -212,7 +213,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma Remotes: &remotePanelState{SelectedLine: 0}, RemoteBranches: &remoteBranchesState{SelectedLine: -1}, Tags: &tagsPanelState{SelectedLine: -1}, - Commits: &commitPanelState{SelectedLine: -1}, + Commits: &commitPanelState{SelectedLine: -1, LimitCommits: true}, ReflogCommits: &reflogCommitPanelState{SelectedLine: 0}, // TODO: might need to make -1 CommitFiles: &commitFilesPanelState{SelectedLine: -1}, Stash: &stashPanelState{SelectedLine: -1},