CompilePaths creates a new ignore parser from a string array
(excludePaths []string, log log.Logger)
| 57 | |
| 58 | // CompilePaths creates a new ignore parser from a string array |
| 59 | func CompilePaths(excludePaths []string, log log.Logger) (IgnoreParser, error) { |
| 60 | if len(excludePaths) > 0 { |
| 61 | requireFullScan := false |
| 62 | absoluteNegatePatterns := []string{} |
| 63 | for _, line := range excludePaths { |
| 64 | line = strings.Trim(line, " ") |
| 65 | if line == "" { |
| 66 | continue |
| 67 | } else if line[0] == '!' { |
| 68 | if len(line) > 1 && line[1] == '/' { |
| 69 | p := line[1:] |
| 70 | if !strings.Contains(p, "**") && !strings.Contains(path.Dir(p), "*") { |
| 71 | absoluteNegatePatterns = append(absoluteNegatePatterns, p) |
| 72 | } else { |
| 73 | log.Warnf("Exclude path '%s' uses a ** or * and thus requires a full initial scan. Please consider using a path in the form of '!/path/to/my/folder/' instead to improve performance", line) |
| 74 | requireFullScan = true |
| 75 | } |
| 76 | } else { |
| 77 | log.Warnf("Exclude path '%s' is not scoped to the directory base and thus requires a full initial scan. Please consider using a path in the form of '!/path/to/my/folder/' instead to improve performance", line) |
| 78 | requireFullScan = true |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | gitIgnoreParser, err := gitignore.CompileIgnoreLines(excludePaths...) |
| 84 | if err != nil { |
| 85 | return nil, errors.Wrap(err, "compile ignore lines") |
| 86 | } |
| 87 | |
| 88 | return &ignoreParser{ |
| 89 | ignoreParser: gitIgnoreParser, |
| 90 | absoluteNegatePatterns: absoluteNegatePatterns, |
| 91 | requireFullScan: requireFullScan, |
| 92 | }, nil |
| 93 | } |
| 94 | |
| 95 | return nil, nil |
| 96 | } |
no test coverage detected