Fixes for tmccombs review comments.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ami Fischman · committed by Ami Fischman · parent d05a718 · Browse files · 5 files·+36 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+36 added−20 removed
- tests:+18 added−2 removed
- other:+18 added−18 removed
Provenance
- Commit
1993c76- Tree
15a9596- Author
Ami Fischman <ami@fischman.org>- Committer
Ami Fischman <ami@fischman.org>- Parent
d05a718
5 files changed+36 added−20 removed
modified:doc/fd.1+4 added
263 unmodified lines264 Examples:265 \-\-exclude '*.pyc'266 \-\-exclude node_modules267 .TP268+.BI "\-\-ignore-contain " name269+Exclude directories that (directly) contain the given name.270+This option can be specified multiple times.271+.TP272 .BI "\-\-ignore-file " path273 Add a custom ignore-file in '.gitignore' format.274 These files have a low precedence.275 .TP303 unmodified linesmodified:src/cli.rs+2 added-5 removed
529 unmodified lines530 531 /// Ignore directories containing the named entry.532 #[arg(533 long,534- value_name = "name",535- hide_short_help = true,536- help = "Ignore directories containing this name",537- long_help534+ value_name = "name"535 )]539- pub ignore_contain: Option<String>,536+ pub ignore_contain: Vec<String>,537 538 /// Set number of threads to use for searching & executing (default: number539 /// of available CPU cores)540 #[arg(long, short = 'j', value_name = "num", hide_short_help = true, value_parser = str::parse::<NonZeroUsize>)]408 unmodified linesmodified:src/config.rs+2 added-2 removed
129 unmodified lines130 131 /// Whether or not to use hyperlinks on paths132 pub hyperlink: bool,133 134- /// A name that should stop traversal down its parent. (e.g. https://bford.info/cachedir/).135- pub ignore_contain: Option<String>,134+ /// Names that should stop traversal down their parent. (e.g. https://bford.info/cachedir/).135+ pub ignore_contain: Vec<String>,136 }137 138 impl Config {139 /// Check whether results are being printed.4 unmodified linesmodified:src/walk.rs+10 added-11 removed
496 unmodified lines497 };498 }499 };500 501+ // Check the depth & name first, since they don't require metadata.502+ let entry_path = entry.path();503+504+ // Filter out directories containing a given name.505+ if entry_path.is_dir()506+ && config.ignore_contain.iter().any(|ic| entry_path.join(ic).exists())507+ {508+ return WalkState::Skip;509+ }510+511 if let Some(min_depth) = config.min_depth512 && entry.depth().is_none_or(|d| d < min_depth)513 {514 return WalkState::Continue;515 }516 507- // Check the name first, since it doesn't require metadata508- let entry_path = entry.path();509-517 let search_str: Cow<OsStr> = if config.search_full_path {518 let path_abs_buf = filesystem::path_absolute_form(entry_path)519 .expect("Retrieving absolute path succeeds");520 Cow::Owned(path_abs_buf.as_os_str().to_os_string())45 unmodified lines566 }567 }568 }569 563- // Filter out directories containing a given name.564- if let Some(ref ignore_contain) = config.ignore_contain565- && entry_path.is_dir()566- && entry_path.join(ignore_contain).exists()567- {568- return WalkState::Skip;569- }570-570 // Filter out unwanted sizes if it is a file and we have been given size constraints.571 if !config.size_constraints.is_empty() {572 if entry_path.is_file() {573 if let Some(metadata) = entry.metadata() {103 unmodified linesmodified:tests/tests.rs+18 added-2 removed
2709 unmodified lines2710 2711 #[test]2712 fn test_ignore_contain() {2713 let te = TestEnv::new(2714- &["include", "exclude", "exclude/sub"],2714+ &["include", "exclude", "exclude/sub", "other"],2715 &[2716 "top",2717 "include/foo",2718 "exclude/CACHEDIR.TAG",2719 "exclude/sub/nope",2720+ "other/ignoremyparent",2721 ],2722 );2723 let expected = "include/2724 include/foo2725 symlink2726 top";2726- te.assert_output(&["--ignore-contain=CACHEDIR.TAG", "."], expected);2727+ te.assert_output(&["--ignore-contain=CACHEDIR.TAG", "--ignore-contain=ignoremyparent", "."], expected);2728 }2729+2730+#[test]2731+fn test_ignore_contain_has_highest_precedence() {2732+ let te = TestEnv::new(2733+ &["include", "exclude", "exclude/sub"],2734+ &[2735+ "top",2736+ "include/foo",2737+ "exclude/CACHEDIR.TAG",2738+ "exclude/sub/nope",2739+ ],2740+ );2741+ let expected = "include/foo";2742+ te.assert_output(&["--ignore-contain=CACHEDIR.TAG", "--min-depth=2", "."], expected);2743+}