Skip to content
Myr

ignore: skip loading unreachable ignore files

Before adoption: this commit came in with the history the project adopted, so no landing records it.

When parallelism isn't used (e.g., when sorting results), then it's possible in some cases for the `ignore` crate to still try and load gitignore files inside of directories that are never descended into. This can occur when `--max-depth` is used, or even just when a directory is skipped for some other reason. Fixes #2565, PR #3496

authored by jif · committed by GitHub · parent dffd776 · Browse files · 1 file+31 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+31 added−3 removed

  • other:+31 added−3 removed

1 file+31 added−3 removed

modified:crates/ignore/src/walk.rs+31 added-3 removed
634 unmodified lines
635 its,636 it: None,637 ig_root: ig_root.clone(),638 ig: ig_root.clone(),639 max_depth: self.max_depth,640 max_filesize: self.max_filesize,641 skip: self.skip.clone(),642 filter: self.filter.clone(),643 }
474 unmodified lines
1118 its: std::vec::IntoIter<(PathBuf, Option<WalkEventIter>)>,1119 it: Option<WalkEventIter>,1120 ig_root: Ignore,1121 ig: Ignore,1122 max_depth: Option<usize>,1123 max_filesize: Option<u64>,1124 skip: Option<Arc<Handle>>,1125 filter: Option<Filter>,1126}
102 unmodified lines
1229 if should_skip {1230 self.it.as_mut().unwrap().it.skip_current_dir();1231 // Still need to push this on the stack because1232 // we'll get a WalkEvent::Exit event for this dir.1231 // We don't care if it errors though.1232 let (igtmp, _) = self.ig.add_child(ent.path());1233 // Its ignore files cannot apply to any visited entry.1234 let (igtmp, _) =1235 self.ig.add_child_with_entries(ent.path(), &[]);1236 self.ig = igtmp;1237 continue;1238 }1236 let (igtmp, err) = self.ig.add_child(ent.path());1239 let (igtmp, err) = if self.max_depth == Some(ent.depth()) {1240 self.ig.add_child_with_entries(ent.path(), &[])1241 } else {1242 self.ig.add_child(ent.path())1243 };1244 self.ig = igtmp;1245 ent.err = err;1246 return Some(Ok(ent));1247 }
1186 unmodified lines
2434 );2435 }24362437 #[test]2438 fn max_depth_does_not_load_unreachable_ignore_files() {2439 let td = tmpdir();2440 let leaf = td.path().join("leaf");2441 mkdirp(&leaf);2442 wfile(leaf.join(".ignore"), "{invalid\n");24432444 let mut builder = WalkBuilder::new(td.path());2445 builder.max_depth(Some(1));2446 let entry = builder2447 .build()2448 .find_map(|result| {2449 let entry = result.unwrap();2450 (entry.path() == leaf).then_some(entry)2451 })2452 .unwrap();24532454 assert!(entry.error().is_none());2455 assert_paths(td.path(), &builder, &["leaf"]);2456 }24572458 #[test]2459 fn min_depth() {2460 let td = tmpdir();2461 mkdirp(td.path().join("a/b/c"));2462 wfile(td.path().join("foo"), "");
278 unmodified lines