mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
only load new reflog entries
This commit is contained in:
@ -1120,7 +1120,9 @@ func (c *GitCommand) FetchRemote(remoteName string) error {
|
|||||||
return c.OSCommand.RunCommand("git fetch %s", remoteName)
|
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")
|
output, err := c.OSCommand.RunCommandWithOutput("git reflog --abbrev=20 --date=iso")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// assume error means we have no reflog
|
// assume error means we have no reflog
|
||||||
@ -1130,10 +1132,11 @@ func (c *GitCommand) GetReflogCommits() ([]*Commit, error) {
|
|||||||
lines := strings.Split(strings.TrimSpace(output), "\n")
|
lines := strings.Split(strings.TrimSpace(output), "\n")
|
||||||
commits := make([]*Commit, 0, len(lines))
|
commits := make([]*Commit, 0, len(lines))
|
||||||
re := regexp.MustCompile(`(\w+).*HEAD@\{([^\}]+)\}: (.*)`)
|
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)
|
match := re.FindStringSubmatch(line)
|
||||||
if len(match) <= 1 {
|
if len(match) <= 1 {
|
||||||
continue
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
commit := &Commit{
|
commit := &Commit{
|
||||||
@ -1143,7 +1146,16 @@ func (c *GitCommand) GetReflogCommits() ([]*Commit, error) {
|
|||||||
Status: "reflog",
|
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)
|
commits = append(commits, commit)
|
||||||
|
return false, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return commits, nil
|
return commits, nil
|
||||||
|
@ -47,12 +47,17 @@ func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshReflogCommits() 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 {
|
if err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
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" {
|
if gui.getCommitsView().Context == "reflog-commits" {
|
||||||
return gui.renderReflogCommitsWithSelection()
|
return gui.renderReflogCommitsWithSelection()
|
||||||
|
Reference in New Issue
Block a user