summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-01-11 18:23:35 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-01-12 10:10:56 +1100
commit282f08df36eb2939d1a1caf12457680b38089e0a (patch)
treeec468e4ba77b30025aa72e7a7d185a45a8735cf5 /pkg
parentd647a96ed55e134f1464878be8d0be3a464d996f (diff)
lazyload commits
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/commit_list_builder.go19
-rw-r--r--pkg/commands/commit_list_builder_test.go4
-rw-r--r--pkg/gui/commits_panel.go48
-rw-r--r--pkg/gui/gui.go3
4 files changed, 50 insertions, 24 deletions
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 {
- return err
- }
- commits, err := builder.GetCommits()
- 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
}
- 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},