diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | fed0a6e7ac361af9b963c1f62411b1a85478230c (patch) | |
| tree | 5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe/src/util/git.rs | |
| parent | e093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff) | |
| download | php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.gz php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.zst php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.zip | |
refactor(preg): add preg_is_match for existence-only call sites
The capture groups were discarded at 162 of the preg_match call sites,
which only tested the Option. They now call preg_is_match, which lets the
regex engine skip capture tracking.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/git.rs')
| -rw-r--r-- | crates/shirabe/src/util/git.rs | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index 2426780f..78c1acb5 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -17,8 +17,8 @@ use indexmap::IndexMap; use shirabe_php_shim::{ AnyThrowable, CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, PregMatches, RuntimeException, array_map, clearstatcache, explode, implode, in_array_loose, in_array_strict, - is_dir, php_regex, preg_match, preg_quote, preg_replace, rawurldecode, rawurlencode, - str_replace_array, strlen, strpos, substr, trim, version_compare, + is_dir, php_regex, preg_is_match, preg_match, preg_quote, preg_replace, rawurldecode, + rawurlencode, str_replace_array, strlen, strpos, substr, trim, version_compare, }; use std::sync::Mutex; @@ -209,7 +209,7 @@ impl Git { status }; - if preg_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), url).is_some() { + if preg_is_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), url) { return Err(InvalidArgumentException::new(format!( "The source URL {} is invalid, ssh URLs should have a port number after \":\".\nUse ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.", url @@ -310,21 +310,19 @@ impl Git { .collect(), _ => vec![], }; - let bypass_ssh_for_github = preg_match( + let bypass_ssh_for_github = preg_is_match( format!( "{{^git@{}:(.+?)\\.git$}}i", Self::get_github_domains_regex(&self.config.borrow()) ), url, - ) - .is_some() - && !in_array_strict( - "ssh".to_string(), - &protocols_list - .iter() - .map(|s| PhpMixed::String(s.clone())) - .collect::<Vec<_>>(), - ); + ) && !in_array_strict( + "ssh".to_string(), + &protocols_list + .iter() + .map(|s| PhpMixed::String(s.clone())) + .collect::<Vec<_>>(), + ); let mut auth: Option<IndexMap<String, Option<String>>> = None; let mut credentials: Vec<String> = vec![]; @@ -915,7 +913,7 @@ impl Git { pretty_version: Option<&str>, ) -> anyhow::Result<bool> { if self.check_ref_is_in_mirror(dir, r#ref)? { - if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), r#ref).is_some() + if preg_is_match(php_regex!(r"{^[a-f0-9]{40}$}"), r#ref) && let Some(pretty_version) = pretty_version { let branch = preg_replace( @@ -949,17 +947,15 @@ impl Git { // this can occur if a git tag gets created *after* the reference is already put into the cache, as the ref check above will then not sync the new tags // see https://github.com/composer/composer/discussions/11002 if branches.is_some() - && preg_match( + && !preg_is_match( format!(r"{{^[\s*]*v?{}$}}m", preg_quote(&branch, None)), branches.as_deref().unwrap_or(""), ) - .is_none() && tags.is_some() - && preg_match( + && !preg_is_match( format!(r"{{^[\s*]*{}$}}m", preg_quote(&branch, None)), tags.as_deref().unwrap_or(""), ) - .is_none() { self.sync_mirror(url, dir)?; } |
