lib/ignore, lib/scanner: Catch included items below ignored ones (#4811)

This commit is contained in:
Simon Frei
2018-05-14 09:47:23 +02:00
committed by GitHub
parent 22b0bd8e13
commit d59aecba31
12 changed files with 244 additions and 104 deletions

View File

@@ -77,15 +77,16 @@ type ChangeDetector interface {
}
type Matcher struct {
fs fs.Filesystem
lines []string // exact lines read from .stignore
patterns []Pattern // patterns including those from included files
withCache bool
matches *cache
curHash string
stop chan struct{}
changeDetector ChangeDetector
mut sync.Mutex
fs fs.Filesystem
lines []string // exact lines read from .stignore
patterns []Pattern // patterns including those from included files
withCache bool
matches *cache
curHash string
stop chan struct{}
changeDetector ChangeDetector
skipIgnoredDirs bool
mut sync.Mutex
}
// An Option can be passed to New()
@@ -108,9 +109,10 @@ func WithChangeDetector(cd ChangeDetector) Option {
func New(fs fs.Filesystem, opts ...Option) *Matcher {
m := &Matcher{
fs: fs,
stop: make(chan struct{}),
mut: sync.NewMutex(),
fs: fs,
stop: make(chan struct{}),
mut: sync.NewMutex(),
skipIgnoredDirs: true,
}
for _, opt := range opts {
opt(m)
@@ -169,6 +171,14 @@ func (m *Matcher) parseLocked(r io.Reader, file string) error {
return err
}
m.skipIgnoredDirs = true
for _, p := range patterns {
if p.result&resultInclude == resultInclude {
m.skipIgnoredDirs = false
break
}
}
m.curHash = newHash
m.patterns = patterns
if m.withCache {
@@ -291,6 +301,12 @@ func (m *Matcher) ShouldIgnore(filename string) bool {
return false
}
func (m *Matcher) SkipIgnoredDirs() bool {
m.mut.Lock()
defer m.mut.Unlock()
return m.skipIgnoredDirs
}
func hashPatterns(patterns []Pattern) string {
h := md5.New()
for _, pat := range patterns {