load reflog commits in two stages to speed up startup time

This commit is contained in:
Jesse Duffield 2020-03-28 11:22:11 +11:00
parent 19604214d7
commit 3f7ec3f3b8
5 changed files with 61 additions and 17 deletions

View file

@ -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 {