File exclusion: Reduce code duplication (#8336)

This commit is contained in:
Micha Reiser 2023-10-30 12:15:08 +09:00 committed by GitHub
parent 221f7cd932
commit 1f2d4f3ee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View file

@ -161,7 +161,7 @@ impl FilePattern {
// Add basename path.
if !pattern.contains(std::path::MAIN_SEPARATOR) {
builder.add(Glob::from_str(&pattern)?);
builder.add(Glob::new(&pattern)?);
}
}
}

View file

@ -547,15 +547,17 @@ fn is_file_excluded(
/// Return `true` if the given file should be ignored based on the exclusion
/// criteria.
#[inline]
pub fn match_exclusion<P: AsRef<Path>, R: AsRef<Path>>(
file_path: P,
file_basename: R,
exclusion: &GlobSet,
) -> bool {
if exclusion.is_empty() {
return false;
}
exclusion.is_match(file_path) || exclusion.is_match(file_basename)
match_candidate_exclusion(
&Candidate::new(file_path.as_ref()),
&Candidate::new(file_basename.as_ref()),
exclusion,
)
}
/// Return `true` if the given candidates should be ignored based on the exclusion