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,30 +217,40 @@ 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;
} }
} }
let mut path = path.to_path_buf(); // If the file has been whitelisted, then we have to stop checking
for id in self.parent_stack.iter().rev() { // parent directories. The only thing that can override a whitelist
if let Some(ref dirname) = id.name { // at this point is a type filter.
path = Path::new(dirname).join(path); if !whitelisted {
} let mut path = path.to_path_buf();
let mat = id.matched(&*path, is_dir); for id in self.parent_stack.iter().rev() {
if let Some(is_ignored) = self.ignore_match(&*path, mat) { if let Some(ref dirname) = id.name {
if is_ignored { path = Path::new(dirname).join(path);
return true; }
let mat = id.matched(&*path, is_dir);
if let Some(is_ignored) = self.ignore_match(&*path, mat) {
if is_ignored {
return true;
}
// If this path is whitelisted by an ignore, then
// fallthrough and let the file type matcher have a
// say.
break;
} }
// If this path is whitelisted by an ignore, then
// fallthrough and let the file type matcher have a say.
break;
} }
} }
} }