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/downloader/git_downloader.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/downloader/git_downloader.rs')
| -rw-r--r-- | crates/shirabe/src/downloader/git_downloader.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index be3205b5..a8a4344d 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -19,8 +19,9 @@ use crate::util::Url; use indexmap::IndexMap; use shirabe_php_shim::{ CaptureKey, CmpOp, PhpMixed, RuntimeException, array_map, basename, dirname, impl_php_class, - implode, in_array_strict, is_dir, php_regex, preg_match, preg_match_all, preg_quote, - preg_replace, preg_split, realpath, rtrim, strlen, strpos, substr, trim, version_compare, + implode, in_array_strict, is_dir, php_regex, preg_is_match, preg_match, preg_match_all, + preg_quote, preg_replace, preg_split, realpath, rtrim, strlen, strpos, substr, trim, + version_compare, }; #[derive(Debug)] @@ -298,13 +299,12 @@ impl GitDownloader { // check whether non-commitish are branches or tags, and fetch branches with the remote name let git_ref = reference.to_string(); - if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference).is_none() + if !preg_is_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference) && branches.is_some() - && preg_match( + && preg_is_match( format!("{{^\\s+composer/{}$}}m", preg_quote(reference, None)), branches.as_deref().unwrap_or(""), ) - .is_some() { let mut command1: Vec<String> = vec!["git".to_string(), "checkout".to_string()]; command1.extend(force.clone()); @@ -345,19 +345,17 @@ impl GitDownloader { } // try to checkout branch by name and then reset it so it's on the proper branch name - if preg_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference).is_some() { + if preg_is_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference) { // add 'v' in front of the branch if it was stripped when generating the pretty name if branches.is_some() - && preg_match( + && !preg_is_match( format!("{{^\\s+composer/{}$}}m", preg_quote(&branch, None)), branches.as_deref().unwrap_or(""), ) - .is_none() - && preg_match( + && preg_is_match( format!("{{^\\s+composer/v{}$}}m", preg_quote(&branch, None)), branches.as_deref().unwrap_or(""), ) - .is_some() { branch = format!("v{}", branch); } @@ -642,8 +640,7 @@ impl GitDownloader { } fn get_short_hash(&self, reference: &str) -> String { - if !self.inner.io.is_verbose() - && preg_match(php_regex!(r"{^[0-9a-f]{40}$}"), reference).is_some() + if !self.inner.io.is_verbose() && preg_is_match(php_regex!(r"{^[0-9a-f]{40}$}"), reference) { return substr(reference, 0, Some(10)); } |
