summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-12-30 13:44:41 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-04 09:07:15 +1100
commit96c2887fd0c1ca95e6b3d55756be8d424f8d905a (patch)
tree6973630fba55d6d6e3c7720db0682ec22d4094d5
parent66e840bc3f83903852408ed8db0be0c6153b5487 (diff)
WIP
-rw-r--r--pkg/commands/loader_adapters.go28
-rw-r--r--pkg/commands/loaders/branches.go (renamed from pkg/commands/loading_branches.go)30
-rw-r--r--pkg/commands/loaders/commits.go27
-rw-r--r--pkg/commands/oscommands/os_test.go2
-rw-r--r--pkg/gui/branches_panel.go8
-rw-r--r--pkg/gui/commits_panel.go5
-rw-r--r--pkg/gui/sub_commits_panel.go3
7 files changed, 35 insertions, 68 deletions
diff --git a/pkg/commands/loader_adapters.go b/pkg/commands/loader_adapters.go
deleted file mode 100644
index 166bf012d..000000000
--- a/pkg/commands/loader_adapters.go
+++ /dev/null
@@ -1,28 +0,0 @@
-package commands
-
-import (
- "io/ioutil"
- "path/filepath"
-
- "github.com/jesseduffield/lazygit/pkg/commands/loaders"
- "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
- "github.com/jesseduffield/lazygit/pkg/common"
-)
-
-// this file defines constructors for loaders, passing in all the dependencies required based on a smaller set of arguments passed in by the client.
-
-func NewCommitLoader(
- cmn *common.Common,
- gitCommand *GitCommand,
- osCommand *oscommands.OSCommand,
-) *loaders.CommitLoader {
- return loaders.NewCommitLoader(
- cmn,
- gitCommand.Cmd,
- gitCommand.CurrentBranchName,
- gitCommand.RebaseMode,
- ioutil.ReadFile,
- filepath.Walk,
- gitCommand.DotGitDir,
- )
-}
diff --git a/pkg/commands/loading_branches.go b/pkg/commands/loaders/branches.go
index 62f758bcd..fc3c15fc9 100644
--- a/pkg/commands/loading_branches.go
+++ b/pkg/commands/loaders/branches.go
@@ -1,9 +1,10 @@
-package commands
+package loaders
import (
"regexp"
"strings"
+ "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -20,32 +21,29 @@ import (
// if we find out we need to use one of these functions in the git.go file, we
// can just pull them out of here and put them there and then call them from in here
-const SEPARATION_CHAR = "|"
-
-// BranchListBuilder returns a list of Branch objects for the current repo
-type BranchListBuilder struct {
+// BranchLoader returns a list of Branch objects for the current repo
+type BranchLoader struct {
*common.Common
getRawBranches func() (string, error)
getCurrentBranchName func() (string, string, error)
reflogCommits []*models.Commit
}
-func NewBranchListBuilder(
+func NewBranchLoader(
cmn *common.Common,
- getRawBranches func() (string, error),
- getCurrentBranchName func() (string, string, error),
+ gitCommand *commands.GitCommand,
reflogCommits []*models.Commit,
-) *BranchListBuilder {
- return &BranchListBuilder{
+) *BranchLoader {
+ return &BranchLoader{
Common: cmn,
- getRawBranches: getRawBranches,
- getCurrentBranchName: getCurrentBranchName,
+ getRawBranches: gitCommand.GetRawBranches,
+ getCurrentBranchName: gitCommand.CurrentBranchName,
reflogCommits: reflogCommits,
}
}
-// Build the list of branches for the current repo
-func (b *BranchListBuilder) Build() []*models.Branch {
+// Load the list of branches for the current repo
+func (b *BranchLoader) Load() []*models.Branch {
branches := b.obtainBranches()
reflogBranches := b.obtainReflogBranches()
@@ -89,7 +87,7 @@ outer:
return branches
}
-func (b *BranchListBuilder) obtainBranches() []*models.Branch {
+func (b *BranchLoader) obtainBranches() []*models.Branch {
output, err := b.getRawBranches()
if err != nil {
panic(err)
@@ -152,7 +150,7 @@ func (b *BranchListBuilder) obtainBranches() []*models.Branch {
// TODO: only look at the new reflog commits, and otherwise store the recencies in
// int form against the branch to recalculate the time ago
-func (b *BranchListBuilder) obtainReflogBranches() []*models.Branch {
+func (b *BranchLoader) obtainReflogBranches() []*models.Branch {
foundBranchesMap := map[string]bool{}
re := regexp.MustCompile(`checkout: moving from ([\S]+) to ([\S]+)`)
reflogBranches := make([]*models.Branch, 0, len(b.reflogCommits))
diff --git a/pkg/commands/loaders/commits.go b/pkg/commands/loaders/commits.go
index 5fc2caa98..bbd520c81 100644
--- a/pkg/commands/loaders/commits.go
+++ b/pkg/commands/loaders/commits.go
@@ -2,12 +2,14 @@ package loaders
import (
"fmt"
+ "io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
+ "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
@@ -35,23 +37,20 @@ type CommitLoader struct {
dotGitDir string
}
+// making our dependencies explicit for the sake of easier testing
func NewCommitLoader(
- common *common.Common,
- cmd oscommands.ICmdObjBuilder,
- getCurrentBranchName func() (string, string, error),
- getRebaseMode func() (enums.RebaseMode, error),
- readFile func(filename string) ([]byte, error),
- walkFiles func(root string, fn filepath.WalkFunc) error,
- dotGitDir string,
+ cmn *common.Common,
+ gitCommand *commands.GitCommand,
+ osCommand *oscommands.OSCommand,
) *CommitLoader {
return &CommitLoader{
- Common: common,
- cmd: cmd,
- getCurrentBranchName: getCurrentBranchName,
- getRebaseMode: getRebaseMode,
- readFile: readFile,
- walkFiles: walkFiles,
- dotGitDir: dotGitDir,
+ Common: cmn,
+ cmd: gitCommand.Cmd,
+ getCurrentBranchName: gitCommand.CurrentBranchName,
+ getRebaseMode: gitCommand.RebaseMode,
+ readFile: ioutil.ReadFile,
+ walkFiles: filepath.Walk,
+ dotGitDir: gitCommand.DotGitDir,
}
}
diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go
index 424aa72b3..73c846fb0 100644
--- a/pkg/commands/oscommands/os_test.go
+++ b/pkg/commands/oscommands/os_test.go
@@ -55,7 +55,7 @@ func TestOSCommandRun(t *testing.T) {
for _, s := range scenarios {
c := NewDummyOSCommand()
- s.test(c.Cmd.New(s.command)).Run()
+ s.test(c.Cmd.New(s.command).Run())
}
}
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index 8dff14ac1..599966794 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -61,13 +62,12 @@ func (gui *Gui) refreshBranches() {
}
}
- builder := commands.NewBranchListBuilder(
+ loader := loaders.NewBranchLoader(
gui.Common,
- gui.GitCommand.GetRawBranches,
- gui.GitCommand.CurrentBranchName,
+ gui.GitCommand,
reflogCommits,
)
- gui.State.Branches = builder.Build()
+ gui.State.Branches = loader.Load()
if err := gui.postRefreshUpdate(gui.State.Contexts.Branches); err != nil {
gui.Log.Error(err)
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index cd85dafd5..2fd04475a 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -4,7 +4,6 @@ import (
"fmt"
"sync"
- "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
@@ -120,7 +119,7 @@ func (gui *Gui) refreshCommitsWithLimit() error {
gui.Mutexes.BranchCommitsMutex.Lock()
defer gui.Mutexes.BranchCommitsMutex.Unlock()
- loader := commands.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
+ loader := loaders.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
commits, err := loader.GetCommits(
loaders.GetCommitsOptions{
@@ -143,7 +142,7 @@ func (gui *Gui) refreshRebaseCommits() error {
gui.Mutexes.BranchCommitsMutex.Lock()
defer gui.Mutexes.BranchCommitsMutex.Unlock()
- loader := commands.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
+ loader := loaders.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
updatedCommits, err := loader.MergeRebasingCommits(gui.State.Commits)
if err != nil {
diff --git a/pkg/gui/sub_commits_panel.go b/pkg/gui/sub_commits_panel.go
index a41ccb315..75bd957d8 100644
--- a/pkg/gui/sub_commits_panel.go
+++ b/pkg/gui/sub_commits_panel.go
@@ -1,7 +1,6 @@
package gui
import (
- "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
@@ -76,7 +75,7 @@ func (gui *Gui) handleViewSubCommitFiles() error {
func (gui *Gui) switchToSubCommitsContext(refName string) error {
// need to populate my sub commits
- loader := commands.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
+ loader := loaders.NewCommitLoader(gui.Common, gui.GitCommand, gui.OSCommand)
commits, err := loader.GetCommits(
loaders.GetCommitsOptions{