summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-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
-rw-r--r--pkg/gui/controllers/global_controller.go8
-rw-r--r--pkg/gui/controllers/helpers/cherry_pick_helper.go36
-rw-r--r--pkg/gui/filetree/collapsed_paths.go32
-rw-r--r--pkg/gui/filetree/commit_file_node.go8
-rw-r--r--pkg/gui/filetree/commit_file_tree.go6
-rw-r--r--pkg/gui/filetree/file_node.go8
-rw-r--r--pkg/gui/filetree/file_tree.go8
-rw-r--r--pkg/gui/filetree/inode.go18
-rw-r--r--pkg/gui/list_context_config.go6
-rw-r--r--pkg/gui/options_menu_panel.go18
-rw-r--r--pkg/gui/patch_building_panel.go6
-rw-r--r--pkg/gui/presentation/commits.go13
-rw-r--r--pkg/gui/presentation/commits_test.go5
-rw-r--r--pkg/gui/presentation/files.go2
-rw-r--r--pkg/gui/presentation/reflog_commits.go5
-rw-r--r--pkg/gui/refresh.go27
-rw-r--r--pkg/utils/slice.go83
-rw-r--r--pkg/utils/slice_test.go76
24 files changed, 123 insertions, 275 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")
diff --git a/pkg/gui/controllers/global_controller.go b/pkg/gui/controllers/global_controller.go
index 487c1e10b..c45e98d85 100644
--- a/pkg/gui/controllers/global_controller.go
+++ b/pkg/gui/controllers/global_controller.go
@@ -1,9 +1,11 @@
package controllers
import (
+ "github.com/jesseduffield/generics/list"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
)
type GlobalController struct {
@@ -36,9 +38,7 @@ func (self *GlobalController) customCommand() error {
FindSuggestionsFunc: self.GetCustomCommandsHistorySuggestionsFunc(),
HandleConfirm: func(command string) error {
self.c.GetAppState().CustomCommandsHistory = utils.Limit(
- utils.Uniq(
- append(self.c.GetAppState().CustomCommandsHistory, command),
- ),
+ lo.Uniq(append(self.c.GetAppState().CustomCommandsHistory, command)),
1000,
)
@@ -57,7 +57,7 @@ func (self *GlobalController) customCommand() error {
func (self *GlobalController) GetCustomCommandsHistorySuggestionsFunc() func(string) []*types.Suggestion {
// reversing so that we display the latest command first
- history := utils.Reverse(self.c.GetAppState().CustomCommandsHistory)
+ history := list.Reverse(self.c.GetAppState().CustomCommandsHistory)
return helpers.FuzzySearchFunc(history)
}
diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go
index badbf0dfe..e4a9b3e81 100644
--- a/pkg/gui/controllers/helpers/cherry_pick_helper.go
+++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go
@@ -1,11 +1,13 @@
package helpers
import (
+ "github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
"github.com/jesseduffield/lazygit/pkg/gui/types"
+ "github.com/samber/lo"
)
type CherryPickHelper struct {
@@ -63,13 +65,13 @@ func (self *CherryPickHelper) CopyRange(selectedIndex int, commitsList []*models
return err
}
- commitShaMap := self.CherryPickedCommitShaMap()
+ commitSet := self.CherryPickedCommitShaSet()
// find the last commit that is copied that's above our position
// if there are none, startIndex = 0
startIndex := 0
for index, commit := range commitsList[0:selectedIndex] {
- if commitShaMap[commit.Sha] {
+ if commitSet.Includes(commit.Sha) {
startIndex = index
}
}
@@ -105,25 +107,23 @@ func (self *CherryPickHelper) Reset() error {
return self.rerender()
}
-func (self *CherryPickHelper) CherryPickedCommitShaMap() map[string]bool {
- commitShaMap := map[string]bool{}
- for _, commit := range self.getData().CherryPickedCommits {
- commitShaMap[commit.Sha] = true
- }
- return commitShaMap
+func (self *CherryPickHelper) CherryPickedCommitShaSet() *set.Set[string] {
+ shas := lo.Map(self.getData().CherryPickedCommits, func(commit *models.Commit, _ int) string {
+ return commit.Sha
+ })
+ return set.NewFromSlice(shas)
}
func (self *CherryPickHelper) add(selectedCommit *models.Commit, commitsList []*models.Commit) {
- commitShaMap := self.CherryPickedCommitShaMap()
- commitShaMap[selectedCommit.Sha] = true
-
- newCommits := []*models.Commit{}
- for _, commit := range commitsList {
- if commitShaMap[commit.Sha] {
- // duplicating just the things we need to put in the rebase TODO list
- newCommits = append(newCommits, &models.Commit{Name: commit.Name, Sha: commit.Sha})
- }
- }
+ commitSet := self.CherryPickedCommitShaSet()
+ commitSet.Add(selectedCommit.Sha)
+
+ commitsInSet := lo.Filter(commitsList, func(commit *models.Commit, _ int) bool {
+ return commitSet.Includes(commit.Sha)
+ })
+ newCommits := lo.Map(commitsInSet, func(commit *models.Commit, _ int) *models.Commit {
+ return &models.Commit{Name: commit.Name, Sha: commit.Sha}
+ })
self.getData().CherryPickedCommits = newCommits
}
diff --git a/pkg/gui/filetree/collapsed_paths.go b/pkg/gui/filetree/collapsed_paths.go
index 02c0b4303..903999b37 100644
--- a/pkg/gui/filetree/collapsed_paths.go
+++ b/pkg/gui/filetree/collapsed_paths.go
@@ -1,20 +1,38 @@
package filetree
-type CollapsedPaths map[string]bool
+import "github.com/jesseduffield/generics/set"
-func (cp CollapsedPaths) ExpandToPath(path string) {
+type CollapsedPaths struct {
+ collapsedPaths *set.Set[string]
+}
+
+func NewCollapsedPaths() *CollapsedPaths {
+ return &CollapsedPaths{
+ collapsedPaths: set.New[string](),
+ }
+}
+
+func (self *CollapsedPaths) ExpandToPath(path string) {
// need every directory along the way
splitPath := split(path)
for i := range splitPath {
dir := join(splitPath[0 : i+1])
- cp[dir] = false
+ self.collapsedPaths.Remove(dir)
}
}
-func (cp CollapsedPaths) IsCollapsed(path string) bool {
- return cp[path]
+func (self *CollapsedPaths) IsCollapsed(path string) bool {
+ return self.collapsedPaths.Includes(path)
+}
+
+func (self *CollapsedPaths) Collapse(path string) {
+ self.collapsedPaths.Add(path)
}
-func (cp CollapsedPaths) ToggleCollapsed(path string) {
- cp[path] = !cp[path]
+func (self *CollapsedPaths) ToggleCollapsed(path string) {
+ if self.collapsedPaths.Includes(path) {
+ self.collapsedPaths.Remove(path)
+ } else {
+ self.collapsedPaths.Add(path)
+ }
}
diff --git a/pkg/gui/filetree/commit_file_node.go b/pkg/gui/filetree/commit_file_node.go
index a8f7d0a95..ac2057da5 100644
--- a/pkg/gui/filetree/commit_file_node.go
+++ b/pkg/gui/filetree/commit_file_node.go
@@ -100,7 +100,7 @@ func (s *CommitFileNode) EveryFile(test func(file *models.CommitFile) bool) bool
})
}
-func (n *CommitFileNode) Flatten(collapsedPaths map[string]bool) []*CommitFileNode {
+func (n *CommitFileNode) Flatten(collapsedPaths *CollapsedPaths) []*CommitFileNode {
results := flatten(n, collapsedPaths)
nodes := make([]*CommitFileNode, len(results))
for i, result := range results {
@@ -110,7 +110,7 @@ func (n *CommitFileNode) Flatten(collapsedPaths map[string]bool) []*CommitFileNo
return nodes
}
-func (node *CommitFileNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *CommitFileNode {
+func (node *CommitFileNode) GetNodeAtIndex(index int, collapsedPaths *CollapsedPaths) *CommitFileNode {
if node == nil {
return nil
}
@@ -124,11 +124,11 @@ func (node *CommitFileNode) GetNodeAtIndex(index int, collapsedPaths map[string]
return result.(*CommitFileNode)
}
-func (node *CommitFileNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) {
+func (node *CommitFileNode) GetIndexForPath(path string, collapsedPaths *CollapsedPaths) (int, bool) {
return getIndexForPath(node, path, collapsedPaths)
}
-func (node *CommitFileNode) Size(collapsedPaths map[string]bool) int {
+func (node *CommitFileNode) Size(collapsedPaths *CollapsedPaths) int {
if node == nil {
return 0
}
diff --git a/pkg/gui/filetree/commit_file_tree.go b/pkg/gui/filetree/commit_file_tree.go
index 055e273f3..e539c9dea 100644
--- a/pkg/gui/filetree/commit_file_tree.go
+++ b/pkg/gui/filetree/commit_file_tree.go
@@ -19,7 +19,7 @@ type CommitFileTree struct {
tree *CommitFileNode
showTree bool
log *logrus.Entry
- collapsedPaths CollapsedPaths
+ collapsedPaths *CollapsedPaths
}
var _ ICommitFileTree = &CommitFileTree{}
@@ -29,7 +29,7 @@ func NewCommitFileTree(getFiles func() []*models.CommitFile, log *logrus.Entry,
getFiles: getFiles,
log: log,
showTree: showTree,
- collapsedPaths: CollapsedPaths{},
+ collapsedPaths: NewCollapsedPaths(),
}
}
@@ -88,7 +88,7 @@ func (self *CommitFileTree) Tree() INode {
return self.tree
}
-func (self *CommitFileTree) CollapsedPaths() CollapsedPaths {
+func (self *CommitFileTree) CollapsedPaths() *CollapsedPaths {
return self.collapsedPaths
}
diff --git a/pkg/gui/filetree/file_node.go b/pkg/gui/filetree/file_node.go
index 841f723fc..e73504321 100644
--- a/pkg/gui/filetree/file_node.go
+++ b/pkg/gui/filetree/file_node.go
@@ -87,7 +87,7 @@ func (s *FileNode) Any(test func(node *FileNode) bool) bool {
})
}
-func (n *FileNode) Flatten(collapsedPaths map[string]bool) []*FileNode {
+func (n *FileNode) Flatten(collapsedPaths *CollapsedPaths) []*FileNode {
results := flatten(n, collapsedPaths)
nodes := make([]*FileNode, len(results))
for i, result := range results {
@@ -97,7 +97,7 @@ func (n *FileNode) Flatten(collapsedPaths map[string]bool) []*FileNode {
return nodes
}
-func (node *FileNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *FileNode {
+func (node *FileNode) GetNodeAtIndex(index int, collapsedPaths *CollapsedPaths) *FileNode {
if node == nil {
return nil
}
@@ -111,11 +111,11 @@ func (node *FileNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool)
return result.(*FileNode)
}
-func (node *FileNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) {
+func (node *FileNode) GetIndexForPath(path string, collapsedPaths *CollapsedPaths) (int, bool) {
return getIndexForPath(node, path, collapsedPaths)
}
-func (node *FileNode) Size(collapsedPaths map[string]bool) int {
+func (node *FileNode) Size(collapsedPaths *CollapsedPaths) int {
if node == nil {
return 0
}
diff --git a/pkg/gui/filetree/file_tree.go b/pkg/gui/filetree/file_tree.go
index 0d0524470..47d7f32f2 100644
--- a/pkg/gui/filetree/file_tree.go
+++ b/pkg/gui/filetree/file_tree.go
@@ -27,7 +27,7 @@ type ITree interface {
IsCollapsed(path string) bool
ToggleCollapsed(path string)
Tree() INode
- CollapsedPaths() CollapsedPaths
+ CollapsedPaths() *CollapsedPaths
}
type IFileTree interface {
@@ -48,7 +48,7 @@ type FileTree struct {
showTree bool
log *logrus.Entry
filter FileTreeDisplayFilter
- collapsedPaths CollapsedPaths
+ collapsedPaths *CollapsedPaths
}
func NewFileTree(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTree {
@@ -57,7 +57,7 @@ func NewFileTree(getFiles func() []*models.File, log *logrus.Entry, showTree boo
log: log,
showTree: showTree,
filter: DisplayAll,
- collapsedPaths: CollapsedPaths{},
+ collapsedPaths: NewCollapsedPaths(),
}
}
@@ -164,7 +164,7 @@ func (self *FileTree) Tree() INode {
return self.tree
}
-func (self *FileTree) CollapsedPaths() CollapsedPaths {
+func (self *FileTree) CollapsedPaths() *CollapsedPaths {
return self.collapsedPaths
}
diff --git a/pkg/gui/filetree/inode.go b/pkg/gui/filetree/inode.go
index 7d9035fe3..7c8b9fb75 100644
--- a/pkg/gui/filetree/inode.go
+++ b/pkg/gui/filetree/inode.go
@@ -90,11 +90,11 @@ func every(node INode, test func(INode) bool) bool {
return true
}
-func flatten(node INode, collapsedPaths map[string]bool) []INode {
+func flatten(node INode, collapsedPaths *CollapsedPaths) []INode {
result := []INode{}
result = append(result, node)
- if !collapsedPaths[node.GetPath()] {
+ if !collapsedPaths.IsCollapsed(node.GetPath()) {
for _, child := range node.GetChildren() {
result = append(result, flatten(child, collapsedPaths)...)
}
@@ -103,20 +103,20 @@ func flatten(node INode, collapsedPaths map[string]bool) []INode {
return result
}
-func getNodeAtIndex(node INode, index int, collapsedPaths map[string]bool) INode {
+func getNodeAtIndex(node INode, index int, collapsedPaths *CollapsedPaths) INode {
foundNode, _ := getNodeAtIndexAux(node, index, collapsedPaths)
return foundNode
}
-func getNodeAtIndexAux(node INode, index int, collapsedPaths map[string]bool) (INode, int) {
+func getNodeAtIndexAux(node INode, index int, collapsedPaths *CollapsedPaths) (INode, int) {
offset := 1
if index == 0 {
return node, offset
}
- if !collapsedPaths[node.GetPath()] {
+ if !collapsedPaths.IsCollapsed(node.GetPath()) {
for _, child := range node.GetChildren() {
foundNode, offsetChange := getNodeAtIndexAux(child, index-offset, collapsedPaths)
offset += offsetChange
@@ -129,14 +129,14 @@ func getNodeAtIndexAux(node INode, index int, collapsedPaths map[string]bool) (I
return nil, offset
}
-func getIndexForPath(node INode, path string, collapsedPaths map[string]bool) (int, bool) {
+func getIndexForPath(node INode, path string, collapsedPaths *CollapsedPaths) (int, bool) {
offset := 0
if node.GetPath() == path {
return offset, true
}
- if !collapsedPaths[node.GetPath()] {
+ if !collapsedPaths.IsCollapsed(node.GetPath()) {
for _, child := range node.GetChildren() {
offsetChange, found := getIndexForPath(child, path, collapsedPaths)
offset += offsetChange + 1
@@ -149,10 +149,10 @@ func getIndexForPath(node INode, path string, collapsedPaths map[string]bool) (i
return offset, false
}
-func size(node INode, collapsedPaths map[string]bool) int {
+func size(node INode, collapsedPaths *CollapsedPaths) int {
output := 1
- if !collapsedPaths[node.GetPath()] {
+ if !collapsedPaths.IsCollapsed(node.GetPath()) {
for _, child := range node.GetChildren() {
output += size(child, collapsedPaths)
}
diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go
index 010a2f0b1..dcea5a936 100644
--- a/pkg/gui/list_context_config.go
+++ b/pkg/gui/list_context_config.go
@@ -123,7 +123,7 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext {
return presentation.GetCommitListDisplayStrings(
gui.State.Model.Commits,
gui.State.ScreenMode != SCREEN_NORMAL,
- gui.helpers.CherryPick.CherryPickedCommitShaMap(),
+ gui.helpers.CherryPick.CherryPickedCommitShaSet(),
gui.State.Modes.Diffing.Ref,
gui.c.UserConfig.Git.ParseEmoji,
selectedCommitSha,
@@ -155,7 +155,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
return presentation.GetCommitListDisplayStrings(
gui.State.Model.SubCommits,
gui.State.ScreenMode != SCREEN_NORMAL,
- gui.helpers.CherryPick.CherryPickedCommitShaMap(),
+ gui.helpers.CherryPick.CherryPickedCommitShaSet(),
gui.State.Modes.Diffing.Ref,
gui.c.UserConfig.Git.ParseEmoji,
selectedCommitSha,
@@ -199,7 +199,7 @@ func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext {
return presentation.GetReflogCommitListDisplayStrings(
gui.State.Model.FilteredReflogCommits,
gui.State.ScreenMode != SCREEN_NORMAL,
- gui.helpers.CherryPick.CherryPickedCommitShaMap(),
+ gui.helpers.CherryPick.CherryPickedCommitShaSet(),
gui.State.Modes.Diffing.Ref,
gui.c.UserConfig.Git.ParseEmoji,
)
diff --git a/pkg/gui/options_menu_panel.go b/pkg/gui/options_menu_panel.go
index 0073bb041..54f08ed50 100644
--- a/pkg/gui/options_menu_panel.go
+++ b/pkg/gui/options_menu_panel.go
@@ -7,7 +7,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
- "github.com/jesseduffield/lazygit/pkg/utils"
+ "github.com/samber/lo"
)
func (gui *Gui) getBindings(context types.Context) []*types.Binding {
@@ -26,7 +26,7 @@ func (gui *Gui) getBindings(context types.Context) []*types.Binding {
bindingsGlobal = append(bindingsGlobal, binding)
} else if binding.Tag == "navigation" {
bindingsNavigation = append(bindingsNavigation, binding)
- } else if utils.IncludesString(binding.Contexts, string(context.GetKey())) {
+ } else if lo.Contains(binding.Contexts, string(context.GetKey())) {
bindingsPanel = append(bindingsPanel, binding)
}
}
@@ -45,17 +45,9 @@ func (gui *Gui) getBindings(context types.Context) []*types.Binding {
// We shouldn't really need to do this. We should define alternative keys for the same
// handler in the keybinding struct.
func uniqueBindings(bindings []*types.Binding) []*types.Binding {
- keys := make(map[string]bool)
- result := make([]*types.Binding, 0)
-
- for _, binding := range bindings {
- if _, ok := keys[binding.Description]; !ok {
- keys[binding.Description] = true
- result = append(result, binding)
- }
- }
-
- return result
+ return lo.UniqBy(bindings, func(binding *types.Binding) string {
+ return binding.Description
+ })
}
func (gui *Gui) displayDescription(binding *types.Binding) string {
diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go
index e734433c4..cae6167a4 100644
--- a/pkg/gui/patch_building_panel.go
+++ b/pkg/gui/patch_building_panel.go
@@ -1,8 +1,6 @@
package gui
-import (
- "github.com/jesseduffield/lazygit/pkg/utils"
-)
+import "github.com/samber/lo"
func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error {
if !gui.git.Patch.PatchManager.Active() {
@@ -68,7 +66,7 @@ func (gui *Gui) handleToggleSelectionForPatch() error {
if err != nil {
return err
}
- currentLineIsStaged := utils.IncludesInt(includedLineIndices, state.GetSelectedLineIdx())
+ currentLineIsStaged := lo.Contains(includedLineIndices, state.GetSelectedLineIdx())
if currentLineIsStaged {
toggleFunc = gui.git.Patch.PatchManager.RemoveFileLineRange
}
diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go
index 2d5262e89..7ec4e78af 100644
--- a/pkg/gui/presentation/commits.go
+++ b/pkg/gui/presentation/commits.go
@@ -4,6 +4,7 @@ import (
"strings"
"sync"
+ "github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/authors"
@@ -32,7 +33,7 @@ type bisectBounds struct {
func GetCommitListDisplayStrings(
commits []*models.Commit,
fullDescription bool,
- cherryPickedCommitShaMap map[string]bool,
+ cherryPickedCommitShaSet *set.Set[string],
diffName string,
parseEmoji bool,
selectedCommitSha string,
@@ -94,7 +95,7 @@ func GetCommitListDisplayStrings(
bisectStatus = getBisectStatus(unfilteredIdx, commit.Sha, bisectInfo, bisectBounds)
lines = append(lines, displayCommit(
commit,
- cherryPickedCommitShaMap,
+ cherryPickedCommitShaSet,
diffName,
parseEmoji,
getGraphLine(unfilteredIdx),
@@ -237,7 +238,7 @@ func getBisectStatusText(bisectStatus BisectStatus, bisectInfo *git_commands.Bis
func displayCommit(
commit *models.Commit,
- cherryPickedCommitShaMap map[string]bool,
+ cherryPickedCommitShaSet *set.Set[string],
diffName string,
parseEmoji bool,
graphLine string,
@@ -245,7 +246,7 @@ func displayCommit(
bisectStatus BisectStatus,
bisectInfo *git_commands.BisectInfo,
) []string {
- shaColor := getShaColor(commit, diffName, cherryPickedCommitShaMap, bisectStatus, bisectInfo)
+ shaColor := getShaColor(commit, diffName, cherryPickedCommitShaSet, bisectStatus, bisectInfo)
bisectString := getBisectStatusText(bisectStatus, bisectInfo)
actionString := ""
@@ -313,7 +314,7 @@ func getBisectStatusColor(status BisectStatus) style.TextStyle {
func getShaColor(
commit *models.Commit,
diffName string,
- cherryPickedCommitShaMap map[string]bool,
+ cherryPickedCommitShaSet *set.Set[string],
bisectStatus Bisect