tools/filetools.go: extract fastWalker consumer func

When calling FastWalkGitRepo, the implementation constructs an
instance of the *fastWalker type, and then consumes items from the
<-chan until it receives a close().

This was left mostly unchanged since 3b9e629d (use a single channel,
2016-11-29), when we had only the single function `FastWalkGitRepo`.

In a subsequent commit, we will introduce a new function
`FastWalkGitRepoAll` with does _not_ exclude patterns found in a
repository's .gitignore(s).

In preparation for this function, which we assume to share the
implementation of `FastWalkGitRepo` in its entirety (modulo the
construction of a `*fastWalker`), let's extract this fastWalkCallback
function to avoid repeating ourselves.
This commit is contained in:
Taylor Blau 2018-08-20 07:00:31 -06:00
parent 6e1f0f9188
commit c9cde1189b

@ -152,7 +152,12 @@ type FastWalkCallback func(parentDir string, info os.FileInfo, err error)
//
// rootDir - Absolute path to the top of the repository working directory
func FastWalkGitRepo(rootDir string, cb FastWalkCallback) {
walker := fastWalkWithExcludeFiles(rootDir, ".gitignore")
fastWalkCallback(fastWalkWithExcludeFiles(rootDir, ".gitignore"), cb)
}
// fastWalkCallback calls the FastWalkCallback "cb" for all files found by the
// given *fastWalker, "walker".
func fastWalkCallback(walker *fastWalker, cb FastWalkCallback) {
for file := range walker.ch {
cb(file.ParentDir, file.Info, file.Err)
}