diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-26 21:12:40 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-26 21:44:33 +1100 |
commit | f2036b42e53e1fc647f431e08e078e5c96bc4352 (patch) | |
tree | 9383b7f76b57cb72263c61a3f5922a4b1de1c5a1 | |
parent | 21b7d4184535e1132c828c379c7125ecd100e02a (diff) |
only load new reflog entries
-rw-r--r-- | pkg/commands/git.go | 18 | ||||
-rw-r--r-- | pkg/gui/reflog_panel.go | 9 |
2 files changed, 22 insertions, 5 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 4884519ea..8c76ddf48 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -1120,7 +1120,9 @@ func (c *GitCommand) FetchRemote(remoteName string) error { return c.OSCommand.RunCommand("git fetch %s", remoteName) } -func (c *GitCommand) GetReflogCommits() ([]*Commit, error) { +// GetNewReflogCommits only returns the new reflog commits since the given lastReflogCommit +// if none is passed (i.e. it's value is nil) then we get all the reflog commits +func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, error) { output, err := c.OSCommand.RunCommandWithOutput("git reflog --abbrev=20 --date=iso") if err != nil { // assume error means we have no reflog @@ -1130,10 +1132,11 @@ func (c *GitCommand) GetReflogCommits() ([]*Commit, error) { lines := strings.Split(strings.TrimSpace(output), "\n") commits := make([]*Commit, 0, len(lines)) re := regexp.MustCompile(`(\w+).*HEAD@\{([^\}]+)\}: (.*)`) - for _, line := range lines { + cmd := c.OSCommand.ExecutableFromString("git reflog --abbrev=20 --date=iso") + err = RunLineOutputCmd(cmd, func(line string) (bool, error) { match := re.FindStringSubmatch(line) if len(match) <= 1 { - continue + return false, nil } commit := &Commit{ @@ -1143,7 +1146,16 @@ func (c *GitCommand) GetReflogCommits() ([]*Commit, error) { Status: "reflog", } + if lastReflogCommit != nil && commit.Sha == lastReflogCommit.Sha && commit.Date == lastReflogCommit.Date { + // after this point we already have these reflogs loaded so we'll simply return the new ones + return true, nil + } + commits = append(commits, commit) + return false, nil + }) + if err != nil { + return nil, err } return commits, nil diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index fd26a67c8..199d9337f 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -47,12 +47,17 @@ func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) refreshReflogCommits() error { - commits, err := gui.GitCommand.GetReflogCommits() + var lastReflogCommit *commands.Commit + if len(gui.State.ReflogCommits) > 0 { + lastReflogCommit = gui.State.ReflogCommits[0] + } + + commits, err := gui.GitCommand.GetNewReflogCommits(lastReflogCommit) if err != nil { return gui.createErrorPanel(gui.g, err.Error()) } - gui.State.ReflogCommits = commits + gui.State.ReflogCommits = append(commits, gui.State.ReflogCommits...) if gui.getCommitsView().Context == "reflog-commits" { return gui.renderReflogCommitsWithSelection() |