summaryrefslogtreecommitdiffstats
path: root/pkg/gui/refresh.go
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/gui/refresh.go
parentdde30fa104347ab9c01f82b7886864b473e6f51c (diff)
make more use of generics
Diffstat (limited to 'pkg/gui/refresh.go')
-rw-r--r--pkg/gui/refresh.go27
1 files changed, 10 insertions, 17 deletions
diff --git a/pkg/gui/refresh.go b/pkg/gui/refresh.go
index 2a47efc7a..5252d7ec9 100644
--- a/pkg/gui/refresh.go
+++ b/pkg/gui/refresh.go
@@ -5,6 +5,7 @@ import (
"strings"
"sync"
+ "github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
@@ -52,14 +53,6 @@ func getModeName(mode types.RefreshMode) string {
}
}
-func arrToMap(arr []types.RefreshableView) map[types.RefreshableView]bool {
- output := map[types.RefreshableView]bool{}
- for _, el := range arr {
- output[el] = true
- }
- return output
-}
-
func (gui *Gui) Refresh(options types.RefreshOptions) error {
if options.Scope == nil {
gui.c.Log.Infof(
@@ -77,9 +70,9 @@ func (gui *Gui) Refresh(options types.RefreshOptions) error {
wg := sync.WaitGroup{}
f := func() {
- var scopeMap map[types.RefreshableView]bool
+ var scopeSet *set.Set[types.RefreshableView]
if len(options.Scope) == 0 {
- scopeMap = arrToMap([]types.RefreshableView{
+ scopeSet = set.NewFromSlice([]types.RefreshableView{
types.COMMITS,
types.BRANCHES,
types.FILES,
@@ -91,7 +84,7 @@ func (gui *Gui) Refresh(options types.RefreshOptions) error {
types.BISECT_INFO,
})
} else {
- scopeMap = arrToMap(options.Scope)
+ scopeSet = set.NewFromSlice(options.Scope)
}
refresh := func(f func()) {
@@ -106,27 +99,27 @@ func (gui *Gui) Refresh(options types.RefreshOptions) error {
}()
}
- if scopeMap[types.COMMITS] || scopeMap[types.BRANCHES] || scopeMap[types.REFLOG] || scopeMap[types.BISECT_INFO] {
+ if scopeSet.Includes(types.COMMITS) || scopeSet.Includes(types.BRANCHES) || scopeSet.Includes(types.REFLOG) || scopeSet.Includes(types.BISECT_INFO) {
refresh(gui.refreshCommits)
- } else if scopeMap[types.REBASE_COMMITS] {
+ } else if scopeSet.Includes(types.REBASE_COMMITS) {
// the above block handles rebase commits so we only need to call this one
// if we've asked specifically for rebase commits and not those other things
refresh(func() { _ = gui.refreshRebaseCommits() })
}
- if scopeMap[types.FILES] || scopeMap[types.SUBMODULES] {
+ if scopeSet.Includes(types.FILES) || scopeSet.Includes(types.SUBMODULES) {
refresh(func() { _ = gui.refreshFilesAndSubmodules() })
}
- if scopeMap[types.STASH] {
+ if scopeSet.Includes(types.STASH) {
refresh(func() { _ = gui.refreshStashEntries() })
}
- if scopeMap[types.TAGS] {
+ if scopeSet.Includes(types.TAGS) {
refresh(func() { _ = gui.refreshTags() })
}
- if scopeMap[types.REMOTES] {
+ if scopeSet.Includes(types.REMOTES) {
refresh(func() { _ = gui.refreshRemotes() })
}