1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-23 12:18:51 +02:00

Merge loaders package into git_commands package

This commit is contained in:
sudoburt 2022-11-10 21:19:29 -05:00 committed by Jesse Duffield
parent f67824b349
commit 3e73dacce3
21 changed files with 66 additions and 61 deletions

View File

@ -11,7 +11,6 @@ import (
gogit "github.com/jesseduffield/go-git/v5" gogit "github.com/jesseduffield/go-git/v5"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/common"
@ -42,14 +41,14 @@ type GitCommand struct {
} }
type Loaders struct { type Loaders struct {
Branches *loaders.BranchLoader BranchLoader *git_commands.BranchLoader
CommitFiles *loaders.CommitFileLoader CommitFileLoader *git_commands.CommitFileLoader
Commits *loaders.CommitLoader CommitLoader *git_commands.CommitLoader
Files *loaders.FileLoader FileLoader *git_commands.FileLoader
ReflogCommits *loaders.ReflogCommitLoader ReflogCommitLoader *git_commands.ReflogCommitLoader
Remotes *loaders.RemoteLoader RemoteLoader *git_commands.RemoteLoader
Stash *loaders.StashLoader StashLoader *git_commands.StashLoader
Tags *loaders.TagLoader TagLoader *git_commands.TagLoader
} }
func NewGitCommand( func NewGitCommand(
@ -98,10 +97,11 @@ func NewGitCommandAux(
// on the one struct. // on the one struct.
// common ones are: cmn, osCommand, dotGitDir, configCommands // common ones are: cmn, osCommand, dotGitDir, configCommands
configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo) configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo)
gitCommon := git_commands.NewGitCommon(cmn, cmd, osCommand, dotGitDir, repo, configCommands, syncMutex)
fileLoader := git_commands.NewFileLoader(cmn, cmd, configCommands)
gitCommon := git_commands.NewGitCommon(cmn, cmd, osCommand, dotGitDir, repo, configCommands, syncMutex)
statusCommands := git_commands.NewStatusCommands(gitCommon) statusCommands := git_commands.NewStatusCommands(gitCommon)
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
flowCommands := git_commands.NewFlowCommands(gitCommon) flowCommands := git_commands.NewFlowCommands(gitCommon)
remoteCommands := git_commands.NewRemoteCommands(gitCommon) remoteCommands := git_commands.NewRemoteCommands(gitCommon)
branchCommands := git_commands.NewBranchCommands(gitCommon) branchCommands := git_commands.NewBranchCommands(gitCommon)
@ -119,6 +119,14 @@ func NewGitCommandAux(
patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchManager) patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchManager)
bisectCommands := git_commands.NewBisectCommands(gitCommon) bisectCommands := git_commands.NewBisectCommands(gitCommon)
branchLoader := git_commands.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchName, configCommands)
commitFileLoader := git_commands.NewCommitFileLoader(cmn, cmd)
commitLoader := git_commands.NewCommitLoader(cmn, cmd, dotGitDir, branchCommands.CurrentBranchName, statusCommands.RebaseMode)
reflogCommitLoader := git_commands.NewReflogCommitLoader(cmn, cmd)
remoteLoader := git_commands.NewRemoteLoader(cmn, cmd, repo.Remotes)
stashLoader := git_commands.NewStashLoader(cmn, cmd)
tagLoader := git_commands.NewTagLoader(cmn, cmd)
return &GitCommand{ return &GitCommand{
Branch: branchCommands, Branch: branchCommands,
Commit: commitCommands, Commit: commitCommands,
@ -137,14 +145,14 @@ func NewGitCommandAux(
Bisect: bisectCommands, Bisect: bisectCommands,
WorkingTree: workingTreeCommands, WorkingTree: workingTreeCommands,
Loaders: Loaders{ Loaders: Loaders{
Branches: loaders.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchName, configCommands), BranchLoader: branchLoader,
CommitFiles: loaders.NewCommitFileLoader(cmn, cmd), CommitFileLoader: commitFileLoader,
Commits: loaders.NewCommitLoader(cmn, cmd, dotGitDir, branchCommands.CurrentBranchName, statusCommands.RebaseMode), CommitLoader: commitLoader,
Files: fileLoader, FileLoader: fileLoader,
ReflogCommits: loaders.NewReflogCommitLoader(cmn, cmd), ReflogCommitLoader: reflogCommitLoader,
Remotes: loaders.NewRemoteLoader(cmn, cmd, repo.Remotes), RemoteLoader: remoteLoader,
Stash: loaders.NewStashLoader(cmn, cmd), StashLoader: stashLoader,
Tags: loaders.NewTagLoader(cmn, cmd), TagLoader: tagLoader,
}, },
} }
} }

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"regexp" "regexp"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
// "*|feat/detect-purge|origin/feat/detect-purge|[ahead 1]" // "*|feat/detect-purge|origin/feat/detect-purge|[ahead 1]"
import ( import (

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"testing" "testing"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"path/filepath" "path/filepath"

View File

@ -6,7 +6,6 @@ import (
"github.com/go-errors/errors" "github.com/go-errors/errors"
gogit "github.com/jesseduffield/go-git/v5" gogit "github.com/jesseduffield/go-git/v5"
"github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/config"
@ -89,8 +88,8 @@ func buildRepo() *gogit.Repository {
return repo return repo
} }
func buildFileLoader(gitCommon *GitCommon) *loaders.FileLoader { func buildFileLoader(gitCommon *GitCommon) *FileLoader {
return loaders.NewFileLoader(gitCommon.Common, gitCommon.cmd, gitCommon.config) return NewFileLoader(gitCommon.Common, gitCommon.cmd, gitCommon.config)
} }
func buildSubmoduleCommands(deps commonDeps) *SubmoduleCommands { func buildSubmoduleCommands(deps commonDeps) *SubmoduleCommands {

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"testing" "testing"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"errors" "errors"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"fmt" "fmt"

View File

@ -4,19 +4,18 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
) )
type StashCommands struct { type StashCommands struct {
*GitCommon *GitCommon
fileLoader *loaders.FileLoader fileLoader *FileLoader
workingTree *WorkingTreeCommands workingTree *WorkingTreeCommands
} }
func NewStashCommands( func NewStashCommands(
gitCommon *GitCommon, gitCommon *GitCommon,
fileLoader *loaders.FileLoader, fileLoader *FileLoader,
workingTree *WorkingTreeCommands, workingTree *WorkingTreeCommands,
) *StashCommands { ) *StashCommands {
return &StashCommands{ return &StashCommands{
@ -111,7 +110,7 @@ func (self *StashCommands) SaveStagedChanges(message string) error {
// meaning it's deleted in your working tree but added in your index. Given that it's // meaning it's deleted in your working tree but added in your index. Given that it's
// now safely stashed, we need to remove it. // now safely stashed, we need to remove it.
files := self.fileLoader. files := self.fileLoader.
GetStatusFiles(loaders.GetStatusFileOptions{}) GetStatusFiles(GetStatusFileOptions{})
for _, file := range files { for _, file := range files {
if file.ShortStatus == "AD" { if file.ShortStatus == "AD" {

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"regexp" "regexp"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"testing" "testing"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"github.com/jesseduffield/generics/slices" "github.com/jesseduffield/generics/slices"

View File

@ -1,4 +1,4 @@
package loaders package git_commands
import ( import (
"testing" "testing"

View File

@ -9,7 +9,6 @@ import (
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/jesseduffield/generics/slices" "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
@ -18,13 +17,13 @@ import (
type WorkingTreeCommands struct { type WorkingTreeCommands struct {
*GitCommon *GitCommon
submodule *SubmoduleCommands submodule *SubmoduleCommands
fileLoader *loaders.FileLoader fileLoader *FileLoader
} }
func NewWorkingTreeCommands( func NewWorkingTreeCommands(
gitCommon *GitCommon, gitCommon *GitCommon,
submodule *SubmoduleCommands, submodule *SubmoduleCommands,
fileLoader *loaders.FileLoader, fileLoader *FileLoader,
) *WorkingTreeCommands { ) *WorkingTreeCommands {
return &WorkingTreeCommands{ return &WorkingTreeCommands{
GitCommon: gitCommon, GitCommon: gitCommon,
@ -90,7 +89,7 @@ func (self *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File)
// all files, passing the --no-renames flag and then recursively call the function // all files, passing the --no-renames flag and then recursively call the function
// again for the before file and after file. // again for the before file and after file.
filesWithoutRenames := self.fileLoader.GetStatusFiles(loaders.GetStatusFileOptions{NoRenames: true}) filesWithoutRenames := self.fileLoader.GetStatusFiles(GetStatusFileOptions{NoRenames: true})
var beforeFile *models.File var beforeFile *models.File
var afterFile *models.File var afterFile *models.File

View File

@ -1,7 +1,7 @@
package controllers package controllers
import ( import (
"github.com/jesseduffield/lazygit/pkg/commands/loaders" "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
) )
@ -57,8 +57,8 @@ func (self *SwitchToSubCommitsController) viewCommits() error {
} }
// need to populate my sub commits // need to populate my sub commits
commits, err := self.git.Loaders.Commits.GetCommits( commits, err := self.git.Loaders.CommitLoader.GetCommits(
loaders.GetCommitsOptions{ git_commands.GetCommitsOptions{
Limit: true, Limit: true,
FilterPath: self.modes.Filtering.GetPath(), FilterPath: self.modes.Filtering.GetPath(),
IncludeRebaseCommits: false, IncludeRebaseCommits: false,

View File

@ -7,7 +7,7 @@ import (
"github.com/jesseduffield/generics/set" "github.com/jesseduffield/generics/set"
"github.com/jesseduffield/generics/slices" "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/loaders" "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/context"
@ -223,8 +223,8 @@ func (gui *Gui) refreshCommitsWithLimit() error {
gui.Mutexes.LocalCommitsMutex.Lock() gui.Mutexes.LocalCommitsMutex.Lock()
defer gui.Mutexes.LocalCommitsMutex.Unlock() defer gui.Mutexes.LocalCommitsMutex.Unlock()
commits, err := gui.git.Loaders.Commits.GetCommits( commits, err := gui.git.Loaders.CommitLoader.GetCommits(
loaders.GetCommitsOptions{ git_commands.GetCommitsOptions{
Limit: gui.State.Contexts.LocalCommits.GetLimitCommits(), Limit: gui.State.Contexts.LocalCommits.GetLimitCommits(),
FilterPath: gui.State.Modes.Filtering.GetPath(), FilterPath: gui.State.Modes.Filtering.GetPath(),
IncludeRebaseCommits: true, IncludeRebaseCommits: true,
@ -245,7 +245,7 @@ func (gui *Gui) refreshCommitFilesContext() error {
to := ref.RefName() to := ref.RefName()
from, reverse := gui.State.Modes.Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) from, reverse := gui.State.Modes.Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
files, err := gui.git.Loaders.CommitFiles.GetFilesInDiff(from, to, reverse) files, err := gui.git.Loaders.CommitFileLoader.GetFilesInDiff(from, to, reverse)
if err != nil { if err != nil {
return gui.c.Error(err) return gui.c.Error(err)
} }
@ -259,7 +259,7 @@ func (gui *Gui) refreshRebaseCommits() error {
gui.Mutexes.LocalCommitsMutex.Lock() gui.Mutexes.LocalCommitsMutex.Lock()
defer gui.Mutexes.LocalCommitsMutex.Unlock() defer gui.Mutexes.LocalCommitsMutex.Unlock()
updatedCommits, err := gui.git.Loaders.Commits.MergeRebasingCommits(gui.State.Model.Commits) updatedCommits, err := gui.git.Loaders.CommitLoader.MergeRebasingCommits(gui.State.Model.Commits)
if err != nil { if err != nil {
return err return err
} }
@ -269,7 +269,7 @@ func (gui *Gui) refreshRebaseCommits() error {
} }
func (self *Gui) refreshTags() error { func (self *Gui) refreshTags() error {
tags, err := self.git.Loaders.Tags.GetTags() tags, err := self.git.Loaders.TagLoader.GetTags()
if err != nil { if err != nil {
return self.c.Error(err) return self.c.Error(err)
} }
@ -300,13 +300,13 @@ func (gui *Gui) refreshBranches() {
// which allows us to order them correctly. So if we're filtering we'll just // which allows us to order them correctly. So if we're filtering we'll just
// manually load all the reflog commits here // manually load all the reflog commits here
var err error var err error
reflogCommits, _, err = gui.git.Loaders.ReflogCommits.GetReflogCommits(nil, "") reflogCommits, _, err = gui.git.Loaders.ReflogCommitLoader.GetReflogCommits(nil, "")
if err != nil { if err != nil {
gui.c.Log.Error(err) gui.c.Log.Error(err)
} }
} }
branches, err := gui.git.Loaders.Branches.Load(reflogCommits) branches, err := gui.git.Loaders.BranchLoader.Load(reflogCommits)
if err != nil { if err != nil {
_ = gui.c.Error(err) _ = gui.c.Error(err)
} }
@ -406,8 +406,8 @@ func (gui *Gui) refreshStateFiles() error {
} }
} }
files := gui.git.Loaders.Files. files := gui.git.Loaders.FileLoader.
GetStatusFiles(loaders.GetStatusFileOptions{}) GetStatusFiles(git_commands.GetStatusFileOptions{})
conflictFileCount := 0 conflictFileCount := 0
for _, file := range files { for _, file := range files {
@ -463,7 +463,7 @@ func (gui *Gui) refreshReflogCommits() error {
} }
refresh := func(stateCommits *[]*models.Commit, filterPath string) error { refresh := func(stateCommits *[]*models.Commit, filterPath string) error {
commits, onlyObtainedNewReflogCommits, err := gui.git.Loaders.ReflogCommits. commits, onlyObtainedNewReflogCommits, err := gui.git.Loaders.ReflogCommitLoader.
GetReflogCommits(lastReflogCommit, filterPath) GetReflogCommits(lastReflogCommit, filterPath)
if err != nil { if err != nil {
return gui.c.Error(err) return gui.c.Error(err)
@ -495,7 +495,7 @@ func (gui *Gui) refreshReflogCommits() error {
func (gui *Gui) refreshRemotes() error { func (gui *Gui) refreshRemotes() error {
prevSelectedRemote := gui.State.Contexts.Remotes.GetSelected() prevSelectedRemote := gui.State.Contexts.Remotes.GetSelected()
remotes, err := gui.git.Loaders.Remotes.GetRemotes() remotes, err := gui.git.Loaders.RemoteLoader.GetRemotes()
if err != nil { if err != nil {
return gui.c.Error(err) return gui.c.Error(err)
} }
@ -525,7 +525,7 @@ func (gui *Gui) refreshRemotes() error {
} }
func (gui *Gui) refreshStashEntries() error { func (gui *Gui) refreshStashEntries() error {
gui.State.Model.StashEntries = gui.git.Loaders.Stash. gui.State.Model.StashEntries = gui.git.Loaders.StashLoader.
GetStashEntries(gui.State.Modes.Filtering.GetPath()) GetStashEntries(gui.State.Modes.Filtering.GetPath())
return gui.postRefreshUpdate(gui.State.Contexts.Stash) return gui.postRefreshUpdate(gui.State.Contexts.Stash)