summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-24 13:06:42 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-30 18:51:23 +1000
commite33fe37a99d4b3866970b1b2f40169d1bc9afa2e (patch)
tree0027f612fb72b2603044d04389da0236df28d864 /pkg/commands
parentea54cb6e9c07ebca4a53e691fcb3cf993c793a50 (diff)
Standardise on using lo for slice functions
We've been sometimes using lo and sometimes using my slices package, and we need to pick one for consistency. Lo is more extensive and better maintained so we're going with that. My slices package was a superset of go's own slices package so in some places I've just used the official one (the methods were just wrappers anyway). I've also moved the remaining methods into the utils package.
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/bisect_info.go4
-rw-r--r--pkg/commands/git_commands/branch_loader.go12
-rw-r--r--pkg/commands/git_commands/commit_file_loader.go3
-rw-r--r--pkg/commands/git_commands/commit_loader.go5
-rw-r--r--pkg/commands/git_commands/rebase.go3
-rw-r--r--pkg/commands/git_commands/remote_loader.go5
-rw-r--r--pkg/commands/git_commands/stash_loader.go4
-rw-r--r--pkg/commands/git_commands/tag_loader.go4
-rw-r--r--pkg/commands/hosting_service/hosting_service.go5
-rw-r--r--pkg/commands/oscommands/os.go3
-rw-r--r--pkg/commands/patch/patch_builder.go5
11 files changed, 25 insertions, 28 deletions
diff --git a/pkg/commands/git_commands/bisect_info.go b/pkg/commands/git_commands/bisect_info.go
index ea20d0d38..67293803a 100644
--- a/pkg/commands/git_commands/bisect_info.go
+++ b/pkg/commands/git_commands/bisect_info.go
@@ -2,7 +2,7 @@ package git_commands
import (
"github.com/jesseduffield/generics/maps"
- "github.com/jesseduffield/generics/slices"
+ "github.com/samber/lo"
"github.com/sirupsen/logrus"
)
@@ -97,5 +97,5 @@ func (self *BisectInfo) Bisecting() bool {
return false
}
- return slices.Contains(maps.Values(self.statusMap), BisectStatusOld)
+ return lo.Contains(maps.Values(self.statusMap), BisectStatusOld)
}
diff --git a/pkg/commands/git_commands/branch_loader.go b/pkg/commands/git_commands/branch_loader.go
index 7c91c1cbc..094354cad 100644
--- a/pkg/commands/git_commands/branch_loader.go
+++ b/pkg/commands/git_commands/branch_loader.go
@@ -6,13 +6,13 @@ import (
"strings"
"github.com/jesseduffield/generics/set"
- "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/go-git/v5/config"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
+ "golang.org/x/exp/slices"
)
// context:
@@ -75,7 +75,7 @@ outer:
if strings.EqualFold(reflogBranch.Name, branch.Name) {
branch.Recency = reflogBranch.Recency
branchesWithRecency = append(branchesWithRecency, branch)
- branches = slices.Remove(branches, j)
+ branches = utils.Remove(branches, j)
continue outer
}
}
@@ -87,14 +87,14 @@ outer:
return a.Name < b.Name
})
- branches = slices.Prepend(branches, branchesWithRecency...)
+ branches = utils.Prepend(branches, branchesWithRecency...)
foundHead := false
for i, branch := range branches {
if branch.Head {
foundHead = true
branch.Recency = " *"
- branches = slices.Move(branches, i, 0)
+ branches = utils.Move(branches, i, 0)
break
}
}
@@ -103,7 +103,7 @@ outer:
if err != nil {
return nil, err
}
- branches = slices.Prepend(branches, &models.Branch{Name: info.RefName, DisplayName: info.DisplayName, Head: true, DetachedHead: info.DetachedHead, Recency: " *"})
+ branches = utils.Prepend(branches, &models.Branch{Name: info.RefName, DisplayName: info.DisplayName, Head: true, DetachedHead: info.DetachedHead, Recency: " *"})
}
configBranches, err := self.config.Branches()
@@ -131,7 +131,7 @@ func (self *BranchLoader) obtainBranches() []*models.Branch {
trimmedOutput := strings.TrimSpace(output)
outputLines := strings.Split(trimmedOutput, "\n")
- return slices.FilterMap(outputLines, func(line string) (*models.Branch, bool) {
+ return lo.FilterMap(outputLines, func(line string, _ int) (*models.Branch, bool) {
if line == "" {
return nil, false
}
diff --git a/pkg/commands/git_commands/commit_file_loader.go b/pkg/commands/git_commands/commit_file_loader.go
index d89c3c578..7abdc74c5 100644
--- a/pkg/commands/git_commands/commit_file_loader.go
+++ b/pkg/commands/git_commands/commit_file_loader.go
@@ -3,7 +3,6 @@ package git_commands
import (
"strings"
- "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common"
@@ -52,7 +51,7 @@ func getCommitFilesFromFilenames(filenames string) []*models.CommitFile {
}
// typical result looks like 'A my_file' meaning my_file was added
- return slices.Map(lo.Chunk(lines, 2), func(chunk []string) *models.CommitFile {
+ return lo.Map(lo.Chunk(lines, 2), func(chunk []string, _ int) *models.CommitFile {
return &models.CommitFile{
ChangeStatus: chunk[0],
Name: chunk[1],
diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go
index ac0f19363..f138adfaf 100644
--- a/pkg/commands/git_commands/commit_loader.go
+++ b/pkg/commands/git_commands/commit_loader.go
@@ -11,7 +11,6 @@ import (
"sync"
"github.com/fsmiamoto/git-todo-parser/todo"
- "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
@@ -233,7 +232,7 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
return nil, nil
}
- commitShas := slices.FilterMap(commits, func(commit *models.Commit) (string, bool) {
+ commitShas := lo.FilterMap(commits, func(commit *models.Commit, _ int) (string, bool) {
return commit.Sha, commit.Sha != ""
})
@@ -379,7 +378,7 @@ func (self *CommitLoader) getInteractiveRebasingCommits() ([]*models.Commit, err
// Command does not have a commit associated, skip
continue
}
- commits = slices.Prepend(commits, &models.Commit{
+ commits = utils.Prepend(commits, &models.Commit{
Sha: t.Commit,
Name: t.Msg,
Status: models.StatusRebasing,
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go
index 66bfbf82d..83c3fbe09 100644
--- a/pkg/commands/git_commands/rebase.go
+++ b/pkg/commands/git_commands/rebase.go
@@ -7,7 +7,6 @@ import (
"github.com/fsmiamoto/git-todo-parser/todo"
"github.com/go-errors/errors"
- "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/app/daemon"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
@@ -158,7 +157,7 @@ func (self *RebaseCommands) EditRebase(branchRef string) error {
}
func logTodoChanges(changes []daemon.ChangeTodoAction) string {
- changeTodoStr := strings.Join(slices.Map(changes, func(c daemon.ChangeTodoAction) string {
+ changeTodoStr := strings.Join(lo.Map(changes, func(c daemon.ChangeTodoAction, _ int) string {
return fmt.Sprintf("%s:%s", c.Sha, c.NewAction)
}), "\n")
return fmt.Sprintf("Changing TODO actions: %s", changeTodoStr)
diff --git a/pkg/commands/git_commands/remote_loader.go b/pkg/commands/git_commands/remote_loader.go
index c2a8da025..6551ecb25 100644
--- a/pkg/commands/git_commands/remote_loader.go
+++ b/pkg/commands/git_commands/remote_loader.go
@@ -4,12 +4,13 @@ import (
"strings"
"sync"
- "github.com/jesseduffield/generics/slices"
gogit "github.com/jesseduffield/go-git/v5"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
+ "golang.org/x/exp/slices"
)
type RemoteLoader struct {
@@ -53,7 +54,7 @@ func (self *RemoteLoader) GetRemotes() ([]*models.Remote, error) {
return nil, remoteBranchesErr
}
- remotes := slices.Map(goGitRemotes, func(goGitRemote *gogit.Remote) *models.Remote {
+ remotes := lo.Map(goGitRemotes, func(goGitRemote *gogit.Remote, _ int) *models.Remote {
remoteName := goGitRemote.Config().Name
branches := remoteBranchesByRemoteName[remoteName]
diff --git a/pkg/commands/git_commands/stash_loader.go b/pkg/commands/git_commands/stash_loader.go
index e5ea1da49..1ab0e0ad0 100644
--- a/pkg/commands/git_commands/stash_loader.go
+++ b/pkg/commands/git_commands/stash_loader.go
@@ -5,11 +5,11 @@ import (
"strconv"
"strings"
- "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
)
type StashLoader struct {
@@ -69,7 +69,7 @@ func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
cmdArgs := NewGitCmd("stash").Arg("list", "-z", "--pretty=%gs").ToArgv()
rawString, _ := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
- return slices.MapWithIndex(utils.SplitNul(rawString), func(line string, index int) *models.StashEntry {
+ return lo.Map(utils.SplitNul(rawString), func(line string, index int) *models.StashEntry {
return self.stashEntryFromLine(line, index)
})
}
diff --git a/pkg/commands/git_commands/tag_loader.go b/pkg/commands/git_commands/tag_loader.go
index f69ebf79a..bd05fe4b4 100644
--- a/pkg/commands/git_commands/tag_loader.go
+++ b/pkg/commands/git_commands/tag_loader.go
@@ -3,11 +3,11 @@ package git_commands
import (
"regexp"
- "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
)
type TagLoader struct {
@@ -38,7 +38,7 @@ func (self *TagLoader) GetTags() ([]*models.Tag, error) {
lineRegex := regexp.MustCompile(`^([^\s]+)(\s+)?(.*)$`)
- tags := slices.Map(split, func(line string) *models.Tag {
+ tags := lo.Map(split, func(line string, _ int) *models.Tag {
matches := lineRegex.FindStringSubmatch(line)
tagName := matches[1]
message := ""
diff --git a/pkg/commands/hosting_service/hosting_service.go b/pkg/commands/hosting_service/hosting_service.go
index dd06e1cb7..e6f9bef79 100644
--- a/pkg/commands/hosting_service/hosting_service.go
+++ b/pkg/commands/hosting_service/hosting_service.go
@@ -8,9 +8,10 @@ import (
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
"github.com/sirupsen/logrus"
- "github.com/jesseduffield/generics/slices"
+ "golang.org/x/exp/slices"
)
// This package is for handling logic specific to a git hosting service like github, gitlab, bitbucket, gitea, etc.
@@ -111,7 +112,7 @@ func (self *HostingServiceMgr) getCandidateServiceDomains() []ServiceDomain {
serviceDefinition, ok := serviceDefinitionByProvider[provider]
if !ok {
- providerNames := slices.Map(serviceDefinitions, func(serviceDefinition ServiceDefinition) string {
+ providerNames := lo.Map(serviceDefinitions, func(serviceDefinition ServiceDefinition, _ int) string {
return serviceDefinition.provider
})
diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go
index 3e305a96f..4a77310b5 100644
--- a/pkg/commands/oscommands/os.go
+++ b/pkg/commands/oscommands/os.go
@@ -13,7 +13,6 @@ import (
"github.com/samber/lo"
"github.com/atotto/clipboard"
- "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/kill"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/config"
@@ -189,7 +188,7 @@ func (c *OSCommand) FileExists(path string) (bool, error) {
// PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C
func (c *OSCommand) PipeCommands(cmdObjs ...ICmdObj) error {
- cmds := slices.Map(cmdObjs, func(cmdObj ICmdObj) *exec.Cmd {
+ cmds := lo.Map(cmdObjs, func(cmdObj ICmdObj, _ int) *exec.Cmd {
return cmdObj.GetCmd()
})
diff --git a/pkg/commands/patch/patch_builder.go b/pkg/commands/patch/patch_builder.go
index b73891911..2f350a40b 100644
--- a/pkg/commands/patch/patch_builder.go
+++ b/pkg/commands/patch/patch_builder.go
@@ -5,7 +5,6 @@ import (
"strings"
"github.com/jesseduffield/generics/maps"
- "github.com/jesseduffield/generics/slices"
"github.com/samber/lo"
"github.com/sirupsen/logrus"
)
@@ -209,10 +208,10 @@ func (p *PatchBuilder) renderEachFilePatch(plain bool) []string {
filenames := maps.Keys(p.fileInfoMap)
sort.Strings(filenames)
- patches := slices.Map(filenames, func(filename string) string {
+ patches := lo.Map(filenames, func(filename string, _ int) string {
return p.RenderPatchForFile(filename, plain, false)
})
- output := slices.Filter(patches, func(patch string) bool {
+ output := lo.Filter(patches, func(patch string, _ int) bool {
return patch != ""
})