Skip to content

skip dirs without go files early: improve logs and save time #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2018
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
16 changes: 16 additions & 0 deletions pkg/fsutils/path_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,21 @@ func (pr PathResolver) Resolve(paths ...string) (*PathResolveResult, error) {
state.addFile(path)
}

state.excludeDirsWithoutGoFiles()

return state.toResult(), nil
}

func (s *pathResolveState) excludeDirsWithoutGoFiles() {
dirToFiles := map[string]bool{}
for f := range s.files {
dir := filepath.Dir(f)
dirToFiles[dir] = true
}

for dir := range s.dirs {
if !dirToFiles[dir] { // no go files in this dir
delete(s.dirs, dir)
}
}
}
52 changes: 31 additions & 21 deletions pkg/fsutils/path_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,27 @@ func TestPathResolverCommonCases(t *testing.T) {
{
name: "empty root recursively",
resolve: []string{"./..."},
expDirs: []string{"."},
},
{
name: "empty root",
resolve: []string{"./"},
expDirs: []string{"."},
},
{
name: "vendor is excluded recursively",
prepare: []string{"vendor/a/"},
prepare: []string{"vendor/a/b.go"},
resolve: []string{"./..."},
expDirs: []string{"."},
},
{
name: "vendor is excluded",
prepare: []string{"vendor/"},
prepare: []string{"vendor/a.go"},
resolve: []string{"./..."},
expDirs: []string{"."},
},
{
name: "vendor implicitely resolved",
prepare: []string{"vendor/"},
resolve: []string{"./vendor"},
expDirs: []string{"vendor"},
name: "vendor implicitely resolved",
prepare: []string{"vendor/a.go"},
resolve: []string{"./vendor"},
expDirs: []string{"vendor"},
expFiles: []string{"vendor/a.go"},
},
{
name: "extensions filter recursively",
Expand All @@ -125,7 +122,7 @@ func TestPathResolverCommonCases(t *testing.T) {
},
{
name: "one level dirs exclusion",
prepare: []string{"a/b/", "a/c.go"},
prepare: []string{"a/b/d.go", "a/c.go"},
resolve: []string{"./a"},
expDirs: []string{"a"},
expFiles: []string{"a/c.go"},
Expand All @@ -138,45 +135,58 @@ func TestPathResolverCommonCases(t *testing.T) {
expFiles: []string{"a/b/c.go", "a/d.txt"},
},
{
name: ".* is always ignored",
name: ".* dotfiles are always ignored",
prepare: []string{".git/a.go", ".circleci/b.go"},
resolve: []string{"./..."},
expDirs: []string{"."},
},
{
name: "exclude dirs on any depth level",
prepare: []string{"ok/.git/a.go"},
resolve: []string{"./..."},
expDirs: []string{".", "ok"},
name: "exclude dirs on any depth level",
prepare: []string{"ok/.git/a.go", "ok/b.go"},
resolve: []string{"./..."},
expDirs: []string{"ok"},
expFiles: []string{"ok/b.go"},
},
{
name: "ignore _*",
prepare: []string{"_any/a.go"},
resolve: []string{"./..."},
expDirs: []string{"."},
},
{
name: "include tests",
prepare: []string{"a/b.go", "a/b_test.go"},
resolve: []string{"./..."},
expDirs: []string{".", "a"},
expDirs: []string{"a"},
expFiles: []string{"a/b.go", "a/b_test.go"},
includeTests: true,
},
{
name: "exclude tests",
prepare: []string{"a/b.go", "a/b_test.go"},
resolve: []string{"./..."},
expDirs: []string{".", "a"},
expDirs: []string{"a"},
expFiles: []string{"a/b.go"},
},
{
name: "exclude tests except explicitly set",
prepare: []string{"a/b.go", "a/b_test.go", "a/c_test.go"},
resolve: []string{"./...", "a/c_test.go"},
expDirs: []string{".", "a"},
expDirs: []string{"a"},
expFiles: []string{"a/b.go", "a/c_test.go"},
},
{
name: "exclude dirs with no go files",
prepare: []string{"a/b.txt", "a/c/d.go"},
resolve: []string{"./..."},
expDirs: []string{"a/c"},
expFiles: []string{"a/c/d.go"},
},
{
name: "exclude dirs with no go files with root dir",
prepare: []string{"a/b.txt", "a/c/d.go", "e.go"},
resolve: []string{"./..."},
expDirs: []string{".", "a/c"},
expFiles: []string{"a/c/d.go", "e.go"},
},
}

for _, tc := range testCases {
Expand Down