summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-26 21:12:40 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-26 21:44:33 +1100
commitf2036b42e53e1fc647f431e08e078e5c96bc4352 (patch)
tree9383b7f76b57cb72263c61a3f5922a4b1de1c5a1 /pkg/commands
parent21b7d4184535e1132c828c379c7125ecd100e02a (diff)
only load new reflog entries
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git.go18
1 files changed, 15 insertions, 3 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