1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-08-04 21:52:54 +02:00

Fix whitelisting precedence.

Once a file is known to be whitelisted, we shouldn't check any ancestor
gitignores.
This commit is contained in:
Andrew Gallant
2016-09-24 20:09:29 -04:00
parent 71ad9bf393
commit 872a107658

View File

@ -217,17 +217,25 @@ impl Ignore {
return true; return true;
} }
if !self.no_ignore { if !self.no_ignore {
let mut whitelisted = false;
for id in self.stack.iter().rev() { for id in self.stack.iter().rev() {
let mat = id.matched(path, is_dir); let mat = id.matched(path, is_dir);
// println!("path: {}, mat: {:?}, id: {:?}",
// path.display(), mat, id);
if let Some(is_ignored) = self.ignore_match(path, mat) { if let Some(is_ignored) = self.ignore_match(path, mat) {
if is_ignored { if is_ignored {
return true; return true;
} }
// If this path is whitelisted by an ignore, then // If this path is whitelisted by an ignore, then
// fallthrough and let the file type matcher have a say. // fallthrough and let the file type matcher have a say.
whitelisted = true;
break; break;
} }
} }
// If the file has been whitelisted, then we have to stop checking
// parent directories. The only thing that can override a whitelist
// at this point is a type filter.
if !whitelisted {
let mut path = path.to_path_buf(); let mut path = path.to_path_buf();
for id in self.parent_stack.iter().rev() { for id in self.parent_stack.iter().rev() {
if let Some(ref dirname) = id.name { if let Some(ref dirname) = id.name {
@ -239,11 +247,13 @@ impl Ignore {
return true; return true;
} }
// If this path is whitelisted by an ignore, then // If this path is whitelisted by an ignore, then
// fallthrough and let the file type matcher have a say. // fallthrough and let the file type matcher have a
// say.
break; break;
} }
} }
} }
}
let mat = self.types.matched(path, is_dir); let mat = self.types.matched(path, is_dir);
if let Some(is_ignored) = self.ignore_match(path, mat) { if let Some(is_ignored) = self.ignore_match(path, mat) {
return is_ignored; return is_ignored;