-
-
Notifications
You must be signed in to change notification settings - Fork 816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closes #535 --prune option #546
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,17 @@ fn spawn_senders( | |
return ignore::WalkState::Continue; | ||
} | ||
|
||
// when pruning, don't descend into matching dirs | ||
// note that prune requires pattern | ||
let walk_action = if config.prune | ||
&& pattern.as_str().len() != 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand why this is necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it so that the prune is only evaluated if there is a pattern specified, thinking that the prune option should only be used with a pattern. (and I added a test case for this). But, I suppose it could be allowed and then the expected behavior would be that no directories would be descended into. What do you think/prefer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, "not having a pattern" does not only refer to cases where I agree that If two options in combination do not make sense, we should also think about disallowing that via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good point! I hadn't considered that...
Lets see. If we are using Currently this implementation uses the
, will look for matches with foo but not descend into dirs matching bar. This would eliminate the need to do the check for pattern on line 369.
That is good to know about!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FWIW, the -E option invokes ripgreps gitignore style excludes. To ignore a directory
|
||
&& entry.file_type().map_or(false, |e| e.is_dir()) | ||
{ | ||
ignore::WalkState::Skip | ||
} else { | ||
ignore::WalkState::Continue | ||
}; | ||
|
||
// Filter out unwanted extensions. | ||
if let Some(ref exts_regex) = config.extensions { | ||
if let Some(path_str) = entry_path.file_name() { | ||
|
@@ -387,10 +398,10 @@ fn spawn_senders( | |
|| (file_types.empty_only && !fshelper::is_empty(&entry)) | ||
|| !(entry_type.is_file() || entry_type.is_dir() || entry_type.is_symlink()) | ||
{ | ||
return ignore::WalkState::Continue; | ||
return walk_action; | ||
} | ||
} else { | ||
return ignore::WalkState::Continue; | ||
return walk_action; | ||
} | ||
} | ||
|
||
|
@@ -404,13 +415,13 @@ fn spawn_senders( | |
.iter() | ||
.any(|sc| !sc.is_within(file_size)) | ||
{ | ||
return ignore::WalkState::Continue; | ||
return walk_action; | ||
} | ||
} else { | ||
return ignore::WalkState::Continue; | ||
return walk_action; | ||
} | ||
} else { | ||
return ignore::WalkState::Continue; | ||
return walk_action; | ||
} | ||
} | ||
|
||
|
@@ -426,7 +437,7 @@ fn spawn_senders( | |
} | ||
} | ||
if !matched { | ||
return ignore::WalkState::Continue; | ||
return walk_action; | ||
} | ||
} | ||
|
||
|
@@ -436,7 +447,7 @@ fn spawn_senders( | |
return ignore::WalkState::Quit; | ||
} | ||
|
||
ignore::WalkState::Continue | ||
walk_action | ||
}) | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, this is slightly ambiguous for people who aren't familiar with find's -prune option. In particular, I think it should be more explicitly stated that the matched directories are included in the output. Maybe something like:
"Do not descend into matched directories"
"When a directory matches the pattern, fd does not descend into it. The directory itself is not excluded."