Waiting for coverage results... If this message persists check your coverage integration. Go to coverage settings

Fix and speed up the file list for the "Enter path to filter by" feature
Closed

stefanhaller merged fix-and-speed-up-file-suggestions into master

#5056

Last updated

Up to quality standards.

vendor/github.com/gobwas/glob/compiler

vendor/github.com/gobwas/glob/syntax/ast

vendor/github.com/gobwas/glob/syntax/lexer

vendor/github.com/gobwas/glob/syntax

vendor/github.com/gobwas/glob/util/runes

vendor/github.com/gobwas/glob/util/strings

vendor/github.com/jesseduffield/minimal/gitignore

pkg/gui/controllers/helpers

vendor/github.com/gobwas/glob/.gitignore

vendor/github.com/gobwas/glob/.travis.yml

vendor/github.com/gobwas/glob/LICENSE

vendor/github.com/gobwas/glob/bench.sh

vendor/github.com/gobwas/glob/compiler/compiler.go

vendor/github.com/gobwas/glob/glob.go

vendor/github.com/gobwas/glob/match/any.go

vendor/github.com/gobwas/glob/match/any_of.go

vendor/github.com/gobwas/glob/match/btree.go

vendor/github.com/gobwas/glob/match/contains.go

vendor/github.com/gobwas/glob/match/every_of.go

vendor/github.com/gobwas/glob/match/list.go

vendor/github.com/gobwas/glob/match/match.go

vendor/github.com/gobwas/glob/match/max.go

vendor/github.com/gobwas/glob/match/min.go

vendor/github.com/gobwas/glob/match/nothing.go

vendor/github.com/gobwas/glob/match/prefix.go

vendor/github.com/gobwas/glob/match/prefix_any.go

vendor/github.com/gobwas/glob/match/prefix_suffix.go

vendor/github.com/gobwas/glob/match/range.go

vendor/github.com/gobwas/glob/match/row.go

vendor/github.com/gobwas/glob/match/segments.go

vendor/github.com/gobwas/glob/match/single.go

vendor/github.com/gobwas/glob/match/suffix.go

vendor/github.com/gobwas/glob/match/suffix_any.go

vendor/github.com/gobwas/glob/match/super.go

vendor/github.com/gobwas/glob/match/text.go

vendor/github.com/gobwas/glob/readme.md

vendor/github.com/gobwas/glob/syntax/ast/ast.go

vendor/github.com/gobwas/glob/syntax/ast/parser.go

vendor/github.com/gobwas/glob/syntax/lexer/lexer.go

vendor/github.com/gobwas/glob/syntax/lexer/token.go

vendor/github.com/gobwas/glob/syntax/syntax.go

vendor/github.com/gobwas/glob/util/runes/runes.go

vendor/github.com/gobwas/glob/util/strings/strings.go

vendor/github.com/jesseduffield/minimal/gitignore/LICENSE

vendor/github.com/jesseduffield/minimal/gitignore/gitignore.go

vendor/github.com/jesseduffield/minimal/gitignore/testgitignore

/go.mod

/go.sum

pkg/commands/git_commands/working_tree.go

Diff coverage

80 %

@@ -451,3 +451,19 @@ func (self *WorkingTreeCommands) MergeFileForObjectIDs(strategy string, oursID s

451 452return self.cmd.New(cmdArgs).RunWithOutput() 453}                
451 452return self.cmd.New(cmdArgs).RunWithOutput() 453} 454 455// Returns all tracked files in the repo (not in the working tree). The returned entries are 456// relative paths to the repo root, using '/' as the path separator on all platforms. 457// Does not really belong in WorkingTreeCommands, but it's close enough, and we don't seem to have a 458// better place for it right now. 459func (self *WorkingTreeCommands) AllRepoFiles() ([]string, error) { 
1 hits
460cmdArgs := NewGitCmd("ls-files").Arg("-z").ToArgv()
1 hits
461output, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
1 hits
462if err != nil {
1 hits
463return nil, err
Not covered
464}
Not covered
465if output == "" {
2 hits
466return []string{}, nil
1 hits
467}
1 hits
468return strings.Split(strings.TrimRight(output, "\x00"), "\x00"), nil
1 hits
469}

pkg/commands/git_commands/working_tree_test.go

pkg/gui/controllers/helpers/suggestions_helper.go

Diff coverage

100 %

@@ -2,15 +2,14 @@ package helpers

2 3import ( 4"fmt" 5"os" 6"strings" 7  8"github.com/jesseduffield/gocui" 9"github.com/jesseduffield/lazygit/pkg/commands/models" 10"github.com/jesseduffield/lazygit/pkg/gui/presentation" 11"github.com/jesseduffield/lazygit/pkg/gui/types" 12"github.com/jesseduffield/lazygit/pkg/utils" 13"github.com/jesseduffield/minimal/gitignore" 14"github.com/samber/lo" 15"golang.org/x/exp/slices" 16"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
2 3import ( 4"fmt"  5"strings" 6 7"github.com/jesseduffield/generics/set" 8"github.com/jesseduffield/gocui" 9"github.com/jesseduffield/lazygit/pkg/commands/models" 10"github.com/jesseduffield/lazygit/pkg/gui/presentation" 11"github.com/jesseduffield/lazygit/pkg/gui/types" 12"github.com/jesseduffield/lazygit/pkg/utils"  13"github.com/samber/lo" 14"golang.org/x/exp/slices" 15"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"

@@ -92,22 +91,28 @@ func (self *SuggestionsHelper) GetBranchNameSuggestionsFunc() func(string) []*ty

92func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*types.Suggestion { 93_ = self.c.WithWaitingStatus(self.c.Tr.LoadingFileSuggestions, func(gocui.Task) error { 94trie := patricia.NewTrie() 95// load every non-gitignored file in the repo 96ignore, err := gitignore.FromGit()  97if err != nil { 98return err 99} 100 101err = ignore.Walk(".", 102func(path string, info os.FileInfo, err error) error { 103if err != nil { 104return err 105} 106if path != "." { 107trie.Insert(patricia.Prefix(path), path)    108} 109return nil 110})   111 112// cache the trie for future use 113self.c.Model().FilesTrie = trie
91func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*types.Suggestion { 92_ = self.c.WithWaitingStatus(self.c.Tr.LoadingFileSuggestions, func(gocui.Task) error { 93trie := patricia.NewTrie() 94 
1 hits
95// load every file in the repo
1 hits
96files, err := self.c.Git().WorkingTree.AllRepoFiles()
1 hits
97if err != nil { 98return err 99} 100 101seen := set.New[string]()
1 hits
102for _, file := range files {
2 hits
103// For every file we also want to add its parent directories, but only once.
1 hits
104for i := range len(file) {
2 hits
105if file[i] == '/' {
2 hits
106dir := file[:i]
1 hits
107if !seen.Includes(dir) {
2 hits
108trie.Insert(patricia.Prefix(dir), dir)
1 hits
109seen.Add(dir)
1 hits
110}
1 hits
111} 112} 113 114trie.Insert(patricia.Prefix(file), file)
1 hits
115} 116 117// cache the trie for future use 118self.c.Model().FilesTrie = trie

vendor/modules.txt