mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-07 13:42:01 +02:00
would you believe that I'm adding even more generics
This commit is contained in:
parent
1b75ed3740
commit
94a53484a1
2
go.mod
2
go.mod
@ -14,7 +14,7 @@ require (
|
|||||||
github.com/gookit/color v1.4.2
|
github.com/gookit/color v1.4.2
|
||||||
github.com/imdario/mergo v0.3.11
|
github.com/imdario/mergo v0.3.11
|
||||||
github.com/integrii/flaggy v1.4.0
|
github.com/integrii/flaggy v1.4.0
|
||||||
github.com/jesseduffield/generics v0.0.0-20220319080325-a60171f800d5
|
github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677
|
||||||
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
|
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
|
||||||
github.com/jesseduffield/gocui v0.3.1-0.20220227022729-69f0c798eec8
|
github.com/jesseduffield/gocui v0.3.1-0.20220227022729-69f0c798eec8
|
||||||
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
|
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
|
||||||
|
4
go.sum
4
go.sum
@ -66,8 +66,8 @@ github.com/integrii/flaggy v1.4.0 h1:A1x7SYx4jqu5NSrY14z8Z+0UyX2S5ygfJJrfolWR3zM
|
|||||||
github.com/integrii/flaggy v1.4.0/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI=
|
github.com/integrii/flaggy v1.4.0/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||||
github.com/jesseduffield/generics v0.0.0-20220319080325-a60171f800d5 h1:mZf9Ezkd4Thuw2tj5naFeoUbHkbNiD38LQFokUGSbtQ=
|
github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677 h1:GoP06WWOE4AvTkAavXkF40nhYsg2hI09uVLDIuxzZYI=
|
||||||
github.com/jesseduffield/generics v0.0.0-20220319080325-a60171f800d5/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
|
github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
|
||||||
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg=
|
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg=
|
||||||
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
|
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
|
||||||
github.com/jesseduffield/gocui v0.3.1-0.20220227022729-69f0c798eec8 h1:9N08i5kjvOfkzMj6THmIM110wPTQLdVYEOHMHT2DFiI=
|
github.com/jesseduffield/gocui v0.3.1-0.20220227022729-69f0c798eec8 h1:9N08i5kjvOfkzMj6THmIM110wPTQLdVYEOHMHT2DFiI=
|
||||||
|
@ -111,10 +111,10 @@ func (self *HostingServiceMgr) getCandidateServiceDomains() []ServiceDomain {
|
|||||||
|
|
||||||
serviceDefinition, ok := serviceDefinitionByProvider[provider]
|
serviceDefinition, ok := serviceDefinitionByProvider[provider]
|
||||||
if !ok {
|
if !ok {
|
||||||
providerNames := []string{}
|
providerNames := slices.Map(serviceDefinitions, func(serviceDefinition ServiceDefinition) string {
|
||||||
for _, serviceDefinition := range serviceDefinitions {
|
return serviceDefinition.provider
|
||||||
providerNames = append(providerNames, serviceDefinition.provider)
|
})
|
||||||
}
|
|
||||||
self.log.Errorf("Unknown git service type: '%s'. Expected one of %s", provider, strings.Join(providerNames, ", "))
|
self.log.Errorf("Unknown git service type: '%s'. Expected one of %s", provider, strings.Join(providerNames, ", "))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -307,6 +307,7 @@ func (self *CommitLoader) getInteractiveRebasingCommits() ([]*models.Commit, err
|
|||||||
|
|
||||||
commits := []*models.Commit{}
|
commits := []*models.Commit{}
|
||||||
lines := strings.Split(string(bytesContent), "\n")
|
lines := strings.Split(string(bytesContent), "\n")
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
if line == "" || line == "noop" {
|
if line == "" || line == "noop" {
|
||||||
return commits, nil
|
return commits, nil
|
||||||
@ -315,12 +316,12 @@ func (self *CommitLoader) getInteractiveRebasingCommits() ([]*models.Commit, err
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
splitLine := strings.Split(line, " ")
|
splitLine := strings.Split(line, " ")
|
||||||
commits = append([]*models.Commit{{
|
commits = slices.Prepend(commits, &models.Commit{
|
||||||
Sha: splitLine[1],
|
Sha: splitLine[1],
|
||||||
Name: strings.Join(splitLine[2:], " "),
|
Name: strings.Join(splitLine[2:], " "),
|
||||||
Status: "rebasing",
|
Status: "rebasing",
|
||||||
Action: splitLine[0],
|
Action: splitLine[0],
|
||||||
}}, commits...)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return commits, nil
|
return commits, nil
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"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/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
"github.com/samber/lo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RemoteLoader struct {
|
type RemoteLoader struct {
|
||||||
@ -43,12 +42,12 @@ func (self *RemoteLoader) GetRemotes() ([]*models.Remote, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// first step is to get our remotes from go-git
|
// first step is to get our remotes from go-git
|
||||||
remotes := lo.Map(goGitRemotes, func(goGitRemote *gogit.Remote, _ int) *models.Remote {
|
remotes := slices.Map(goGitRemotes, func(goGitRemote *gogit.Remote) *models.Remote {
|
||||||
remoteName := goGitRemote.Config().Name
|
remoteName := goGitRemote.Config().Name
|
||||||
|
|
||||||
re := regexp.MustCompile(fmt.Sprintf(`(?m)^\s*%s\/([\S]+)`, remoteName))
|
re := regexp.MustCompile(fmt.Sprintf(`(?m)^\s*%s\/([\S]+)`, remoteName))
|
||||||
matches := re.FindAllStringSubmatch(remoteBranchesStr, -1)
|
matches := re.FindAllStringSubmatch(remoteBranchesStr, -1)
|
||||||
branches := lo.Map(matches, func(match []string, _ int) *models.RemoteBranch {
|
branches := slices.Map(matches, func(match []string) *models.RemoteBranch {
|
||||||
return &models.RemoteBranch{
|
return &models.RemoteBranch{
|
||||||
Name: match[1],
|
Name: match[1],
|
||||||
RemoteName: remoteName,
|
RemoteName: remoteName,
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/generics/slices"
|
||||||
"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/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
@ -65,11 +66,9 @@ outer:
|
|||||||
|
|
||||||
func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
|
func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
|
||||||
rawString, _ := self.cmd.New("git stash list --pretty='%gs'").DontLog().RunWithOutput()
|
rawString, _ := self.cmd.New("git stash list --pretty='%gs'").DontLog().RunWithOutput()
|
||||||
stashEntries := []*models.StashEntry{}
|
return slices.MapWithIndex(utils.SplitLines(rawString), func(line string, index int) *models.StashEntry {
|
||||||
for i, line := range utils.SplitLines(rawString) {
|
return self.stashEntryFromLine(line, index)
|
||||||
stashEntries = append(stashEntries, self.stashEntryFromLine(line, i))
|
})
|
||||||
}
|
|
||||||
return stashEntries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StashLoader) stashEntryFromLine(line string, index int) *models.StashEntry {
|
func (c *StashLoader) stashEntryFromLine(line string, index int) *models.StashEntry {
|
||||||
|
@ -191,7 +191,7 @@ func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndic
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
renderedLines := lo.Map(p.PatchLines, func(patchLine *PatchLine, index int) string {
|
renderedLines := slices.MapWithIndex(p.PatchLines, func(patchLine *PatchLine, index int) string {
|
||||||
selected := index >= firstLineIndex && index <= lastLineIndex
|
selected := index >= firstLineIndex && index <= lastLineIndex
|
||||||
included := lo.Contains(incLineIndices, index)
|
included := lo.Contains(incLineIndices, index)
|
||||||
return patchLine.render(selected, included)
|
return patchLine.render(selected, included)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,13 +24,9 @@ func (m *statusManager) removeStatus(id int) {
|
|||||||
m.mutex.Lock()
|
m.mutex.Lock()
|
||||||
defer m.mutex.Unlock()
|
defer m.mutex.Unlock()
|
||||||
|
|
||||||
newStatuses := []appStatus{}
|
m.statuses = slices.Filter(m.statuses, func(status appStatus) bool {
|
||||||
for _, status := range m.statuses {
|
return status.id != id
|
||||||
if status.id != id {
|
})
|
||||||
newStatuses = append(newStatuses, status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.statuses = newStatuses
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *statusManager) addWaitingStatus(message string) int {
|
func (m *statusManager) addWaitingStatus(message string) int {
|
||||||
|
@ -14,14 +14,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) popupViewNames() []string {
|
func (gui *Gui) popupViewNames() []string {
|
||||||
result := []string{}
|
return slices.FilterThenMap(gui.State.Contexts.Flatten(),
|
||||||
for _, context := range gui.State.Contexts.Flatten() {
|
func(c types.Context) bool {
|
||||||
if context.GetKind() == types.PERSISTENT_POPUP || context.GetKind() == types.TEMPORARY_POPUP {
|
return c.GetKind() == types.PERSISTENT_POPUP || c.GetKind() == types.TEMPORARY_POPUP
|
||||||
result = append(result, context.GetViewName())
|
},
|
||||||
}
|
func(c types.Context) string {
|
||||||
}
|
return c.GetViewName()
|
||||||
|
},
|
||||||
return result
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) currentContextKeyIgnoringPopups() types.ContextKey {
|
func (gui *Gui) currentContextKeyIgnoringPopups() types.ContextKey {
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
"github.com/samber/lo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CherryPickHelper struct {
|
type CherryPickHelper struct {
|
||||||
@ -109,7 +108,7 @@ func (self *CherryPickHelper) Reset() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *CherryPickHelper) CherryPickedCommitShaSet() *set.Set[string] {
|
func (self *CherryPickHelper) CherryPickedCommitShaSet() *set.Set[string] {
|
||||||
shas := lo.Map(self.getData().CherryPickedCommits, func(commit *models.Commit, _ int) string {
|
shas := slices.Map(self.getData().CherryPickedCommits, func(commit *models.Commit) string {
|
||||||
return commit.Sha
|
return commit.Sha
|
||||||
})
|
})
|
||||||
return set.NewFromSlice(shas)
|
return set.NewFromSlice(shas)
|
||||||
|
@ -200,10 +200,7 @@ func getLeaves(node INode) []INode {
|
|||||||
return []INode{node}
|
return []INode{node}
|
||||||
}
|
}
|
||||||
|
|
||||||
output := []INode{}
|
return slices.FlatMap(node.GetChildren(), func(child INode) []INode {
|
||||||
for _, child := range node.GetChildren() {
|
return getLeaves(child)
|
||||||
output = append(output, getLeaves(child)...)
|
})
|
||||||
}
|
|
||||||
|
|
||||||
return output
|
|
||||||
}
|
}
|
||||||
|
@ -67,13 +67,10 @@ func GetPipeSets(commits []*models.Commit, getStyle func(c *models.Commit) style
|
|||||||
|
|
||||||
pipes := []*Pipe{{fromPos: 0, toPos: 0, fromSha: "START", toSha: commits[0].Sha, kind: STARTS, style: style.FgDefault}}
|
pipes := []*Pipe{{fromPos: 0, toPos: 0, fromSha: "START", toSha: commits[0].Sha, kind: STARTS, style: style.FgDefault}}
|
||||||
|
|
||||||
pipeSets := [][]*Pipe{}
|
return slices.Map(commits, func(commit *models.Commit) []*Pipe {
|
||||||
for _, commit := range commits {
|
|
||||||
pipes = getNextPipes(pipes, commit, getStyle)
|
pipes = getNextPipes(pipes, commit, getStyle)
|
||||||
pipeSets = append(pipeSets, pipes)
|
return pipes
|
||||||
}
|
})
|
||||||
|
|
||||||
return pipeSets
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitSha string) []string {
|
func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitSha string) []string {
|
||||||
@ -115,9 +112,9 @@ func RenderAux(pipeSets [][]*Pipe, commits []*models.Commit, selectedCommitSha s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *models.Commit) style.TextStyle) []*Pipe {
|
func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *models.Commit) style.TextStyle) []*Pipe {
|
||||||
maxPos := lo.Max(
|
maxPos := slices.MaxBy(prevPipes, func(pipe *Pipe) int {
|
||||||
slices.Map(prevPipes, func(pipe *Pipe) int { return pipe.toPos }),
|
return pipe.toPos
|
||||||
)
|
})
|
||||||
|
|
||||||
// a pipe that terminated in the previous line has no bearing on the current line
|
// a pipe that terminated in the previous line has no bearing on the current line
|
||||||
// so we'll filter those out
|
// so we'll filter those out
|
||||||
|
22
vendor/github.com/jesseduffield/generics/slices/slices.go
generated
vendored
22
vendor/github.com/jesseduffield/generics/slices/slices.go
generated
vendored
@ -37,6 +37,16 @@ func Map[T any, V any](slice []T, f func(T) V) []V {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Produces a new slice, leaves the input slice untouched.
|
||||||
|
func MapWithIndex[T any, V any](slice []T, f func(T, int) V) []V {
|
||||||
|
result := make([]V, 0, len(slice))
|
||||||
|
for i, value := range slice {
|
||||||
|
result = append(result, f(value, i))
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// Produces a new slice, leaves the input slice untouched.
|
// Produces a new slice, leaves the input slice untouched.
|
||||||
func FlatMap[T any, V any](slice []T, f func(T) []V) []V {
|
func FlatMap[T any, V any](slice []T, f func(T) []V) []V {
|
||||||
// impossible to know how long this slice will be in the end but the length
|
// impossible to know how long this slice will be in the end but the length
|
||||||
@ -74,6 +84,18 @@ func Filter[T any](slice []T, test func(T) bool) []T {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Produces a new slice, leaves the input slice untouched.
|
||||||
|
func FilterWithIndex[T any](slice []T, f func(T, int) bool) []T {
|
||||||
|
result := make([]T, 0, len(slice))
|
||||||
|
for i, value := range slice {
|
||||||
|
if f(value, i) {
|
||||||
|
result = append(result, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// Mutates original slice. Intended usage is to reassign the slice result to the input slice.
|
// Mutates original slice. Intended usage is to reassign the slice result to the input slice.
|
||||||
func FilterInPlace[T any](slice []T, test func(T) bool) []T {
|
func FilterInPlace[T any](slice []T, test func(T) bool) []T {
|
||||||
newLength := 0
|
newLength := 0
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -120,7 +120,7 @@ github.com/integrii/flaggy
|
|||||||
# github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99
|
# github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99
|
||||||
## explicit
|
## explicit
|
||||||
github.com/jbenet/go-context/io
|
github.com/jbenet/go-context/io
|
||||||
# github.com/jesseduffield/generics v0.0.0-20220319080325-a60171f800d5
|
# github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
github.com/jesseduffield/generics/maps
|
github.com/jesseduffield/generics/maps
|
||||||
github.com/jesseduffield/generics/set
|
github.com/jesseduffield/generics/set
|
||||||
|
Loading…
x
Reference in New Issue
Block a user