chore: Pass regex pattern as slice instead of string

This commit is contained in:
Baptiste Roux
2023-02-01 18:14:56 +01:00
parent d267564bca
commit fdafa3aa81
2 changed files with 6 additions and 6 deletions

View File

@@ -199,7 +199,8 @@ fn main() {
} }
}; };
let (found_repos, warnings) = match find_in_tree(&path, &args.exclude) { let (found_repos, warnings) = match find_in_tree(&path, args.exclude.as_deref())
{
Ok((repos, warnings)) => (repos, warnings), Ok((repos, warnings)) => (repos, warnings),
Err(error) => { Err(error) => {
print_error(&error); print_error(&error);

View File

@@ -21,15 +21,14 @@ pub mod worktree;
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn find_repos( fn find_repos(
root: &Path, root: &Path,
exclusion_pattern: &Option<String>, exclusion_pattern: Option<&str>,
) -> Result<Option<(Vec<repo::Repo>, Vec<String>, bool)>, String> { ) -> Result<Option<(Vec<repo::Repo>, Vec<String>, bool)>, String> {
let mut repos: Vec<repo::Repo> = Vec::new(); let mut repos: Vec<repo::Repo> = Vec::new();
let mut repo_in_root = false; let mut repo_in_root = false;
let mut warnings = Vec::new(); let mut warnings = Vec::new();
let exlusion_regex: regex::Regex = let exlusion_regex: regex::Regex = regex::Regex::new(&exclusion_pattern.unwrap_or(r"^$"))
regex::Regex::new(&exclusion_pattern.clone().unwrap_or(r"^$".to_string())) .unwrap_or_else(|_| regex::Regex::new(r"^$").unwrap());
.unwrap_or_else(|_| regex::Regex::new(r"^$").unwrap());
for path in tree::find_repo_paths(root)? { for path in tree::find_repo_paths(root)? {
if exclusion_pattern.is_some() && exlusion_regex.is_match(&path::path_as_string(&path)) { if exclusion_pattern.is_some() && exlusion_regex.is_match(&path::path_as_string(&path)) {
warnings.push(format!("[skipped] {}", &path::path_as_string(&path))); warnings.push(format!("[skipped] {}", &path::path_as_string(&path)));
@@ -143,7 +142,7 @@ fn find_repos(
pub fn find_in_tree( pub fn find_in_tree(
path: &Path, path: &Path,
exclusion_pattern: &Option<String>, exclusion_pattern: Option<&str>,
) -> Result<(tree::Tree, Vec<String>), String> { ) -> Result<(tree::Tree, Vec<String>), String> {
let mut warnings = Vec::new(); let mut warnings = Vec::new();