From 55f98449f43c6bfc80e4fb5502c2d5065d20fd94 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Fri, 20 Sep 2024 17:50:00 -0700 Subject: [PATCH] todo: move .gitignore loading into walk where it has access to trie --- walk/config.go | 13 ------------- walk/walk.go | 9 +++++++++ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/walk/config.go b/walk/config.go index db9187381..4de57c904 100644 --- a/walk/config.go +++ b/walk/config.go @@ -112,19 +112,6 @@ func (cr *Configurer) Configure(c *config.Config, rel string, f *rule.File) { } c.Exts[walkName] = wcCopy - - // TODO: read the gitignore file even if gitignoring is not enabled in this dir - // because it might be enabled in a subdir. - if wcCopy.gitignoreEnabled { - // Collect gitignore style ignore files in this directory. - ignoreFilePath := path.Join(c.RepoRoot, rel, ".gitignore") - - // TODO: reuse the fs entry already created by gazelle to avoid os.Open, - // see https://github.com/bazelbuild/bazel-gazelle/pull/1737. - if ignoreReader, ignoreErr := os.Open(ignoreFilePath); ignoreErr == nil { - wcCopy.gitignore = createGitIgnorer(wcCopy.gitignore, rel, ignoreReader) - } - } } type isIgnoredFunc = func(string) bool diff --git a/walk/walk.go b/walk/walk.go index 4db142e0f..75e5d8e90 100644 --- a/walk/walk.go +++ b/walk/walk.go @@ -161,6 +161,15 @@ func visit(c *config.Config, cexts []config.Configurer, knownDirectives map[stri c = configure(cexts, knownDirectives, c, rel, f) wc := getWalkConfig(c) + // Load any .gitignore file + if _, hasIgnore := trie.children[".gitignore"]; hasIgnore { + // Collect gitignore style ignore files in this directory. + ignoreFilePath := path.Join(c.RepoRoot, rel, ".gitignore") + if ignoreReader, ignoreErr := os.Open(ignoreFilePath); ignoreErr == nil { + wc.gitignore = createGitIgnorer(wc.gitignore, rel, ignoreReader) + } + } + if wc.isExcluded(rel) { return }