summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-12-30 17:25:36 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-12-30 17:25:36 +1100
commit3f1cda88ed87bb7cb2c9cdd63f02754347961e41 (patch)
tree97d472925da8e4b6f6f068c2703b21ec0747fe5d /pkg
parentedd43bcbeb34f54b4a62c46fe99d7dfffcbfd350 (diff)
move reflog commit loader into loaders package
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/loaders/loading_reflog_commits.go (renamed from pkg/commands/loading_reflog_commits.go)22
-rw-r--r--pkg/gui/branches_panel.go2
-rw-r--r--pkg/gui/reflog_panel.go5
3 files changed, 23 insertions, 6 deletions
diff --git a/pkg/commands/loading_reflog_commits.go b/pkg/commands/loaders/loading_reflog_commits.go
index 218db9865..012c7c297 100644
--- a/pkg/commands/loading_reflog_commits.go
+++ b/pkg/commands/loaders/loading_reflog_commits.go
@@ -1,4 +1,4 @@
-package commands
+package loaders
import (
"fmt"
@@ -6,19 +6,33 @@ import (
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/common"
)
+type ReflogCommitLoader struct {
+ *common.Common
+ cmd oscommands.ICmdObjBuilder
+}
+
+func NewReflogCommitLoader(common *common.Common, cmd oscommands.ICmdObjBuilder) *ReflogCommitLoader {
+ return &ReflogCommitLoader{
+ Common: common,
+ cmd: cmd,
+ }
+}
+
// 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) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string) ([]*models.Commit, bool, error) {
+func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string) ([]*models.Commit, bool, error) {
commits := make([]*models.Commit, 0)
filterPathArg := ""
if filterPath != "" {
- filterPathArg = fmt.Sprintf(" --follow -- %s", c.OSCommand.Quote(filterPath))
+ filterPathArg = fmt.Sprintf(" --follow -- %s", self.cmd.Quote(filterPath))
}
- cmdObj := c.OSCommand.Cmd.New(fmt.Sprintf(`git log -g --abbrev=20 --format="%%h %%ct %%gs" %s`, filterPathArg))
+ cmdObj := self.cmd.New(fmt.Sprintf(`git log -g --abbrev=20 --format="%%h %%ct %%gs" %s`, filterPathArg))
onlyObtainedNewReflogCommits := false
err := cmdObj.RunAndProcessLines(func(line string) (bool, error) {
fields := strings.SplitN(line, " ", 3)
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index 599966794..14e9e9743 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -56,7 +56,7 @@ func (gui *Gui) refreshBranches() {
// which allows us to order them correctly. So if we're filtering we'll just
// manually load all the reflog commits here
var err error
- reflogCommits, _, err = gui.GitCommand.GetReflogCommits(nil, "")
+ reflogCommits, _, err = loaders.NewReflogCommitLoader(gui.Common, gui.GitCommand.Cmd).GetReflogCommits(nil, "")
if err != nil {
gui.Log.Error(err)
}
diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go
index 9df0d2501..c0f36aa42 100644
--- a/pkg/gui/reflog_panel.go
+++ b/pkg/gui/reflog_panel.go
@@ -1,6 +1,7 @@
package gui
import (
+ "github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
@@ -52,7 +53,9 @@ func (gui *Gui) refreshReflogCommits() error {
}
refresh := func(stateCommits *[]*models.Commit, filterPath string) error {
- commits, onlyObtainedNewReflogCommits, err := gui.GitCommand.GetReflogCommits(lastReflogCommit, filterPath)
+ commits, onlyObtainedNewReflogCommits, err := loaders.
+ NewReflogCommitLoader(gui.Common, gui.GitCommand.Cmd).
+ GetReflogCommits(lastReflogCommit, filterPath)
if err != nil {
return gui.surfaceError(err)
}