pub struct FileFilter {
pub ignored: HashSet<String>,
pub not_ignored: HashSet<String>,
pub extensions: HashSet<String>,
/* private fields */
}file-changes only.Expand description
A structure to encapsulate file path filtering behavior.
Fields§
§ignored: HashSet<String>A set of paths or glob patterns to be ignored.
These paths/patterns are relative to the working directory. An empty entry represents the working directory itself.
not_ignored: HashSet<String>A set of paths or glob patterns to be explicitly not ignored.
These paths/patterns are relative to the working directory. An empty entry represents the working directory itself.
extensions: HashSet<String>A set of valid file extensions.
These extensions do not include the leading dot. For example, use “txt” instead of “.txt”.
A blank extension ("") can be used to match files with
no extension (eg. “.clang-format”).
Implementations§
Source§impl FileFilter
impl FileFilter
Sourcepub fn new(
ignore: &[&str],
extensions: &[&str],
log_scope: Option<&str>,
) -> Self
pub fn new( ignore: &[&str], extensions: &[&str], log_scope: Option<&str>, ) -> Self
Convenience constructor to instantiate a FileFilter object.
The ignore parameter is a list of paths (or glob patterns).
A path or pattern is explicitly not ignored if it is prefixed with !.
Otherwise it is ignored.
Leading and trailing spaces are stripped from each item in the ignore list.
Also, leading ./ sequences are stripped.
#[cfg(feature = "file-changes")]
use git_bot_feedback::FileFilter;
let filter = FileFilter::new(
&[" src ", " ! src/lib.rs "],
&["rs", "toml"],
None,
);
assert!(filter.ignored.contains("src"));
assert!(filter.not_ignored.contains("src/lib.rs"));Sourcepub async fn parse_submodules(&mut self)
pub async fn parse_submodules(&mut self)
This function will read a .gitmodules file located in the working directory.
The named submodules’ paths will be automatically added to the FileFilter::ignored set,
unless the submodule’s path is already specified in the FileFilter::not_ignored set.
Sourcepub fn is_file_in_list(&self, file_name: &Path, is_ignored: bool) -> bool
pub fn is_file_in_list(&self, file_name: &Path, is_ignored: bool) -> bool
Describes if a specified file_name is contained within the specified set of paths.
The is_ignored flag describes which set of paths is used as domains.
The specified file_name can be a direct or distant descendant of any
paths in the set.
Returns a true value of the the path/pattern that matches the given file_name.
If given file_name is not in the specified set, then false is returned.
Sourcepub fn is_file_ignored(&self, file_name: &Path) -> bool
pub fn is_file_ignored(&self, file_name: &Path) -> bool
Convenience function to check if a given file_name is ignored.
Equivalent to calling
file_filter.is_file_in_list(file_name, true).
Sourcepub fn is_file_not_ignored(&self, file_name: &Path) -> bool
pub fn is_file_not_ignored(&self, file_name: &Path) -> bool
Convenience function to check if a given file_name is not ignored.
Equivalent to calling
file_filter.is_file_in_list(file_name, false).
Sourcepub fn is_not_ignored(&self, file_path: &Path) -> bool
pub fn is_not_ignored(&self, file_path: &Path) -> bool
A function that checks if file_path satisfies the following conditions (in
ordered priority):
- Does
file_pathuse at least 1 ofFileFilter::extensions? Not applicable ifFileFilter::extensionsis empty. - Is
file_pathspecified inFileFilter::not_ignored? - Is
file_pathnot specified inFileFilter::ignored? - Is
file_pathnot a hidden path (any parts of the path start with “.”)? Mutually exclusive with last condition; does not apply to “./” or “../”.
Sourcepub async fn walk_dir(
&self,
root_path: &str,
) -> Result<HashMap<String, FileDiffLines>, DirWalkError>
pub async fn walk_dir( &self, root_path: &str, ) -> Result<HashMap<String, FileDiffLines>, DirWalkError>
Walks a given root_path recursively and returns a map of discovered source files.
Each entry in the returned map is comprises the discovered file’s path (as key) and
an empty FileDiffLines object (as value). Only files that satisfy the following
conditions are included in the returned map:
- uses at least 1 of the given
FileFilter::extensions. - is specified in the internal list
FileFilter::not_ignoredpaths/patterns - is not specified in the set of
FileFilter::ignoredpaths/patterns and is not a hidden path (starts with “.”).
Trait Implementations§
Source§impl Clone for FileFilter
impl Clone for FileFilter
Source§fn clone(&self) -> FileFilter
fn clone(&self) -> FileFilter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more