From 915f76f4d91088fbcfd8b4daf0e82d7490cb3cf7 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 1 Jul 2023 13:56:05 +0900 Subject: [PATCH] git: use RegexSet in place of concatenating multiple glob patterns Perhaps, this would handle patterns like ["a(b", "c)"] better. It might not be correct to error out on "(", but should be better than building wrong regexp pattern "a(b|c)". --- lib/src/git.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/git.rs b/lib/src/git.rs index 55f6fd0ba..cc5126195 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -519,12 +519,13 @@ pub fn fetch( remote.disconnect()?; tracing::debug!("import_refs"); if let Some(globs) = branch_name_globs { - let pattern = format!( - "^({})$", - globs.iter().map(|glob| glob.replace('*', ".*")).join("|") - ); - tracing::debug!(?globs, ?pattern, "globs as regex"); - let branch_regex = regex::Regex::new(&pattern).map_err(|_| GitFetchError::InvalidGlob)?; + let branch_regex = regex::RegexSet::new( + globs + .iter() + .map(|glob| format!("^{}$", glob.replace('*', ".*"))), + ) + .map_err(|_| GitFetchError::InvalidGlob)?; + tracing::debug!(?globs, ?branch_regex, "globs as regex"); import_some_refs( mut_repo, git_repo,