summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-03-19 12:26:30 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-24 20:14:41 +1100
commitc7a629c4401ae0d4aad06767c88ce1e9e418dbf3 (patch)
tree2ff5599041030a423e02214989f07129772337c6 /pkg/commands
parentdde30fa104347ab9c01f82b7886864b473e6f51c (diff)
make more use of generics
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/rebase_test.go4
-rw-r--r--pkg/commands/loaders/branches.go7
-rw-r--r--pkg/commands/loaders/files.go10
-rw-r--r--pkg/commands/patch/hunk.go3
-rw-r--r--pkg/commands/patch/patch_manager.go6
-rw-r--r--pkg/commands/patch/patch_parser.go3
6 files changed, 18 insertions, 15 deletions
diff --git a/pkg/commands/git_commands/rebase_test.go b/pkg/commands/git_commands/rebase_test.go
index 56df77a86..4e7b5c2c6 100644
--- a/pkg/commands/git_commands/rebase_test.go
+++ b/pkg/commands/git_commands/rebase_test.go
@@ -8,7 +8,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
- "github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
"github.com/stretchr/testify/assert"
)
@@ -64,7 +64,7 @@ func TestRebaseSkipEditorCommand(t *testing.T) {
"^LAZYGIT_CLIENT_COMMAND=EXIT_IMMEDIATELY$",
} {
regexStr := regexStr
- foundMatch := utils.IncludesStringFunc(envVars, func(envVar string) bool {
+ foundMatch := lo.ContainsBy(envVars, func(envVar string) bool {
return regexp.MustCompile(regexStr).MatchString(envVar)
})
if !foundMatch {
diff --git a/pkg/commands/loaders/branches.go b/pkg/commands/loaders/branches.go
index 1f78908a8..9fa1e80f4 100644
--- a/pkg/commands/loaders/branches.go
+++ b/pkg/commands/loaders/branches.go
@@ -4,6 +4,7 @@ import (
"regexp"
"strings"
+ "github.com/jesseduffield/generics/set"
"github.com/jesseduffield/go-git/v5/config"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/common"
@@ -181,15 +182,15 @@ func (self *BranchLoader) 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 (self *BranchLoader) obtainReflogBranches(reflogCommits []*models.Commit) []*models.Branch {
- foundBranchesMap := map[string]bool{}
+ foundBranches := set.New[string]()
re := regexp.MustCompile(`checkout: moving from ([\S]+) to ([\S]+)`)
reflogBranches := make([]*models.Branch, 0, len(reflogCommits))
for _, commit := range reflogCommits {
if match := re.FindStringSubmatch(commit.Name); len(match) == 3 {
recency := utils.UnixToTimeAgo(commit.UnixTimestamp)
for _, branchName := range match[1:] {
- if !foundBranchesMap[branchName] {
- foundBranchesMap[branchName] = true
+ if !foundBranches.Includes(branchName) {
+ foundBranches.Add(branchName)
reflogBranches = append(reflogBranches, &models.Branch{
Recency: recency,
Name: branchName,
diff --git a/pkg/commands/loaders/files.go b/pkg/commands/loaders/files.go
index f5becdb92..8ab727453 100644
--- a/pkg/commands/loaders/files.go
+++ b/pkg/commands/loaders/files.go
@@ -7,7 +7,7 @@ import (
"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 FileLoaderConfig interface {
@@ -57,10 +57,10 @@ func (self *FileLoader) GetStatusFiles(opts GetStatusFileOptions) []*models.File
change := status.Change
stagedChange := change[0:1]
unstagedChange := change[1:2]
- untracked := utils.IncludesString([]string{"??", "A ", "AM"}, change)
- hasNoStagedChanges := utils.IncludesString([]string{" ", "U", "?"}, stagedChange)
- hasInlineMergeConflicts := utils.IncludesString([]string{"UU", "AA"}, change)
- hasMergeConflicts := hasInlineMergeConflicts || utils.IncludesString([]string{"DD", "AU", "UA", "UD", "DU"}, change)
+ untracked := lo.Contains([]string{"??", "A ", "AM"}, change)
+ hasNoStagedChanges := lo.Contains([]string{" ", "U", "?"}, stagedChange)
+ hasInlineMergeConflicts := lo.Contains([]string{"UU", "AA"}, change)
+ hasMergeConflicts := hasInlineMergeConflicts || lo.Contains([]string{"DD", "AU", "UA", "UD", "DU"}, change)
file := &models.File{
Name: status.Name,
diff --git a/pkg/commands/patch/hunk.go b/pkg/commands/patch/hunk.go
index bbb2d54ff..98d932126 100644
--- a/pkg/commands/patch/hunk.go
+++ b/pkg/commands/patch/hunk.go
@@ -5,6 +5,7 @@ import (
"strings"
"github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
)
type PatchHunk struct {
@@ -54,7 +55,7 @@ func (hunk *PatchHunk) updatedLines(lineIndices []int, reverse bool) []string {
if line == "" {
break
}
- isLineSelected := utils.IncludesInt(lineIndices, lineIdx)
+ isLineSelected := lo.Contains(lineIndices, lineIdx)
firstChar, content := line[:1], line[1:]
transformedFirstChar := transformedFirstChar(firstChar, reverse, isLineSelected)
diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_manager.go
index cbdf7b2d4..1282356f8 100644
--- a/pkg/commands/patch/patch_manager.go
+++ b/pkg/commands/patch/patch_manager.go
@@ -4,7 +4,7 @@ import (
"sort"
"strings"
- "github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
"github.com/sirupsen/logrus"
)
@@ -140,7 +140,7 @@ func (p *PatchManager) AddFileLineRange(filename string, firstLineIdx, lastLineI
return err
}
info.mode = PART
- info.includedLineIndices = utils.UnionInt(info.includedLineIndices, getIndicesForRange(firstLineIdx, lastLineIdx))
+ info.includedLineIndices = lo.Union(info.includedLineIndices, getIndicesForRange(firstLineIdx, lastLineIdx))
return nil
}
@@ -151,7 +151,7 @@ func (p *PatchManager) RemoveFileLineRange(filename string, firstLineIdx, lastLi
return err
}
info.mode = PART
- info.includedLineIndices = utils.DifferenceInt(info.includedLineIndices, getIndicesForRange(firstLineIdx, lastLineIdx))
+ info.includedLineIndices, _ = lo.Difference(info.includedLineIndices, getIndicesForRange(firstLineIdx, lastLineIdx))
if len(info.includedLineIndices) == 0 {
p.removeFile(info)
}
diff --git a/pkg/commands/patch/patch_parser.go b/pkg/commands/patch/patch_parser.go
index c2be120c9..3810d8a29 100644
--- a/pkg/commands/patch/patch_parser.go
+++ b/pkg/commands/patch/patch_parser.go
@@ -7,6 +7,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
"github.com/sirupsen/logrus"
)
@@ -186,7 +187,7 @@ func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndic
renderedLines := make([]string, len(p.PatchLines))
for index, patchLine := range p.PatchLines {
selected := index >= firstLineIndex && index <= lastLineIndex
- included := utils.IncludesInt(incLineIndices, index)
+ included := lo.Contains(incLineIndices, index)
renderedLines[index] = patchLine.render(selected, included)
}
result := strings.Join(renderedLines, "\n")