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)".
This commit is contained in:
Yuya Nishihara 2023-07-01 13:56:05 +09:00
parent a07574a233
commit 915f76f4d9

View file

@ -519,12 +519,13 @@ pub fn fetch(
remote.disconnect()?; remote.disconnect()?;
tracing::debug!("import_refs"); tracing::debug!("import_refs");
if let Some(globs) = branch_name_globs { if let Some(globs) = branch_name_globs {
let pattern = format!( let branch_regex = regex::RegexSet::new(
"^({})$", globs
globs.iter().map(|glob| glob.replace('*', ".*")).join("|") .iter()
); .map(|glob| format!("^{}$", glob.replace('*', ".*"))),
tracing::debug!(?globs, ?pattern, "globs as regex"); )
let branch_regex = regex::Regex::new(&pattern).map_err(|_| GitFetchError::InvalidGlob)?; .map_err(|_| GitFetchError::InvalidGlob)?;
tracing::debug!(?globs, ?branch_regex, "globs as regex");
import_some_refs( import_some_refs(
mut_repo, mut_repo,
git_repo, git_repo,