From 371418ca1169bd0916ac56075ca594ab1ae16d69 Mon Sep 17 00:00:00 2001 From: Chris Dueck Date: Mon, 9 May 2022 16:13:08 -0400 Subject: [PATCH 1/2] Ignored directories should not be included in import analysis --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index b2211eb..fada046 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,10 @@ func main() { return } + if isIgnored(importPath) { + return + } + pkg, err := buildContext.Import(importPath, repo, build.AllowBinary) if err, ok := err.(*build.NoGoError); err != nil && ok { return From 4ea4058a00670fa35f5d9d49ea13fe82ec64ffc3 Mon Sep 17 00:00:00 2001 From: Chris Dueck Date: Tue, 10 May 2022 09:38:11 -0400 Subject: [PATCH 2/2] Remove unnecessary intermediate data The `modifiedPackages` var is created only to later select the `ImportPath` field of each `Package`. Since the import paths are already stored in the `pkgSeen` map, it's an unnecessary intermediate. --- main.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index fada046..b7a13f2 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,6 @@ func main() { repo := gitRoot() pkgSeen := make(map[string]bool) - var modifiedPackages []*build.Package buildContext := build.Default for _, f := range files { if isIgnored(f) { @@ -59,7 +58,6 @@ func main() { } pkgSeen[pkg.ImportPath] = true - modifiedPackages = append(modifiedPackages, pkg) } // TODO: list all packages in the repo, determine dependency tree and filter package list to those that transitively import affected packages @@ -100,8 +98,8 @@ func main() { // filter the package list to those affected var affectedPackages []string - for _, p := range modifiedPackages { - affectedPackages = append(affectedPackages, p.ImportPath) + for path := range pkgSeen { + affectedPackages = append(affectedPackages, path) } addedMore := true for addedMore {