Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/commands/git_commands/commit_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
var tags []string

if extraInfo != "" {
extraInfoFields := strings.Split(extraInfo, ",")
for _, extraInfoField := range extraInfoFields {
extraInfoFields := strings.SplitSeq(extraInfo, ",")
for extraInfoField := range extraInfoFields {
extraInfoField = strings.TrimSpace(extraInfoField)
re := regexp.MustCompile(`tag: (.+)`)
tagMatch := re.FindStringSubmatch(extraInfoField)
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (self *FlowCommands) FinishCmdObj(branchName string) (*oscommands.CmdObj, e
suffix := strings.Replace(branchName, prefix, "", 1)

branchType := ""
for _, line := range strings.Split(strings.TrimSpace(prefixes), "\n") {
for line := range strings.SplitSeq(strings.TrimSpace(prefixes), "\n") {
if strings.HasPrefix(line, "gitflow.prefix.") && strings.HasSuffix(line, prefix) {

regex := regexp.MustCompile("gitflow.prefix.([^ ]*) .*")
Expand Down
4 changes: 2 additions & 2 deletions pkg/fakes/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type FakeFieldLogger struct {
*logrus.Entry
}

func (self *FakeFieldLogger) Error(args ...interface{}) {
func (self *FakeFieldLogger) Error(args ...any) {
if len(args) != 1 {
panic("Expected exactly one argument to FakeFieldLogger.Error")
}
Expand All @@ -29,7 +29,7 @@ func (self *FakeFieldLogger) Error(args ...interface{}) {
}
}

func (self *FakeFieldLogger) Errorf(format string, args ...interface{}) {
func (self *FakeFieldLogger) Errorf(format string, args ...any) {
msg := fmt.Sprintf(format, args...)
self.loggedErrors = append(self.loggedErrors, msg)
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/gui/controllers/helpers/confirmation_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ func (self *ConfirmationHelper) getPopupPanelWidth() int {
panelWidth := 4 * width / 7
minWidth := 80
if panelWidth < minWidth {
if width-2 < minWidth {
panelWidth = width - 2
} else {
panelWidth = minWidth
}
panelWidth = min(width-2, minWidth)
}

return panelWidth
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/controllers/helpers/fixup_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) ([]string,
if err != nil {
return err
}
blameLines := strings.Split(strings.TrimSuffix(blameOutput, "\n"), "\n")
for _, line := range blameLines {
blameLines := strings.SplitSeq(strings.TrimSuffix(blameOutput, "\n"), "\n")
for line := range blameLines {
hashChan <- strings.Split(line, " ")[0]
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/controllers/helpers/repos_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (self *ReposHelper) getCurrentBranch(path string) string {
content := strings.TrimSpace(string(headFile))
refsPrefix := "ref: refs/heads/"
var branchDisplay string
if strings.HasPrefix(content, refsPrefix) {
if bareName, ok := strings.CutPrefix(content, refsPrefix); ok {
// is a branch
branchDisplay = strings.TrimPrefix(content, refsPrefix)
branchDisplay = bareName
} else {
// detached HEAD state, displaying short hash
branchDisplay = utils.ShortHash(content)
Expand Down
5 changes: 2 additions & 3 deletions pkg/gui/controllers/helpers/window_arrangement_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helpers

import (
"fmt"
mapsPkg "maps"
"math"
"strings"

Expand Down Expand Up @@ -194,9 +195,7 @@ func mainPanelChildren(args WindowArrangementArgs) []*boxlayout.Box {
func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
result := map[K]V{}
for _, currMap := range maps {
for key, value := range currMap {
result[key] = value
}
mapsPkg.Copy(result, currMap)
}

return result
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,8 @@ func isFixupCommit(subject string) (string, bool) {
prefixes := []string{"fixup! ", "squash! ", "amend! "}
trimPrefix := func(s string) (string, bool) {
for _, prefix := range prefixes {
if strings.HasPrefix(s, prefix) {
return strings.TrimPrefix(s, prefix), true
if trimmedSubject, ok := strings.CutPrefix(s, prefix); ok {
return trimmedSubject, true
}
}
return s, false
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/presentation/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func TestRenderCommitGraph(t *testing.T) {
lines := RenderCommitGraph(commits, hashPool.Add("blah"), getStyle)

trimmedExpectedOutput := ""
for _, line := range strings.Split(strings.TrimPrefix(test.expectedOutput, "\n"), "\n") {
for line := range strings.SplitSeq(strings.TrimPrefix(test.expectedOutput, "\n"), "\n") {
trimmedExpectedOutput += strings.TrimSpace(line) + "\n"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/services/custom_commands/menu_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (self *MenuGenerator) call(commandOutput, filter, valueFormat, labelFormat
}

menuItems := []*commandMenuItem{}
for _, line := range strings.Split(commandOutput, "\n") {
for line := range strings.SplitSeq(commandOutput, "\n") {
if line == "" {
continue
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/gui/style/text_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type TextStyle struct {
}

type Sprinter interface {
Sprint(a ...interface{}) string
Sprintf(format string, a ...interface{}) string
Sprint(a ...any) string
Sprintf(format string, a ...any) string
}

func New() TextStyle {
Expand All @@ -46,11 +46,11 @@ func New() TextStyle {
return s
}

func (b TextStyle) Sprint(a ...interface{}) string {
func (b TextStyle) Sprint(a ...any) string {
return b.Style.Sprint(a...)
}

func (b TextStyle) Sprintf(format string, a ...interface{}) string {
func (b TextStyle) Sprintf(format string, a ...any) string {
return b.Style.Sprintf(format, a...)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/types/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/style"
)

type Key interface{} // FIXME: find out how to get `gocui.Key | rune`
type Key any // FIXME: find out how to get `gocui.Key | rune`

// Binding - a keybinding mapping a key and modifier to a handler. The keypress
// is only handled if the given view has focus, or handled globally if the view
Expand Down
11 changes: 4 additions & 7 deletions pkg/gui/view_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ func (gui *Gui) linesToReadFromCmdTask(v *gocui.View) tasks.LinesToRead {
// scrollbar go to its minimum height, so that the scrollbar thumb doesn't
// change size as you scroll down.
minScrollbarHeight := 1
linesToReadForAccurateScrollbar := height*(height-1)/minScrollbarHeight + oy

// However, cap it at some arbitrary max limit, so that we don't get
// performance problems for huge monitors or tiny font sizes
if linesToReadForAccurateScrollbar > 5000 {
linesToReadForAccurateScrollbar = 5000
}
linesToReadForAccurateScrollbar := min(
// However, cap it at some arbitrary max limit, so that we don't get
// performance problems for huge monitors or tiny font sizes
height*(height-1)/minScrollbarHeight+oy, 5000)

return tasks.LinesToRead{
Total: linesToReadForAccurateScrollbar,
Expand Down
7 changes: 3 additions & 4 deletions pkg/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/fs"
"slices"
"strings"

"dario.cat/mergo"
Expand Down Expand Up @@ -37,10 +38,8 @@ func NewTranslationSetFromConfig(log *logrus.Entry, configLanguage string) (*Tra
return EnglishTranslationSet(), nil
}

for _, key := range languageCodes {
if key == configLanguage {
return newTranslationSet(log, configLanguage)
}
if slices.Contains(languageCodes, configLanguage) {
return newTranslationSet(log, configLanguage)
}

// Configuring a language that we don't have a translation for *is* an
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/components/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type RunTestArgs struct {
Tests []*IntegrationTest
Logf func(format string, formatArgs ...interface{})
Logf func(format string, formatArgs ...any)
RunCmd func(cmd *exec.Cmd) (int, error)
TestWrapper func(test *IntegrationTest, f func() error)
Sandbox bool
Expand Down
2 changes: 1 addition & 1 deletion pkg/jsonschema/generate_config_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func setComment(yamlNode *yaml.Node, description string) {
"\n")
}

func (n *Node) MarshalYAML() (interface{}, error) {
func (n *Node) MarshalYAML() (any, error) {
node := yaml.Node{
Kind: yaml.MappingNode,
}
Expand Down
12 changes: 4 additions & 8 deletions pkg/tasks/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,10 @@ func TestNewCmdTask(t *testing.T) {

fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
wg.Go(func() {
time.Sleep(100 * time.Millisecond)
close(stop)
wg.Done()
}()
})
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})

wg.Wait()
Expand Down Expand Up @@ -252,12 +250,10 @@ func TestNewCmdTaskRefresh(t *testing.T) {

fn := manager.NewCmdTask(start, "", s.linesToRead, func() {})
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
wg.Go(func() {
time.Sleep(100 * time.Millisecond)
close(stop)
wg.Done()
}()
})
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})

wg.Wait()
Expand Down
6 changes: 2 additions & 4 deletions pkg/utils/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ func PrevIntInCycle(sl []int, current int) int {

func StringArraysOverlap(strArrA []string, strArrB []string) bool {
for _, first := range strArrA {
for _, second := range strArrB {
if first == second {
return true
}
if slices.Contains(strArrB, first) {
return true
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"text/template"
)

func ResolveTemplate(templateStr string, object interface{}, funcs template.FuncMap) (string, error) {
func ResolveTemplate(templateStr string, object any, funcs template.FuncMap) (string, error) {
tmpl, err := template.New("template").Funcs(funcs).Option("missingkey=error").Parse(templateStr)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func SortRange(x int, y int) (int, int) {
return y, x
}

func AsJson(i interface{}) string {
func AsJson(i any) string {
bytes, _ := json.MarshalIndent(i, "", " ")
return string(bytes)
}
Expand Down