diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-28 11:22:11 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-28 11:59:45 +1100 |
commit | 3f7ec3f3b801f33ca8b2bc436d8f047cdf57b4f0 (patch) | |
tree | 7d300178ab6d053c867deb2aaac28c0dcbd86cbf /pkg/commands | |
parent | 19604214d7da76a685085961095c1d7b2ad5f5cb (diff) |
load reflog commits in two stages to speed up startup time
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 5ec4bb70a..799f26326 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -1116,13 +1116,24 @@ func (c *GitCommand) FetchRemote(remoteName string) error { return c.OSCommand.RunCommand("git fetch %s", remoteName) } -// GetNewReflogCommits only returns the new reflog commits since the given lastReflogCommit +type GetReflogCommitsOptions struct { + Limit int + Recycle bool +} + +// GetReflogCommits 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, bool, error) { +func (c *GitCommand) GetReflogCommits(lastReflogCommit *Commit, options GetReflogCommitsOptions) ([]*Commit, bool, error) { commits := make([]*Commit, 0) re := regexp.MustCompile(`(\w+).*HEAD@\{([^\}]+)\}: (.*)`) - cmd := c.OSCommand.ExecutableFromString("git reflog --abbrev=20 --date=unix") - foundLastReflogCommit := false + + limitArg := "" + if options.Limit > 0 { + limitArg = fmt.Sprintf("-%d", options.Limit) + } + + cmd := c.OSCommand.ExecutableFromString(fmt.Sprintf("git reflog --abbrev=20 --date=unix %s", limitArg)) + onlyObtainedNewReflogCommits := false err := RunLineOutputCmd(cmd, func(line string) (bool, error) { match := re.FindStringSubmatch(line) if len(match) <= 1 { @@ -1138,8 +1149,8 @@ func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, b Status: "reflog", } - if lastReflogCommit != nil && commit.Sha == lastReflogCommit.Sha && commit.UnixTimestamp == lastReflogCommit.UnixTimestamp { - foundLastReflogCommit = true + if options.Recycle && lastReflogCommit != nil && commit.Sha == lastReflogCommit.Sha && commit.UnixTimestamp == lastReflogCommit.UnixTimestamp { + onlyObtainedNewReflogCommits = true // after this point we already have these reflogs loaded so we'll simply return the new ones return true, nil } @@ -1151,7 +1162,7 @@ func (c *GitCommand) GetNewReflogCommits(lastReflogCommit *Commit) ([]*Commit, b return nil, false, err } - return commits, foundLastReflogCommit, nil + return commits, onlyObtainedNewReflogCommits, nil } func (c *GitCommand) ConfiguredPager() string { |