Add in regular expression exclusion
@@ -6,6 +6,7 @@ import (
"github.com/monochromegane/go-gitignore"
"io/ioutil"
"path/filepath"
+ "regexp"
"runtime/debug"
"strings"
"sync"
@@ -78,6 +79,12 @@ func walkDirectoryParallel(root string, output chan *FileJob) {
gitignore, gitignoreerror := gitignore.NewGitIgnore(filepath.Join(root, ".gitignore"))
resetGc := false
+ var regex *regexp.Regexp
+
+ if Exclude != "" {
+ regex = regexp.MustCompile(Exclude)
+ }
+
for _, f := range all {
// Godirwalk despite being faster than the default walk is still too slow to feed the
// CPU's and so we need to walk in parallel to keep up as much as possible
@@ -87,11 +94,22 @@ func walkDirectoryParallel(root string, output chan *FileJob) {
for _, black := range blackList {
if strings.HasPrefix(filepath.Join(root, f.Name()), black) {
shouldSkip = true
+ if Verbose {
printWarn(fmt.Sprintf("skipping directory due to being in blacklist: %s", filepath.Join(root, f.Name())))
+ }
break
}
}
+ if Exclude != "" {
+ if regex.Match([]byte(f.Name())) {
+ if Verbose {
+ printWarn("skipping directory due to match exclude: " + f.Name())
+ }
+ shouldSkip = true
+ }
+ }
+
if !shouldSkip {
wg.Add(1)
go func(toWalk string) {
@@ -114,6 +132,18 @@ func walkDirectoryParallel(root string, output chan *FileJob) {
}
} else {
if gitignoreerror != nil || !gitignore.Match(filepath.Join(root, f.Name()), false) {
+
+ shouldSkip := false
+ if Exclude != "" {
+ if regex.Match([]byte(f.Name())) {
+ if Verbose {
+ printWarn("skipping file due to match exclude: " + f.Name())
+ }
+ shouldSkip = true
+ }
+ }
+
+ if !shouldSkip {
extension := ""
// Lookup in case the full name matches
language, ok := extensionLookup[strings.ToLower(f.Name())]
@@ -140,6 +170,7 @@ func walkDirectoryParallel(root string, output chan *FileJob) {
}
}
}
+ }
wg.Wait()
close(output)
@@ -156,6 +187,21 @@ func walkDirectory(toWalk string, blackList []string, extensionLookup map[string
// Unsorted is meant to make the walk faster and we need to sort after processing anyway
Unsorted: true,
Callback: func(root string, info *godirwalk.Dirent) error {
+
+ var regex *regexp.Regexp
+ if Exclude != "" {
+ regex = regexp.MustCompile(Exclude)
+ }
+
+ if Exclude != "" {
+ if regex.Match([]byte(info.Name())) {
+ if Verbose {
+ printWarn("skipping directory due to match exclude: " + info.Name())
+ }
+ return nil
+ }
+ }
+
if info.IsDir() {
for _, black := range blackList {
if strings.HasPrefix(root, black+"/") || strings.HasPrefix(root, black) {
