aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-18 15:03:55 +0900
committernsfisis <nsfisis@gmail.com>2026-07-18 15:54:27 +0900
commit91692846909ed191addb7ec1c34aad11392ab88b (patch)
tree7c477055e432fd43a98e5dddc016e07dcfc67f60 /crates/shirabe/src/repository
parent4ae58baf8618f5fe916ba2a69faaca93514134ce (diff)
downloadphp-shirabe-91692846909ed191addb7ec1c34aad11392ab88b.tar.gz
php-shirabe-91692846909ed191addb7ec1c34aad11392ab88b.tar.zst
php-shirabe-91692846909ed191addb7ec1c34aad11392ab88b.zip
perf(regex): eliminate per-call clone overhead in preg_* dispatch
regex::Regex::clone() does not share the underlying meta engine's search-cache pool, so every fresh clone pays a ~10us warmup cost on its first use. Two changes together eliminate this across nearly all preg_* call sites: - A php_regex! macro resolves PHP-style patterns to a per-call-site &'static regex::Regex (via regex-macro's LazyLock), applied at the majority of call sites throughout the codebase. - Call sites still passing dynamic pattern strings go through PATTERN_CACHE, which now stores Arc<(Regex, bool)> and hands out Arc::clone()s instead of cloning the Regex itself. PregPattern::resolve() returns a ResolvedPattern enum (Arc or 'static reference) rather than an owned Regex, so neither path ever clones the Regex proper. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
-rw-r--r--crates/shirabe/src/repository/array_repository.rs6
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs25
-rw-r--r--crates/shirabe/src/repository/filesystem_repository.rs4
-rw-r--r--crates/shirabe/src/repository/package_repository.rs8
-rw-r--r--crates/shirabe/src/repository/path_repository.rs6
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs95
-rw-r--r--crates/shirabe/src/repository/repository_factory.rs6
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/fossil_driver.rs12
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs8
-rw-r--r--crates/shirabe/src/repository/vcs/git_driver.rs16
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs47
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs14
-rw-r--r--crates/shirabe/src/repository/vcs/hg_driver.rs27
-rw-r--r--crates/shirabe/src/repository/vcs/perforce_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs34
-rw-r--r--crates/shirabe/src/repository/vcs/vcs_driver.rs6
-rw-r--r--crates/shirabe/src/repository/vcs_repository.rs10
18 files changed, 202 insertions, 130 deletions
diff --git a/crates/shirabe/src/repository/array_repository.rs b/crates/shirabe/src/repository/array_repository.rs
index 6f5e4194..ba085020 100644
--- a/crates/shirabe/src/repository/array_repository.rs
+++ b/crates/shirabe/src/repository/array_repository.rs
@@ -13,7 +13,7 @@ use crate::repository::{
};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{implode, preg_quote, strtolower};
+use shirabe_php_shim::{implode, php_regex, preg_quote, strtolower};
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::SimpleConstraint;
use std::rc::Weak;
@@ -329,11 +329,11 @@ impl RepositoryInterface for ArrayRepository {
r#type: Option<String>,
) -> anyhow::Result<Vec<SearchResult>> {
let regex = if mode == crate::repository::SEARCH_FULLTEXT {
- let parts = Preg::split("{\\s+}", &preg_quote(&query, None));
+ let parts = Preg::split(php_regex!("{\\s+}"), &preg_quote(&query, None));
format!("{{(?:{})}}i", implode("|", &parts))
} else {
// vendor/name searches expect the caller to have preg_quoted the query
- let parts = Preg::split("{\\s+}", &query);
+ let parts = Preg::split(php_regex!("{\\s+}"), &query);
format!("{{(?:{})}}i", implode("|", &parts))
};
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index fc576189..54edc39a 100644
--- a/crates/shirabe/src/repository/composer_repository.rs
+++ b/crates/shirabe/src/repository/composer_repository.rs
@@ -41,7 +41,7 @@ use shirabe_metadata_minifier::MetadataMinifier;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, RuntimeException,
UnexpectedValueException, extension_loaded, hash, http_build_query, in_array, json_decode,
- parse_url_all, realpath, strtolower, strtr, urlencode, var_export,
+ parse_url_all, php_regex, realpath, strtolower, strtr, urlencode, var_export,
};
use shirabe_semver::CompilingMatcher;
use shirabe_semver::constraint::AnyConstraint;
@@ -160,7 +160,7 @@ impl ComposerRepository {
.and_then(|v| v.as_string())
.unwrap_or("")
.to_string();
- if !Preg::is_match(r"{^[\w.]+\??://}", &url_str) {
+ if !Preg::is_match(php_regex!(r"{^[\w.]+\??://}"), &url_str) {
if let Some(local_file_path) = realpath(&url_str) {
// it is a local path, add file scheme
repo_config.insert(
@@ -247,7 +247,7 @@ impl ComposerRepository {
// force url for packagist.org to repo.packagist.org
let mut match_packagist: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- r"{^(?P<proto>https?)://packagist\.org/?$}i",
+ php_regex!(r"{^(?P<proto>https?)://packagist\.org/?$}i"),
&url,
Some(&mut match_packagist),
) {
@@ -258,7 +258,8 @@ impl ComposerRepository {
url = format!("{}://repo.packagist.org", proto);
}
- let base_url_trimmed = Preg::replace(r"{(?:/[^/\\]+\.json)?(?:[?#].*)?$}", "", &url);
+ let base_url_trimmed =
+ Preg::replace(php_regex!(r"{(?:/[^/\\]+\.json)?(?:[?#].*)?$}"), "", &url);
let base_url = base_url_trimmed.trim_end_matches('/').to_string();
assert!(!base_url.is_empty());
@@ -772,7 +773,7 @@ impl ComposerRepository {
if mode == SEARCH_VENDOR {
let mut results: Vec<IndexMap<String, PhpMixed>> = Vec::new();
- let parts = Preg::split(r"{\s+}", &query);
+ let parts = Preg::split(php_regex!(r"{\s+}"), &query);
let regex = format!("{{(?:{})}}i", parts.join("|"));
let vendor_names = self.get_vendor_names()?;
@@ -791,7 +792,7 @@ impl ComposerRepository {
// optimize search for "^foo/bar" where at least "^foo/" is present by loading this directly from the listUrl if present
let mut match_groups: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- r"{^\^(?P<query>(?P<vendor>[a-z0-9_.-]+)/[a-z0-9_.-]*)\*?$}i",
+ php_regex!(r"{^\^(?P<query>(?P<vendor>[a-z0-9_.-]+)/[a-z0-9_.-]*)\*?$}i"),
&query,
Some(&mut match_groups),
) && let Some(list_url) = self.list_url.as_ref()
@@ -837,7 +838,7 @@ impl ComposerRepository {
}
let mut results: Vec<IndexMap<String, PhpMixed>> = Vec::new();
- let parts = Preg::split(r"{\s+}", &query);
+ let parts = Preg::split(php_regex!(r"{\s+}"), &query);
let regex = format!("{{(?:{})}}i", parts.join("|"));
let package_names = self.get_package_names(None)?;
@@ -1747,7 +1748,7 @@ impl ComposerRepository {
.into_iter()
.filter_map(|(name, constraint)| {
let name = strtolower(&name);
- let real_name = Preg::replace(r"{~dev$}", "", &name);
+ let real_name = Preg::replace(php_regex!(r"{~dev$}"), "", &name);
// skip platform packages, root package and composer-plugin-api
if PlatformRepository::is_platform_package(&real_name) || real_name == "__root__" {
None
@@ -2435,7 +2436,11 @@ impl ComposerRepository {
if url.starts_with('/') {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^[^:]++://[^/]*+}", &self.url, Some(&mut matches)) {
+ if Preg::is_match3(
+ php_regex!(r"{^[^:]++://[^/]*+}"),
+ &self.url,
+ Some(&mut matches),
+ ) {
return Ok(format!(
"{}{}",
matches
@@ -2732,7 +2737,7 @@ impl ComposerRepository {
// url-encode $ signs in URLs as bad proxies choke on them
if let Some(pos) = filename.find('$')
&& pos > 0
- && Preg::is_match(r"{^https?://}i", &filename)
+ && Preg::is_match(php_regex!(r"{^https?://}i"), &filename)
{
filename = format!("{}%24{}", &filename[..pos], &filename[pos + 1..]);
}
diff --git a/crates/shirabe/src/repository/filesystem_repository.rs b/crates/shirabe/src/repository/filesystem_repository.rs
index 7d59bb0e..c2b23b52 100644
--- a/crates/shirabe/src/repository/filesystem_repository.rs
+++ b/crates/shirabe/src/repository/filesystem_repository.rs
@@ -23,7 +23,7 @@ use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
Exception, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException,
array_flip, dirname, r#eval, file_get_contents, get_class_err, get_debug_type, in_array,
- is_array, is_null, is_string, ksort, realpath, str_repeat, trim, usort, var_export,
+ is_array, is_null, is_string, ksort, php_regex, realpath, str_repeat, trim, usort, var_export,
};
use shirabe_semver::constraint::AnyConstraint;
@@ -356,7 +356,7 @@ impl FilesystemRepository {
let mixed = PhpMixed::String(data.clone());
if is_string(&mixed) && Preg::is_match(pattern, &trim(&data, None)) {
let replaced = Preg::replace(
- r#"{=>\s*+__DIR__\s*+\.\s*+(['\"])}"#,
+ php_regex!(r#"{=>\s*+__DIR__\s*+\.\s*+(['\"])}"#),
&format!(
"=> {} . $1",
var_export(&PhpMixed::String(dirname(path)), true),
diff --git a/crates/shirabe/src/repository/package_repository.rs b/crates/shirabe/src/repository/package_repository.rs
index 0973332d..7f61bc9e 100644
--- a/crates/shirabe/src/repository/package_repository.rs
+++ b/crates/shirabe/src/repository/package_repository.rs
@@ -16,7 +16,7 @@ use crate::repository::{
};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{Exception, PhpMixed, RuntimeException, var_export};
+use shirabe_php_shim::{Exception, PhpMixed, RuntimeException, php_regex, var_export};
use shirabe_semver::constraint::AnyConstraint;
#[derive(Debug)]
@@ -85,7 +85,11 @@ impl PackageRepository {
pub fn get_repo_name(&self) -> String {
use crate::repository::RepositoryInterface;
- Preg::replace(r"{^array }", "package ", &self.inner.get_repo_name())
+ Preg::replace(
+ php_regex!(r"{^array }"),
+ "package ",
+ &self.inner.get_repo_name(),
+ )
}
// In PHP the inherited ArrayRepository methods lazily call the overridden initialize() to load
diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs
index 8249bb90..d7f24fa7 100644
--- a/crates/shirabe/src/repository/path_repository.rs
+++ b/crates/shirabe/src/repository/path_repository.rs
@@ -26,7 +26,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
DIRECTORY_SEPARATOR, GLOB_BRACE, GLOB_MARK, GLOB_ONLYDIR, PhpMixed, RuntimeException, defined,
- file_exists, file_get_contents, glob_with_flags, hash, realpath, serialize,
+ file_exists, file_get_contents, glob_with_flags, hash, php_regex, realpath, serialize,
};
#[derive(Debug)]
@@ -161,9 +161,9 @@ impl PathRepository {
let url_matches = self.get_url_matches()?;
if url_matches.is_empty() {
- if Preg::is_match(r"{[*{}]}", &self.url) {
+ if Preg::is_match(php_regex!(r"{[*{}]}"), &self.url) {
let mut url = self.url.clone();
- while Preg::is_match(r"{[*{}]}", &url) {
+ while Preg::is_match(php_regex!(r"{[*{}]}"), &url) {
url = shirabe_php_shim::dirname(&url);
}
// the parent directory before any wildcard exists, so we assume it is correctly configured but simply empty
diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs
index 73c4dbea..0d63940c 100644
--- a/crates/shirabe/src/repository/platform_repository.rs
+++ b/crates/shirabe/src/repository/platform_repository.rs
@@ -23,7 +23,7 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::composer::xdebug_handler::XdebugHandler;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, UnexpectedValueException, array_map_str_fn,
- array_slice_strs, explode, get_class, implode, in_array, is_string, str_replace,
+ array_slice_strs, explode, get_class, implode, in_array, is_string, php_regex, str_replace,
str_starts_with, strpos, strtolower, var_export,
};
use shirabe_semver::constraint::SimpleConstraint;
@@ -223,7 +223,8 @@ impl PlatformRepository {
version = v;
}
Err(_) => {
- pretty_version = Preg::replace("#^([^~+-]+).*$#", "$1", &php_version_str);
+ pretty_version =
+ Preg::replace(php_regex!("#^([^~+-]+).*$#"), "$1", &php_version_str);
version = self
.version_parser
.as_ref()
@@ -344,7 +345,7 @@ impl PlatformRepository {
// librabbitmq version => 0.9.0
let mut librabbitmq_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^librabbitmq version => (?<version>.+)$/im",
+ php_regex!("/^librabbitmq version => (?<version>.+)$/im"),
&info,
Some(&mut librabbitmq_matches),
) {
@@ -363,7 +364,7 @@ impl PlatformRepository {
// AMQP protocol version => 0-9-1
let mut protocol_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^AMQP protocol version => (?<version>.+)$/im",
+ php_regex!("/^AMQP protocol version => (?<version>.+)$/im"),
&info,
Some(&mut protocol_matches),
) {
@@ -388,7 +389,7 @@ impl PlatformRepository {
// BZip2 Version => 1.0.6, 6-Sept-2010
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^BZip2 Version => (?<version>.*),/im",
+ php_regex!("/^BZip2 Version => (?<version>.*),/im"),
&info,
Some(&mut matches),
) {
@@ -423,7 +424,7 @@ impl PlatformRepository {
// SSL Version => OpenSSL/1.0.1t
let mut ssl_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "{^SSL Version => (?<library>[^/]+)/(?<version>.+)$}im",
+ php_regex!("{^SSL Version => (?<library>[^/]+)/(?<version>.+)$}im"),
&info,
Some(&mut ssl_matches),
) {
@@ -459,7 +460,7 @@ impl PlatformRepository {
let mut securetransport_matches: IndexMap<CaptureKey, String> =
IndexMap::new();
if Preg::is_match3(
- "{^\\(securetransport\\) ([a-z0-9]+)}",
+ php_regex!("{^\\(securetransport\\) ([a-z0-9]+)}"),
&library,
Some(&mut securetransport_matches),
) {
@@ -491,7 +492,9 @@ impl PlatformRepository {
// libSSH Version => libssh2/1.4.3
let mut ssh_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "{^libSSH Version => (?<library>[^/]+)/(?<version>.+?)(?:/.*)?$}im",
+ php_regex!(
+ "{^libSSH Version => (?<library>[^/]+)/(?<version>.+?)(?:/.*)?$}im"
+ ),
&info,
Some(&mut ssh_matches),
) {
@@ -516,7 +519,7 @@ impl PlatformRepository {
// ZLib Version => 1.2.8
let mut zlib_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "{^ZLib Version => (?<version>.+)$}im",
+ php_regex!("{^ZLib Version => (?<version>.+)$}im"),
&info,
Some(&mut zlib_matches),
) {
@@ -539,7 +542,7 @@ impl PlatformRepository {
// timelib version => 2018.03
let mut timelib_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^timelib version => (?<version>.+)$/im",
+ php_regex!("/^timelib version => (?<version>.+)$/im"),
&info,
Some(&mut timelib_matches),
) {
@@ -558,7 +561,7 @@ impl PlatformRepository {
// Timezone Database => internal
let mut zoneinfo_source_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^Timezone Database => (?<source>internal|external)$/im",
+ php_regex!("/^Timezone Database => (?<source>internal|external)$/im"),
&info,
Some(&mut zoneinfo_source_matches),
) {
@@ -568,7 +571,9 @@ impl PlatformRepository {
.unwrap_or(false);
let mut zoneinfo_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^\"Olson\" Timezone Database Version => (?<version>.+?)(?:\\.system)?$/im",
+ php_regex!(
+ "/^\"Olson\" Timezone Database Version => (?<version>.+?)(?:\\.system)?$/im"
+ ),
&info,
Some(&mut zoneinfo_matches),
) {
@@ -608,7 +613,7 @@ impl PlatformRepository {
// libmagic => 537
let mut magic_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libmagic => (?<version>.+)$/im",
+ php_regex!("/^libmagic => (?<version>.+)$/im"),
&info,
Some(&mut magic_matches),
) {
@@ -644,7 +649,7 @@ impl PlatformRepository {
let mut libjpeg_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libJPEG Version => (?<version>.+?)(?: compatible)?$/im",
+ php_regex!("/^libJPEG Version => (?<version>.+?)(?: compatible)?$/im"),
&info,
Some(&mut libjpeg_matches),
) {
@@ -665,7 +670,7 @@ impl PlatformRepository {
let mut libpng_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libPNG Version => (?<version>.+)$/im",
+ php_regex!("/^libPNG Version => (?<version>.+)$/im"),
&info,
Some(&mut libpng_matches),
) {
@@ -683,7 +688,7 @@ impl PlatformRepository {
let mut freetype_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^FreeType Version => (?<version>.+)$/im",
+ php_regex!("/^FreeType Version => (?<version>.+)$/im"),
&info,
Some(&mut freetype_matches),
) {
@@ -701,7 +706,7 @@ impl PlatformRepository {
let mut libxpm_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libXpm Version => (?<versionId>\\d+)$/im",
+ php_regex!("/^libXpm Version => (?<versionId>\\d+)$/im"),
&info,
Some(&mut libxpm_matches),
) {
@@ -775,7 +780,7 @@ impl PlatformRepository {
} else {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^ICU version => (?<version>.+)$/im",
+ php_regex!("/^ICU version => (?<version>.+)$/im"),
&info,
Some(&mut matches),
) {
@@ -795,7 +800,7 @@ impl PlatformRepository {
// ICU TZData version => 2019c
let mut zoneinfo_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^ICU TZData version => (?<version>.*)$/im",
+ php_regex!("/^ICU TZData version => (?<version>.*)$/im"),
&info,
Some(&mut zoneinfo_matches),
) {
@@ -878,7 +883,7 @@ impl PlatformRepository {
// 7.x: ImageMagick 7.0.8-34 Q16 x86_64 2019-03-23 https://imagemagick.org
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^ImageMagick (?<version>[\\d.]+)(?:-(?<patch>\\d+))?/",
+ php_regex!("/^ImageMagick (?<version>[\\d.]+)(?:-(?<patch>\\d+))?/"),
&image_magick_version_str,
Some(&mut matches),
) {
@@ -907,11 +912,11 @@ impl PlatformRepository {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
let mut vendor_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^Vendor Version => (?<versionId>\\d+)$/im",
+ php_regex!("/^Vendor Version => (?<versionId>\\d+)$/im"),
&info,
Some(&mut matches),
) && Preg::is_match3(
- "/^Vendor Name => (?<vendor>.+)$/im",
+ php_regex!("/^Vendor Name => (?<vendor>.+)$/im"),
&info,
Some(&mut vendor_matches),
) {
@@ -966,7 +971,7 @@ impl PlatformRepository {
// libmbfl version => 1.3.2
let mut libmbfl_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libmbfl version => (?<version>.+)$/im",
+ php_regex!("/^libmbfl version => (?<version>.+)$/im"),
&info,
Some(&mut libmbfl_matches),
) {
@@ -1002,7 +1007,9 @@ impl PlatformRepository {
} else {
let mut oniguruma_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^(?:oniguruma|Multibyte regex \\(oniguruma\\)) version => (?<version>.+)$/im",
+ php_regex!(
+ "/^(?:oniguruma|Multibyte regex \\(oniguruma\\)) version => (?<version>.+)$/im"
+ ),
&info,
Some(&mut oniguruma_matches),
) {
@@ -1026,7 +1033,7 @@ impl PlatformRepository {
// libmemcached version => 1.0.18
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libmemcached version => (?<version>.+)$/im",
+ php_regex!("/^libmemcached version => (?<version>.+)$/im"),
&info,
Some(&mut matches),
) {
@@ -1052,7 +1059,7 @@ impl PlatformRepository {
// OpenSSL 1.1.1g 21 Apr 2020
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "{^(?:OpenSSL|LibreSSL)?\\s*(?<version>\\S+)}i",
+ php_regex!("{^(?:OpenSSL|LibreSSL)?\\s*(?<version>\\S+)}i"),
&openssl_text_str,
Some(&mut matches),
) {
@@ -1084,7 +1091,8 @@ impl PlatformRepository {
PhpMixed::String(s) => s.clone(),
_ => "".to_string(),
};
- let stripped = Preg::replace("{^(\\S+).*}", "$1", &pcre_version_str);
+ let stripped =
+ Preg::replace(php_regex!("{^(\\S+).*}"), "$1", &pcre_version_str);
self.add_library(&mut libraries, name, Some(&stripped), None, &[], &[])?;
let info = self.runtime.get_extension_info(name)?;
@@ -1092,7 +1100,7 @@ impl PlatformRepository {
// PCRE Unicode Version => 12.1.0
let mut pcre_unicode_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^PCRE Unicode Version => (?<version>.+)$/im",
+ php_regex!("/^PCRE Unicode Version => (?<version>.+)$/im"),
&info,
Some(&mut pcre_unicode_matches),
) {
@@ -1114,7 +1122,9 @@ impl PlatformRepository {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^(?:Client API version|Version) => mysqlnd (?<version>.+?) /mi",
+ php_regex!(
+ "/^(?:Client API version|Version) => mysqlnd (?<version>.+?) /mi"
+ ),
&info,
Some(&mut matches),
) {
@@ -1136,7 +1146,7 @@ impl PlatformRepository {
let mut libmongoc_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libmongoc bundled version => (?<version>.+)$/im",
+ php_regex!("/^libmongoc bundled version => (?<version>.+)$/im"),
&info,
Some(&mut libmongoc_matches),
) {
@@ -1154,7 +1164,7 @@ impl PlatformRepository {
let mut libbson_matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libbson bundled version => (?<version>.+)$/im",
+ php_regex!("/^libbson bundled version => (?<version>.+)$/im"),
&info,
Some(&mut libbson_matches),
) {
@@ -1192,7 +1202,7 @@ impl PlatformRepository {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im",
+ php_regex!("/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im"),
&info,
Some(&mut matches),
) {
@@ -1215,7 +1225,7 @@ impl PlatformRepository {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im",
+ php_regex!("/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im"),
&info,
Some(&mut matches),
) {
@@ -1239,7 +1249,7 @@ impl PlatformRepository {
// libpq => 14.3 (Ubuntu 14.3-1.pgdg22.04+1) => 15.0.2
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libpq => (?<compiled>.+) => (?<linked>.+)$/im",
+ php_regex!("/^libpq => (?<compiled>.+) => (?<linked>.+)$/im"),
&info,
Some(&mut matches),
) {
@@ -1318,7 +1328,7 @@ impl PlatformRepository {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^SQLite Library => (?<version>.+)$/im",
+ php_regex!("/^SQLite Library => (?<version>.+)$/im"),
&info,
Some(&mut matches),
) {
@@ -1340,7 +1350,7 @@ impl PlatformRepository {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libssh2 version => (?<version>.+)$/im",
+ php_regex!("/^libssh2 version => (?<version>.+)$/im"),
&info,
Some(&mut matches),
) {
@@ -1375,7 +1385,9 @@ impl PlatformRepository {
let info = self.runtime.get_extension_info("xsl")?;
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^libxslt compiled against libxml Version => (?<version>.+)$/im",
+ php_regex!(
+ "/^libxslt compiled against libxml Version => (?<version>.+)$/im"
+ ),
&info,
Some(&mut matches),
) {
@@ -1397,7 +1409,7 @@ impl PlatformRepository {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^LibYAML Version => (?<version>.+)$/im",
+ php_regex!("/^LibYAML Version => (?<version>.+)$/im"),
&info,
Some(&mut matches),
) {
@@ -1458,7 +1470,7 @@ impl PlatformRepository {
let info = self.runtime.get_extension_info(name)?;
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "/^Linked Version => (?<version>.+)$/im",
+ php_regex!("/^Linked Version => (?<version>.+)$/im"),
&info,
Some(&mut matches),
) {
@@ -1494,7 +1506,8 @@ impl PlatformRepository {
version = v;
}
Err(_) => {
- pretty_version = Preg::replace("#^([^~+-]+).*$#", "$1", &hhvm_version);
+ pretty_version =
+ Preg::replace(php_regex!("#^([^~+-]+).*$#"), "$1", &hhvm_version);
version = self
.version_parser
.as_ref()
@@ -1655,7 +1668,7 @@ impl PlatformRepository {
extra_description = Some(format!(" (actual version: {})", pretty_version));
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
- "{^(\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)}",
+ php_regex!("{^(\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)}"),
&pretty_version,
Some(&mut m),
) {
diff --git a/crates/shirabe/src/repository/repository_factory.rs b/crates/shirabe/src/repository/repository_factory.rs
index 23766bf1..972a5161 100644
--- a/crates/shirabe/src/repository/repository_factory.rs
+++ b/crates/shirabe/src/repository/repository_factory.rs
@@ -15,7 +15,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, UnexpectedValueException, get_debug_type, json_encode,
- php_to_string,
+ php_regex, php_to_string,
};
pub struct RepositoryFactory;
@@ -320,7 +320,7 @@ impl RepositoryFactory {
) -> String {
let mut name = if matches!(index, PhpMixed::Int(_)) && repo.contains_key("url") {
let url = repo.get("url").and_then(|v| v.as_string()).unwrap_or("");
- Preg::replace("{^https?://}i", "", url)
+ Preg::replace(php_regex!("{^https?://}i"), "", url)
} else {
php_to_string(index)
};
@@ -336,7 +336,7 @@ impl RepositoryFactory {
existing_repos: &IndexMap<String, RepositoryInterfaceHandle>,
) -> String {
let mut name = if let Some(url) = repo.get("url").and_then(|v| v.as_string()) {
- Preg::replace("{^https?://}i", "", url)
+ Preg::replace(php_regex!("{^https?://}i"), "", url)
} else {
index.to_string()
};
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
index 0c7e201f..49d0dcf1 100644
--- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs
+++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
@@ -17,7 +17,7 @@ use crate::util::http::Response;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, urlencode,
+ PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, urlencode,
};
#[derive(Debug)]
@@ -585,7 +585,7 @@ impl ForgejoDriver {
let links = explode(",", &header);
for link in links {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r#"{<(.+?)>; *rel="next"}"#, &link, Some(&mut m))
+ if Preg::match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link, Some(&mut m))
&& let Some(url) = m.get(&CaptureKey::ByIndex(1))
{
return Some(url.clone());
diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs
index cf9a2ea0..a75f6874 100644
--- a/crates/shirabe/src/repository/vcs/fossil_driver.rs
+++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs
@@ -12,7 +12,9 @@ use crate::util::ProcessExecutor;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable};
+use shirabe_php_shim::{
+ PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex,
+};
#[derive(Debug)]
pub struct FossilDriver {
@@ -82,7 +84,7 @@ impl FossilDriver {
.into());
}
- let local_name = Preg::replace(r"{[^a-z0-9]}i", "-", &self.inner.url);
+ let local_name = Preg::replace(php_regex!(r"{[^a-z0-9]}i"), "-", &self.inner.url);
self.repo_file = Some(format!("{}/{}.fossil", cache_repo_dir, local_name));
self.checkout_dir = format!("{}/{}/", cache_vcs_dir, local_name);
@@ -301,7 +303,7 @@ impl FossilDriver {
Some(&self.checkout_dir),
);
for branch in self.inner.process.borrow().split_lines(&output) {
- let branch = Preg::replace(r"/^\*/", "", branch.trim());
+ let branch = Preg::replace(php_regex!(r"/^\*/"), "", branch.trim());
let branch = branch.trim().to_string();
branches.insert(branch.clone(), branch);
}
@@ -317,13 +319,13 @@ impl FossilDriver {
deep: bool,
) -> anyhow::Result<bool> {
if Preg::is_match(
- r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i",
+ php_regex!(r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i"),
url,
) {
return Ok(true);
}
- if Preg::is_match(r"!/fossil/|\.fossil!", url) {
+ 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 875945af..546dc72d 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_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_key_exists,
array_search_mixed, extension_loaded, http_build_query_mixed, implode, in_array, is_array,
- strpos,
+ php_regex, strpos,
};
#[derive(Debug)]
@@ -86,7 +86,7 @@ impl GitBitbucketDriver {
pub fn initialize(&mut self) -> anyhow::Result<()> {
let mut m: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new();
if !Preg::is_match3(
- r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(?:\.git|/?)?$#i",
+ php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(?:\.git|/?)?$#i"),
&self.inner.url,
Some(&mut m),
) {
@@ -788,7 +788,7 @@ impl GitBitbucketDriver {
// Format: https://(user@)bitbucket.org/{user}/{repo}
// Strip username from URL (only present in clone URL's for private repositories)
self.clone_https_url = Preg::replace(
- r"/https:\/\/([^@]+@)?/",
+ php_regex!(r"/https:\/\/([^@]+@)?/"),
"https://",
m.get("href").and_then(|v| v.as_string()).unwrap_or(""),
);
@@ -850,7 +850,7 @@ impl GitBitbucketDriver {
_deep: bool,
) -> anyhow::Result<bool> {
if !Preg::is_match(
- r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i",
+ php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i"),
url,
) {
return Ok(false);
diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs
index 81110335..22691b0c 100644
--- a/crates/shirabe/src/repository/vcs/git_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_driver.rs
@@ -15,11 +15,11 @@ use chrono::TimeZone;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::PhpMixed;
use shirabe_php_shim::{
InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, realpath,
sys_get_temp_dir,
};
+use shirabe_php_shim::{PhpMixed, php_regex};
#[derive(Debug)]
pub struct GitDriver {
@@ -50,7 +50,7 @@ impl GitDriver {
pub fn initialize(&mut self) -> anyhow::Result<()> {
let cache_url;
if Filesystem::is_local_path(&self.inner.url) {
- self.inner.url = Preg::replace(r"{[\\/]\.git/?$}", "", &self.inner.url);
+ self.inner.url = Preg::replace(php_regex!(r"{[\\/]\.git/?$}"), "", &self.inner.url);
if !is_dir(&self.inner.url) {
return Err(RuntimeException {
message: format!(
@@ -107,7 +107,7 @@ impl GitDriver {
.into());
}
- if Preg::is_match(r"{^ssh://[^@]+@[^:]+:[^0-9]+}", &self.inner.url) {
+ if Preg::is_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), &self.inner.url) {
return Err(InvalidArgumentException {
message: 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.",
@@ -214,7 +214,7 @@ impl GitDriver {
for branch in &branches {
if !branch.is_empty() {
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"{^\* +(\S+)}", branch, Some(&mut caps))
+ if Preg::match3(php_regex!(r"{^\* +(\S+)}"), branch, Some(&mut caps))
&& let Some(name) = caps.get(&CaptureKey::ByIndex(1))
{
self.root_identifier = Some(name.clone());
@@ -333,7 +333,7 @@ impl GitDriver {
if !tag.is_empty() {
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::match3(
- r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}",
+ php_regex!(r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}"),
&tag,
Some(&mut caps),
) && let (Some(hash), Some(name)) = (
@@ -369,10 +369,10 @@ impl GitDriver {
Some(&self.repo_dir),
);
for branch in self.inner.process.borrow().split_lines(&output) {
- if !branch.is_empty() && !Preg::is_match(r"{^ *[^/]+/HEAD }", &branch) {
+ if !branch.is_empty() && !Preg::is_match(php_regex!(r"{^ *[^/]+/HEAD }"), &branch) {
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::match3(
- r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}",
+ php_regex!(r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}"),
&branch,
Some(&mut caps),
) && let (Some(name), Some(hash)) = (
@@ -398,7 +398,7 @@ impl GitDriver {
deep: bool,
) -> anyhow::Result<bool> {
if Preg::is_match(
- r"#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i",
+ php_regex!(r"#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i"),
url,
) {
return Ok(true);
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs
index 3ee38f27..37bba1c7 100644
--- a/crates/shirabe/src/repository/vcs/github_driver.rs
+++ b/crates/shirabe/src/repository/vcs/github_driver.rs
@@ -18,7 +18,7 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_key_exists, array_map,
array_search_mixed, base64_decode, basename, empty, explode, extension_loaded, in_array,
- parse_url_all, strpos, strtolower, substr, trim, urlencode,
+ parse_url_all, php_regex, strpos, strtolower, substr, trim, urlencode,
};
#[derive(Debug)]
@@ -71,7 +71,9 @@ impl GitHubDriver {
pub fn initialize(&mut self) -> anyhow::Result<()> {
let mut match_: IndexMap<CaptureKey, String> = IndexMap::new();
if !Preg::is_match3(
- r"#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#",
+ php_regex!(
+ r"#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#"
+ ),
&self.inner.url,
Some(&mut match_),
) {
@@ -494,10 +496,10 @@ impl GitHubDriver {
let mut result: Vec<IndexMap<String, PhpMixed>> = vec![];
let mut key: Option<String> = None;
- for line in Preg::split(r"{\r?\n}", &funding) {
+ for line in Preg::split(php_regex!(r"{\r?\n}"), &funding) {
let line = trim(&line, None);
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^(\w+)\s*:\s*(.+)$}", &line, Some(&mut m)) {
+ if Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line, Some(&mut m)) {
let g1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let g2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
if g2 == "[" {
@@ -505,11 +507,11 @@ impl GitHubDriver {
continue;
}
let mut m2: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\[(.*?)\](?:\s*#.*)?$}", &g2, Some(&mut m2)) {
+ if Preg::is_match3(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2, Some(&mut m2)) {
let inner = m2.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
for item in array_map(
|s: &String| trim(s, None),
- &Preg::split(r#"{[\'\"]?\s*,\s*[\'\"]?}"#, &inner),
+ &Preg::split(php_regex!(r#"{[\'\"]?\s*,\s*[\'\"]?}"#), &inner),
) {
let mut entry = IndexMap::new();
entry.insert("type".to_string(), PhpMixed::String(g1.clone()));
@@ -519,7 +521,11 @@ impl GitHubDriver {
);
result.push(entry);
}
- } else if Preg::is_match3(r"{^([^#].*?)(?:\s+#.*)?$}", &g2, Some(&mut m2)) {
+ } else if Preg::is_match3(
+ php_regex!(r"{^([^#].*?)(?:\s+#.*)?$}"),
+ &g2,
+ Some(&mut m2),
+ ) {
let mut entry = IndexMap::new();
entry.insert("type".to_string(), PhpMixed::String(g1.clone()));
entry.insert(
@@ -532,15 +538,16 @@ impl GitHubDriver {
result.push(entry);
}
key = None;
- } else if Preg::is_match3(r"{^(\w+)\s*:\s*#\s*$}", &line, Some(&mut m)) {
+ } else if Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line, Some(&mut m)) {
key = Some(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default());
} else if key.is_some() && {
let mut tmp: IndexMap<CaptureKey, String> = IndexMap::new();
- Preg::is_match3(r"{^-\s*(.+)(?:\s+#.*)?$}", &line, Some(&mut m))
- || Preg::is_match3(r"{^(.+),(?:\s*#.*)?$}", &line, Some(&mut tmp)) && {
- m = tmp;
- true
- }
+ Preg::is_match3(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line, Some(&mut m))
+ || Preg::is_match3(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line, Some(&mut tmp))
+ && {
+ m = tmp;
+ true
+ }
} {
let mut entry = IndexMap::new();
entry.insert(
@@ -675,7 +682,7 @@ impl GitHubDriver {
if !array_key_exists("scheme", &bits_map)
&& !array_key_exists("host", &bits_map)
{
- if Preg::is_match(r"{^[a-z0-9-]++\.[a-z]{2,3}$}", &item_url) {
+ 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)),
@@ -941,7 +948,9 @@ impl GitHubDriver {
) -> anyhow::Result<bool> {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if !Preg::is_match3(
- r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#",
+ php_regex!(
+ r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#"
+ ),
url,
Some(&mut matches),
) {
@@ -959,7 +968,11 @@ impl GitHubDriver {
.unwrap_or_default()
});
if !in_array(
- PhpMixed::String(strtolower(&Preg::replace(r"{^www\.}i", "", &origin_url))),
+ PhpMixed::String(strtolower(&Preg::replace(
+ php_regex!(r"{^www\.}i"),
+ "",
+ &origin_url,
+ ))),
&config.borrow().get("github-domains"),
false,
) {
@@ -1294,7 +1307,7 @@ impl GitHubDriver {
let links = explode(",", &header);
for link in &links {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r#"{<(.+?)>; *rel="next"}"#, link, Some(&mut m)) {
+ if Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, Some(&mut m)) {
return Some(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default());
}
}
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index 4ad75b64..b1cfd004 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_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed,
array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array, is_array,
- is_string, ord, strpos, strtolower,
+ is_string, ord, php_regex, strpos, strtolower,
};
/// Driver for GitLab API, use the Git driver for local checkouts.
@@ -193,7 +193,7 @@ impl GitLabDriver {
self.namespace = implode("/", &url_parts);
self.repository = Preg::replace(
- r"#(\.git)$#",
+ php_regex!(r"#(\.git)$#"),
"",
&match_
.get(&CaptureKey::ByName("repo".to_string()))
@@ -426,7 +426,7 @@ impl GitLabDriver {
// Convert the root identifier to a cacheable commit id
let mut identifier = identifier.to_string();
- if !Preg::is_match(r"{[a-f0-9]{40}}i", &identifier) {
+ 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();
@@ -1048,7 +1048,11 @@ impl GitLabDriver {
let links = explode(",", &header);
for link in &links {
let mut match_: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r#"{<(.+?)>; *rel="next"}"#, link, Some(&mut match_)) {
+ if Preg::is_match3(
+ php_regex!(r#"{<(.+?)>; *rel="next"}"#),
+ link,
+ Some(&mut match_),
+ ) {
return Some(
match_
.get(&CaptureKey::ByIndex(1))
@@ -1108,7 +1112,7 @@ impl GitLabDriver {
false,
) || (port_number.is_some()
&& in_array(
- PhpMixed::String(Preg::replace(r"{:\d+}", "", &guessed_domain)),
+ PhpMixed::String(Preg::replace(php_regex!(r"{:\d+}"), "", &guessed_domain)),
configured_domains,
false,
))
diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs
index f987eb4b..a346094c 100644
--- a/crates/shirabe/src/repository/vcs/hg_driver.rs
+++ b/crates/shirabe/src/repository/vcs/hg_driver.rs
@@ -12,7 +12,7 @@ use crate::util::Url;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_writable};
+use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex};
#[derive(Debug)]
pub struct HgDriver {
@@ -59,8 +59,11 @@ impl HgDriver {
}.into());
}
- let sanitized =
- Preg::replace(r"{[^a-z0-9]}i", "-", &Url::sanitize(self.inner.url.clone()));
+ let sanitized = Preg::replace(
+ php_regex!(r"{[^a-z0-9]}i"),
+ "-",
+ &Url::sanitize(self.inner.url.clone()),
+ );
self.repo_dir = format!("{}/{}/", cache_vcs_dir, sanitized);
let mut fs = Filesystem::new(None);
@@ -242,7 +245,7 @@ impl HgDriver {
for tag in self.inner.process.borrow().split_lines(&output) {
if !tag.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"(^([^\s]+)\s+\d+:(.*)$)", &tag, Some(&mut m)) {
+ if Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag, Some(&mut m)) {
tags.insert(
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(),
@@ -272,7 +275,11 @@ impl HgDriver {
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"(^([^\s]+)\s+\d+:([a-f0-9]+))", &branch, Some(&mut m)) {
+ if Preg::match3(
+ php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"),
+ &branch,
+ Some(&mut m),
+ ) {
let name = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
if !name.starts_with('-') {
branches.insert(
@@ -293,7 +300,11 @@ impl HgDriver {
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)", &branch, Some(&mut m)) {
+ if Preg::match3(
+ php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"),
+ &branch,
+ Some(&mut m),
+ ) {
let name = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
if !name.starts_with('-') {
bookmarks.insert(
@@ -320,7 +331,9 @@ impl HgDriver {
deep: bool,
) -> anyhow::Result<bool> {
if Preg::is_match(
- r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i",
+ php_regex!(
+ r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i"
+ ),
url,
) {
return Ok(true);
diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs
index 9a98f4d3..452ac5a2 100644
--- a/crates/shirabe/src/repository/vcs/perforce_driver.rs
+++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs
@@ -10,7 +10,7 @@ use crate::util::ProcessExecutor;
use crate::util::http::Response;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException};
+use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException, php_regex};
#[derive(Debug)]
pub struct PerforceDriver {
@@ -193,7 +193,7 @@ impl PerforceDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if deep || Preg::is_match(r"#\b(perforce|p4)\b#i", url) {
+ 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 50852aef..5f1faa65 100644
--- a/crates/shirabe/src/repository/vcs/svn_driver.rs
+++ b/crates/shirabe/src/repository/vcs/svn_driver.rs
@@ -15,7 +15,7 @@ use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- PhpMixed, RuntimeException, array_key_exists, stripos, strrpos, strtr, substr, trim,
+ PhpMixed, RuntimeException, array_key_exists, php_regex, stripos, strrpos, strtr, substr, trim,
};
#[derive(Debug)]
@@ -157,7 +157,7 @@ impl SvnDriver {
}
pub(crate) fn should_cache(&self, identifier: &str) -> bool {
- self.inner.cache.is_some() && Preg::is_match(r"{@\d+$}", identifier)
+ self.inner.cache.is_some() && Preg::is_match(php_regex!(r"{@\d+$}"), identifier)
}
pub fn get_composer_information(
@@ -262,7 +262,7 @@ impl SvnDriver {
let identifier = format!("/{}/", trim(identifier, Some("/")));
let (path, rev) = if let Some(m) =
- Preg::is_match_with_indexed_captures(r"{^(.+?)(@\d+)?/$}", &identifier)
+ Preg::is_match_with_indexed_captures(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier)
{
if m.get(2).is_some() {
(
@@ -302,7 +302,7 @@ impl SvnDriver {
let identifier = format!("/{}/", trim(identifier, Some("/")));
let (path, rev) = if let Some(m) =
- Preg::is_match_with_indexed_captures(r"{^(.+?)(@\d+)?/$}", &identifier)
+ Preg::is_match_with_indexed_captures(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier)
{
if m.get(2).is_some() {
(
@@ -323,7 +323,11 @@ impl SvnDriver {
for line in self.inner.process.borrow().split_lines(&output) {
if !line.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^Last Changed Date: ([^(]+)}", &line, Some(&mut m)) {
+ if Preg::is_match3(
+ php_regex!(r"{^Last Changed Date: ([^(]+)}"),
+ &line,
+ Some(&mut m),
+ ) {
let date_str = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
return Ok(shirabe_php_shim::date_create::<Utc>(date_str.trim())
.ok()
@@ -351,7 +355,11 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m)) {
+ if Preg::is_match3(
+ php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"),
+ &line,
+ Some(&mut m),
+ ) {
let rev: i64 = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -398,7 +406,11 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m)) {
+ if Preg::is_match3(
+ php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"),
+ &line,
+ Some(&mut m),
+ ) {
let rev: i64 = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -436,7 +448,11 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m)) {
+ if Preg::is_match3(
+ php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"),
+ &line,
+ Some(&mut m),
+ ) {
let rev: i64 = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -472,7 +488,7 @@ impl SvnDriver {
deep: bool,
) -> anyhow::Result<bool> {
let url = Self::normalize_url(url);
- if Preg::is_match(r"#(^svn://|^svn\+ssh://|svn\.)#i", &url) {
+ 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 1dce8567..5aa74959 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_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded};
+use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex};
#[derive(Debug)]
pub struct VcsDriverBase {
@@ -56,7 +56,7 @@ impl VcsDriverBase {
}
pub fn should_cache(&self, identifier: &str) -> bool {
- self.cache.is_some() && Preg::is_match("{^[a-f0-9]{40}$}iD", identifier)
+ self.cache.is_some() && Preg::is_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier)
}
pub fn get_scheme(&self) -> &str {
@@ -199,7 +199,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::is_match("{^[a-f0-9]{40}$}iD", identifier)
+ self.cache().is_some() && Preg::is_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier)
}
fn get_composer_information(
diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs
index 29702db3..c04b1b67 100644
--- a/crates/shirabe/src/repository/vcs_repository.rs
+++ b/crates/shirabe/src/repository/vcs_repository.rs
@@ -28,7 +28,9 @@ use crate::util::ProcessExecutor;
use crate::util::Url;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{InvalidArgumentException, PhpMixed, in_array, str_replace, strpos};
+use shirabe_php_shim::{
+ InvalidArgumentException, PhpMixed, in_array, php_regex, str_replace, strpos,
+};
use shirabe_semver::constraint::SimpleConstraint;
// TODO(phase-c): the driver registration should be refactored later.
@@ -479,7 +481,7 @@ impl VcsRepository {
data.insert(
"version".to_string(),
PhpMixed::String(Preg::replace(
- r"{[.-]?dev$}i",
+ php_regex!(r"{[.-]?dev$}i"),
"",
data.get("version")
.and_then(|v| v.as_string())
@@ -489,7 +491,7 @@ impl VcsRepository {
data.insert(
"version_normalized".to_string(),
PhpMixed::String(Preg::replace(
- r"{(^dev-|[.-]?dev$)}i",
+ php_regex!(r"{(^dev-|[.-]?dev$)}i"),
"",
data.get("version_normalized")
.and_then(|v| v.as_string())
@@ -509,7 +511,7 @@ impl VcsRepository {
// broken package, version doesn't match tag
if version_normalized != parsed_tag {
if is_very_verbose {
- if Preg::is_match(r"{(^dev-|[.-]?dev$)}i", &parsed_tag) {
+ if Preg::is_match(php_regex!(r"{(^dev-|[.-]?dev$)}i"), &parsed_tag) {
self.io.write_error(&format!(
"<warning>Skipped tag {}, invalid tag name, tags can not use dev prefixes or suffixes</warning>",
tag