Skip to content

Commit

Permalink
todo: move .gitignore loading into walk where it has access to trie
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Sep 21, 2024
1 parent 1256149 commit 55f9844
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
13 changes: 0 additions & 13 deletions walk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions walk/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 55f9844

Please sign in to comment.