aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository/vcs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
commitfed0a6e7ac361af9b963c1f62411b1a85478230c (patch)
tree5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe/src/repository/vcs
parente093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff)
downloadphp-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/repository/vcs')
-rw-r--r--crates/shirabe/src/repository/vcs/fossil_driver.rs10
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs8
-rw-r--r--crates/shirabe/src/repository/vcs/git_driver.rs14
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs8
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/hg_driver.rs9
-rw-r--r--crates/shirabe/src/repository/vcs/perforce_driver.rs6
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs8
-rw-r--r--crates/shirabe/src/repository/vcs/vcs_driver.rs6
9 files changed, 33 insertions, 40 deletions
diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs
index d5a9334f..9a678284 100644
--- a/crates/shirabe/src/repository/vcs/fossil_driver.rs
+++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs
@@ -13,7 +13,7 @@ use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex, preg_match,
+ PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex, preg_is_match,
preg_replace,
};
@@ -301,16 +301,14 @@ impl FossilDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if preg_match(
+ if preg_is_match(
php_regex!(r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i"),
url,
- )
- .is_some()
- {
+ ) {
return Ok(true);
}
- if preg_match(php_regex!(r"!/fossil/|\.fossil!"), url).is_some() {
+ if preg_is_match(php_regex!(r"!/fossil/|\.fossil!"), url) {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index a05e9835..b1960974 100644
--- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
@@ -19,7 +19,7 @@ use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_key_exists,
array_search_mixed, extension_loaded, http_build_query, implode, is_array, php_regex,
- preg_match, preg_replace, strpos,
+ preg_is_match, preg_match, preg_replace, strpos,
};
#[derive(Debug)]
@@ -797,12 +797,10 @@ impl GitBitbucketDriver {
url: &str,
_deep: bool,
) -> anyhow::Result<bool> {
- if preg_match(
+ if !preg_is_match(
php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i"),
url,
- )
- .is_none()
- {
+ ) {
return Ok(false);
}
diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs
index 63598517..f45dbcaa 100644
--- a/crates/shirabe/src/repository/vcs/git_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_driver.rs
@@ -16,8 +16,8 @@ use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, preg_match,
- preg_replace, realpath, sys_get_temp_dir,
+ InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, preg_is_match,
+ preg_match, preg_replace, realpath, sys_get_temp_dir,
};
use shirabe_php_shim::{PhpMixed, php_regex};
@@ -98,7 +98,7 @@ impl GitDriver {
.into());
}
- if preg_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), &self.inner.url).is_some() {
+ if preg_is_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), &self.inner.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.",
self.inner.url
@@ -343,7 +343,7 @@ impl GitDriver {
);
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty()
- && preg_match(php_regex!(r"{^ *[^/]+/HEAD }"), &branch).is_none()
+ && !preg_is_match(php_regex!(r"{^ *[^/]+/HEAD }"), &branch)
&& let Some(caps) = preg_match(
php_regex!(r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}"),
&branch,
@@ -367,12 +367,10 @@ impl GitDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if preg_match(
+ if preg_is_match(
php_regex!(r"#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i"),
url,
- )
- .is_some()
- {
+ ) {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs
index f310da3d..c41cc2d0 100644
--- a/crates/shirabe/src/repository/vcs/github_driver.rs
+++ b/crates/shirabe/src/repository/vcs/github_driver.rs
@@ -18,8 +18,8 @@ use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_map,
array_search_mixed, base64_decode, basename, empty, explode, extension_loaded, in_array_loose,
- parse_url, php_regex, preg_match, preg_replace, preg_split, strpos, strtolower, substr, trim,
- urlencode,
+ parse_url, php_regex, preg_is_match, preg_match, preg_replace, preg_split, strpos, strtolower,
+ substr, trim, urlencode,
};
#[derive(Debug)]
@@ -642,9 +642,7 @@ impl GitHubDriver {
};
if bits.scheme.is_none() && bits.host.is_none() {
- if preg_match(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url)
- .is_some()
- {
+ if preg_is_match(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url) {
result[key_idx].insert(
"url".to_string(),
PhpMixed::String(format!("https://{}", item_url)),
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index 229d043b..b40297da 100644
--- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs
+++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
@@ -19,7 +19,7 @@ use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed,
array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array_loose, is_array,
- is_string, ord, php_regex, preg_match, preg_replace, strpos, strtolower,
+ is_string, ord, php_regex, preg_is_match, preg_match, preg_replace, strpos, strtolower,
};
/// Driver for GitLab API, use the Git driver for local checkouts.
@@ -382,7 +382,7 @@ impl GitLabDriver {
// Convert the root identifier to a cacheable commit id
let mut identifier = identifier.to_string();
- if preg_match(php_regex!(r"{[a-f0-9]{40}}i"), &identifier).is_none() {
+ if !preg_is_match(php_regex!(r"{[a-f0-9]{40}}i"), &identifier) {
let branches = self.get_branches()?;
if let Some(sha) = branches.get(&identifier) {
identifier = sha.clone();
diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs
index 977d6b97..54341070 100644
--- a/crates/shirabe/src/repository/vcs/hg_driver.rs
+++ b/crates/shirabe/src/repository/vcs/hg_driver.rs
@@ -13,7 +13,8 @@ use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex, preg_match, preg_replace,
+ PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex, preg_is_match, preg_match,
+ preg_replace,
};
#[derive(Debug)]
@@ -305,14 +306,12 @@ impl HgDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if preg_match(
+ if preg_is_match(
php_regex!(
r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i"
),
url,
- )
- .is_some()
- {
+ ) {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs
index 16dad1e9..d55d361c 100644
--- a/crates/shirabe/src/repository/vcs/perforce_driver.rs
+++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs
@@ -9,7 +9,9 @@ use crate::util::PerforceInterface;
use crate::util::ProcessExecutor;
use crate::util::http::Response;
use indexmap::IndexMap;
-use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException, php_regex, preg_match};
+use shirabe_php_shim::{
+ BadMethodCallException, PhpMixed, RuntimeException, php_regex, preg_is_match,
+};
#[derive(Debug)]
pub struct PerforceDriver {
@@ -188,7 +190,7 @@ impl PerforceDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if deep || preg_match(php_regex!(r"#\b(perforce|p4)\b#i"), url).is_some() {
+ if deep || preg_is_match(php_regex!(r"#\b(perforce|p4)\b#i"), url) {
return Ok(Perforce::check_server_exists(
url,
&mut ProcessExecutor::new(Some(io)),
diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs
index 28239452..0431c33b 100644
--- a/crates/shirabe/src/repository/vcs/svn_driver.rs
+++ b/crates/shirabe/src/repository/vcs/svn_driver.rs
@@ -15,8 +15,8 @@ use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, php_regex, preg_match, preg_replace, stripos, strrpos, strtr,
- substr, trim,
+ PhpMixed, RuntimeException, php_regex, preg_is_match, preg_match, preg_replace, stripos,
+ strrpos, strtr, substr, trim,
};
#[derive(Debug)]
@@ -153,7 +153,7 @@ impl SvnDriver {
}
fn should_cache(&self, identifier: &str) -> bool {
- self.inner.cache.is_some() && preg_match(php_regex!(r"{@\d+$}"), identifier).is_some()
+ self.inner.cache.is_some() && preg_is_match(php_regex!(r"{@\d+$}"), identifier)
}
pub fn get_composer_information(
@@ -440,7 +440,7 @@ impl SvnDriver {
deep: bool,
) -> anyhow::Result<bool> {
let url = Self::normalize_url(url);
- if preg_match(php_regex!(r"#(^svn://|^svn\+ssh://|svn\.)#i"), &url).is_some() {
+ if preg_is_match(php_regex!(r"#(^svn://|^svn\+ssh://|svn\.)#i"), &url) {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs
index 439275f1..17616c36 100644
--- a/crates/shirabe/src/repository/vcs/vcs_driver.rs
+++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs
@@ -13,7 +13,7 @@ use crate::util::http::Response;
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
-use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex, preg_match};
+use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex, preg_is_match};
#[derive(Debug)]
pub struct VcsDriverBase {
@@ -56,7 +56,7 @@ impl VcsDriverBase {
}
pub fn should_cache(&self, identifier: &str) -> bool {
- self.cache.is_some() && preg_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier).is_some()
+ self.cache.is_some() && preg_is_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier)
}
pub fn get_scheme(&self) -> &str {
@@ -201,7 +201,7 @@ pub trait VcsDriver: VcsDriverInterface {
fn cache_mut(&mut self) -> Option<&mut Cache>;
fn should_cache(&self, identifier: &str) -> bool {
- self.cache().is_some() && preg_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier).is_some()
+ self.cache().is_some() && preg_is_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier)
}
fn get_composer_information(