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 | 530d085d4f3e19f94ac3cf8f8ac3b17000214b2e (patch) | |
| tree | b4de2c2443e2bb2cfc692454ac284dc1d2313e59 /crates/shirabe/src/repository/vcs | |
| parent | 0caac63bacefb9a1f62848636d47fca07f592bba (diff) | |
| download | php-shirabe-530d085d4f3e19f94ac3cf8f8ac3b17000214b2e.tar.gz php-shirabe-530d085d4f3e19f94ac3cf8f8ac3b17000214b2e.tar.zst php-shirabe-530d085d4f3e19f94ac3cf8f8ac3b17000214b2e.zip | |
refactor(pcre): inline Preg into its call sites and drop the crate
Preg had shed everything it owned: after the last few rounds its methods
were one-line forwards to the shim's preg_*(), differing only in a
default argument or a wrapper the caller unwrapped anyway. The 460 call
sites now name the shim function, and shirabe-pcre is gone from the
workspace along with its LICENSE entry.
The forwards expand as they read: isMatch becomes
preg_match2(.., 0).is_some() (is_none() where PHP negates it), isMatch3
and match3 drop the .is_some(), matchAll counts through
preg_match_all2(..).occurrence_count(), and replace4/replace5 spell out
the limit and count arguments preg_replace2 takes. Callbacks are the one
place the shapes differ: preg_replace_callback carries an error out of
the callback, so the fourteen infallible closures wrap their result in
Ok() and expect() it back.
Config::process() is the fifteenth, and it drops the `error` cell it
captured to smuggle a failure past a closure that could only return a
String. The `?` in the closure now carries it, which is what the PHP
does -- a throw from the callback leaves preg_replace_callback at the
failing match rather than running the remaining replacements and
reporting the last error.
The module doc that explained why composer/pcre's exceptions and
*StrictGroups() variants have no counterpart moves to the shim's preg
module, where the functions it describes live.
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/forgejo_driver.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/fossil_driver.rs | 17 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs | 16 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/git_driver.rs | 36 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/github_driver.rs | 30 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/gitlab_driver.rs | 15 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/hg_driver.rs | 20 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/perforce_driver.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/svn_driver.rs | 23 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/vcs_driver.rs | 9 |
10 files changed, 102 insertions, 77 deletions
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 8047602a..90480add 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -15,10 +15,10 @@ use crate::util::ForgejoRepositoryData; use crate::util::ForgejoUrl; use crate::util::http::Response; use indexmap::IndexMap; -use shirabe_pcre::Preg; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, urlencode, + PhpMixed, RuntimeException, base64_decode, explode, extension_loaded, php_regex, preg_match2, + urlencode, }; #[derive(Debug)] @@ -584,7 +584,7 @@ impl ForgejoDriver { let links = explode(",", &header); for link in links { - if let Some(m) = Preg::match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link) + if let Some(m) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link, 0) && let Some(url) = m.get(1) { return Some(url.to_string()); diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index 8ce479fd..c42ca271 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -11,10 +11,10 @@ use crate::util::Filesystem; use crate::util::ProcessExecutor; use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; -use shirabe_pcre::Preg; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex, + PhpMixed, RuntimeException, dirname, is_dir, is_file, is_writable, php_regex, preg_match2, + preg_replace, }; #[derive(Debug)] @@ -82,7 +82,7 @@ impl FossilDriver { .into()); } - let local_name = Preg::replace(php_regex!(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); @@ -286,7 +286,7 @@ impl FossilDriver { Some(&self.checkout_dir), ); for branch in self.inner.process.borrow().split_lines(&output) { - let branch = Preg::replace(php_regex!(r"/^\*/"), "", branch.trim()); + let branch = preg_replace(php_regex!(r"/^\*/"), "", branch.trim()); let branch = branch.trim().to_string(); branches.insert(branch.clone(), branch); } @@ -301,14 +301,17 @@ impl FossilDriver { url: &str, deep: bool, ) -> anyhow::Result<bool> { - if Preg::is_match( + if preg_match2( php_regex!(r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i"), url, - ) { + 0, + ) + .is_some() + { return Ok(true); } - if Preg::is_match(php_regex!(r"!/fossil/|\.fossil!"), url) { + if preg_match2(php_regex!(r"!/fossil/|\.fossil!"), url, 0).is_some() { 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 5f83b4e1..9f8e7a80 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -15,11 +15,11 @@ use crate::util::Bitbucket; use crate::util::http::Response; use chrono::{DateTime, FixedOffset}; use indexmap::IndexMap; -use shirabe_pcre::Preg; 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, strpos, + array_search_mixed, extension_loaded, http_build_query, implode, is_array, php_regex, + preg_match2, preg_replace, strpos, }; #[derive(Debug)] @@ -84,9 +84,10 @@ impl GitBitbucketDriver { /// @inheritDoc pub fn initialize(&mut self) -> anyhow::Result<()> { - let Some(m) = Preg::is_match3( + let Some(m) = preg_match2( php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(?:\.git|/?)?$#i"), &self.inner.url, + 0, ) else { return Err(InvalidArgumentException::new(format!( "The Bitbucket repository URL {} is invalid. It must be the HTTPS URL of a Bitbucket repository.", @@ -739,7 +740,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( + self.clone_https_url = preg_replace( php_regex!(r"/https:\/\/([^@]+@)?/"), "https://", m.get("href").and_then(|v| v.as_string()).unwrap_or(""), @@ -797,10 +798,13 @@ impl GitBitbucketDriver { url: &str, _deep: bool, ) -> anyhow::Result<bool> { - if !Preg::is_match( + if preg_match2( php_regex!(r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i"), url, - ) { + 0, + ) + .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 c224e8e6..62cca379 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -14,11 +14,10 @@ use crate::util::Url; use chrono::TimeZone; use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; -use shirabe_pcre::Preg; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, realpath, - sys_get_temp_dir, + InvalidArgumentException, RuntimeException, dirname, is_dir, is_writable, preg_match2, + preg_replace, realpath, sys_get_temp_dir, }; use shirabe_php_shim::{PhpMixed, php_regex}; @@ -51,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(php_regex!(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::new(format!( "Failed to read package information from {} as the path does not exist", @@ -78,7 +77,7 @@ impl GitDriver { self.repo_dir = format!( "{}/{}/", cache_vcs_dir, - Preg::replace( + preg_replace( r"{[^a-z0-9.]}i", "-", &Url::sanitize(self.inner.url.clone()) @@ -99,7 +98,13 @@ impl GitDriver { .into()); } - if Preg::is_match(php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), &self.inner.url) { + if preg_match2( + php_regex!(r"{^ssh://[^@]+@[^:]+:[^0-9]+}"), + &self.inner.url, + 0, + ) + .is_some() + { 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 @@ -146,7 +151,7 @@ impl GitDriver { &format!( "{}/{}", cache_repo_dir, - Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(cache_url)) + preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(cache_url)) ), None, None, @@ -199,7 +204,7 @@ impl GitDriver { if !branches.contains(&"* master".to_string()) { for branch in &branches { if !branch.is_empty() - && let Some(caps) = Preg::match3(php_regex!(r"{^\* +(\S+)}"), branch) + && let Some(caps) = preg_match2(php_regex!(r"{^\* +(\S+)}"), branch, 0) && let Some(name) = caps.get(1) { self.root_identifier = Some(name.to_string()); @@ -309,9 +314,10 @@ impl GitDriver { ); for tag in self.inner.process.borrow().split_lines(&output) { if !tag.is_empty() - && let Some(caps) = Preg::match3( + && let Some(caps) = preg_match2( php_regex!(r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}"), &tag, + 0, ) && let (Some(hash), Some(name)) = (caps.get(1), caps.get(2)) { @@ -344,10 +350,11 @@ impl GitDriver { ); for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() - && !Preg::is_match(php_regex!(r"{^ *[^/]+/HEAD }"), &branch) - && let Some(caps) = Preg::match3( + && preg_match2(php_regex!(r"{^ *[^/]+/HEAD }"), &branch, 0).is_none() + && let Some(caps) = preg_match2( php_regex!(r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}"), &branch, + 0, ) && let (Some(name), Some(hash)) = (caps.get(1), caps.get(2)) && !name.starts_with('-') @@ -368,10 +375,13 @@ impl GitDriver { url: &str, deep: bool, ) -> anyhow::Result<bool> { - if Preg::is_match( + if preg_match2( php_regex!(r"#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i"), url, - ) { + 0, + ) + .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 11bb9503..e9c17d30 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -14,12 +14,12 @@ use crate::util::GitHub; use crate::util::http::Response; use chrono::{DateTime, FixedOffset}; use indexmap::IndexMap; -use shirabe_pcre::Preg; 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_split, strpos, strtolower, substr, trim, urlencode, + parse_url, php_regex, preg_match2, preg_replace, preg_split, strpos, strtolower, substr, trim, + urlencode, }; #[derive(Debug)] @@ -70,11 +70,12 @@ impl GitHubDriver { } pub fn initialize(&mut self) -> anyhow::Result<()> { - let Some(match_) = Preg::is_match3( + let Some(match_) = preg_match2( php_regex!( r"#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#" ), &self.inner.url, + 0, ) else { return Err(InvalidArgumentException::new(format!( "The GitHub repository URL {} is invalid.", @@ -482,14 +483,14 @@ impl GitHubDriver { let mut key: Option<String> = None; for line in preg_split(php_regex!(r"{\r?\n}"), &funding) { let line = trim(&line, None); - if let Some(m) = Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line) { + if let Some(m) = preg_match2(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line, 0) { let g1 = m.get(1).unwrap_or_default().to_string(); let g2 = m.get(2).unwrap_or_default().to_string(); if g2 == "[" { key = Some(g1); continue; } - if let Some(m2) = Preg::is_match3(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2) { + if let Some(m2) = preg_match2(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2, 0) { let inner = m2.get(1).unwrap_or_default().to_string(); for item in array_map( |s: &String| trim(s, None), @@ -504,7 +505,7 @@ impl GitHubDriver { result.push(entry); } } else if let Some(m2) = - Preg::is_match3(php_regex!(r"{^([^#].*?)(?:\s+#.*)?$}"), &g2) + preg_match2(php_regex!(r"{^([^#].*?)(?:\s+#.*)?$}"), &g2, 0) { let mut entry = IndexMap::new(); entry.insert("type".to_string(), PhpMixed::String(g1.clone())); @@ -515,11 +516,11 @@ impl GitHubDriver { result.push(entry); } key = None; - } else if let Some(m) = Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line) { + } else if let Some(m) = preg_match2(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line, 0) { key = Some(m.get(1).unwrap_or_default().to_string()); } else if key.is_some() - && let Some(m) = Preg::is_match3(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line) - .or_else(|| Preg::is_match3(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line)) + && let Some(m) = preg_match2(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line, 0) + .or_else(|| preg_match2(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line, 0)) { let mut entry = IndexMap::new(); entry.insert( @@ -644,7 +645,9 @@ impl GitHubDriver { }; if bits.scheme.is_none() && bits.host.is_none() { - if Preg::is_match(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url) { + if preg_match2(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url, 0) + .is_some() + { result[key_idx].insert( "url".to_string(), PhpMixed::String(format!("https://{}", item_url)), @@ -908,11 +911,12 @@ impl GitHubDriver { url: &str, _deep: bool, ) -> anyhow::Result<bool> { - let Some(matches) = Preg::is_match3( + let Some(matches) = preg_match2( php_regex!( r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#" ), url, + 0, ) else { return Ok(false); }; @@ -923,7 +927,7 @@ impl GitHubDriver { .map(str::to_string) .unwrap_or_else(|| matches.get(3).unwrap_or_default().to_string()); if !in_array_loose( - strtolower(&Preg::replace(php_regex!(r"{^www\.}i"), "", &origin_url)), + strtolower(&preg_replace(php_regex!(r"{^www\.}i"), "", &origin_url)), config.borrow().get("github-domains").values(), ) { return Ok(false); @@ -1249,7 +1253,7 @@ impl GitHubDriver { let links = explode(",", &header); for link in &links { - if let Some(m) = Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) { + if let Some(m) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, 0) { return Some(m.get(1).unwrap_or_default().to_string()); } } diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 30c3f7ae..6054d941 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -15,12 +15,11 @@ use crate::util::HttpDownloader; use crate::util::http::Response; use chrono::{DateTime, FixedOffset}; use indexmap::IndexMap; -use shirabe_pcre::Preg; 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, strpos, strtolower, + is_string, ord, php_regex, preg_match2, preg_replace, strpos, strtolower, }; /// Driver for GitLab API, use the Git driver for local checkouts. @@ -81,7 +80,7 @@ impl GitLabDriver { /// /// SSH urls use https by default. Set "secure-http": false on the repository config to use http instead. pub fn initialize(&mut self) -> anyhow::Result<()> { - let Some(match_) = Preg::is_match3(Self::URL_REGEX, &self.inner.url) else { + let Some(match_) = preg_match2(Self::URL_REGEX, &self.inner.url, 0) else { return Err(InvalidArgumentException::new(format!( "The GitLab repository URL {} is invalid. It must be the HTTP URL of a GitLab project.", self.inner.url.clone(), @@ -152,7 +151,7 @@ impl GitLabDriver { } self.namespace = implode("/", &url_parts); - self.repository = Preg::replace( + self.repository = preg_replace( php_regex!(r"#(\.git)$#"), "", match_.name("repo").unwrap_or_default(), @@ -383,7 +382,7 @@ impl GitLabDriver { // Convert the root identifier to a cacheable commit id let mut identifier = identifier.to_string(); - if !Preg::is_match(php_regex!(r"{[a-f0-9]{40}}i"), &identifier) { + if preg_match2(php_regex!(r"{[a-f0-9]{40}}i"), &identifier, 0).is_none() { let branches = self.get_branches()?; if let Some(sha) = branches.get(&identifier) { identifier = sha.clone(); @@ -927,7 +926,7 @@ impl GitLabDriver { url: &str, _deep: bool, ) -> anyhow::Result<bool> { - let Some(match_) = Preg::is_match3(Self::URL_REGEX, url) else { + let Some(match_) = preg_match2(Self::URL_REGEX, url, 0) else { return Ok(false); }; @@ -978,7 +977,7 @@ impl GitLabDriver { let links = explode(",", &header); for link in &links { - if let Some(match_) = Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) { + if let Some(match_) = preg_match2(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link, 0) { return Some(match_.get(1).unwrap_or_default().to_string()); } } @@ -1022,7 +1021,7 @@ impl GitLabDriver { if in_array_loose(guessed_domain.clone(), configured_domains.values()) || (port_number.is_some() && in_array_loose( - Preg::replace(php_regex!(r"{:\d+}"), "", &guessed_domain), + preg_replace(php_regex!(r"{:\d+}"), "", &guessed_domain), configured_domains.values(), )) { diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index 120b8ea8..ada1063e 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -11,9 +11,10 @@ use crate::util::Hg as HgUtils; use crate::util::Url; use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; -use shirabe_pcre::Preg; use shirabe_php_shim::Catch as _; -use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex}; +use shirabe_php_shim::{ + PhpMixed, RuntimeException, dirname, is_dir, is_writable, php_regex, preg_match2, preg_replace, +}; #[derive(Debug)] pub struct HgDriver { @@ -57,7 +58,7 @@ impl HgDriver { return Err(RuntimeException::new("HgDriver requires a usable cache directory, and it looks like you set it to be disabled".to_string()).into()); } - let sanitized = Preg::replace( + let sanitized = preg_replace( php_regex!(r"{[^a-z0-9]}i"), "-", &Url::sanitize(self.inner.url.clone()), @@ -233,7 +234,7 @@ impl HgDriver { ); for tag in self.inner.process.borrow().split_lines(&output) { if !tag.is_empty() - && let Some(m) = Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag) + && let Some(m) = preg_match2(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag, 0) { tags.insert( m.get(1).unwrap_or_default().to_string(), @@ -263,7 +264,7 @@ impl HgDriver { for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() && let Some(m) = - Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch) + preg_match2(php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch, 0) { let name = m.get(1).unwrap_or_default().to_string(); if !name.starts_with('-') { @@ -281,7 +282,7 @@ impl HgDriver { for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() && let Some(m) = - Preg::match3(php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch) + preg_match2(php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch, 0) { let name = m.get(1).unwrap_or_default().to_string(); if !name.starts_with('-') { @@ -304,12 +305,15 @@ impl HgDriver { url: &str, deep: bool, ) -> anyhow::Result<bool> { - if Preg::is_match( + if preg_match2( php_regex!( r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i" ), url, - ) { + 0, + ) + .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 ce9ffb49..50aed379 100644 --- a/crates/shirabe/src/repository/vcs/perforce_driver.rs +++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs @@ -9,8 +9,9 @@ use crate::util::PerforceInterface; use crate::util::ProcessExecutor; use crate::util::http::Response; use indexmap::IndexMap; -use shirabe_pcre::Preg; -use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException, php_regex}; +use shirabe_php_shim::{ + BadMethodCallException, PhpMixed, RuntimeException, php_regex, preg_match2, +}; #[derive(Debug)] pub struct PerforceDriver { @@ -189,7 +190,7 @@ impl PerforceDriver { url: &str, deep: bool, ) -> anyhow::Result<bool> { - if deep || Preg::is_match(php_regex!(r"#\b(perforce|p4)\b#i"), url) { + if deep || preg_match2(php_regex!(r"#\b(perforce|p4)\b#i"), url, 0).is_some() { 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 6fb987a4..3398eb59 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -13,10 +13,10 @@ use crate::util::Svn as SvnUtil; use crate::util::Url; use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; -use shirabe_pcre::Preg; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - PhpMixed, RuntimeException, php_regex, stripos, strrpos, strtr, substr, trim, + PhpMixed, RuntimeException, php_regex, preg_match2, preg_replace, stripos, strrpos, strtr, + substr, trim, }; #[derive(Debug)] @@ -110,7 +110,7 @@ impl SvnDriver { .get("cache-repo-dir") .as_string() .unwrap_or(""), - Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(self.base_url.clone())), + preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(self.base_url.clone())), ), None, None, @@ -153,7 +153,7 @@ impl SvnDriver { } fn should_cache(&self, identifier: &str) -> bool { - self.inner.cache.is_some() && Preg::is_match(php_regex!(r"{@\d+$}"), identifier) + self.inner.cache.is_some() && preg_match2(php_regex!(r"{@\d+$}"), identifier, 0).is_some() } pub fn get_composer_information( @@ -258,7 +258,7 @@ impl SvnDriver { let identifier = format!("/{}/", trim(identifier, Some("/"))); let (path, rev) = if let Some(m) = - Preg::is_match3(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier) + preg_match2(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier, 0) && let Some(rev) = m.get(2) { (m.get(1).unwrap_or_default().to_string(), rev.to_string()) @@ -292,7 +292,7 @@ impl SvnDriver { let identifier = format!("/{}/", trim(identifier, Some("/"))); let (path, rev) = if let Some(m) = - Preg::is_match3(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier) + preg_match2(php_regex!(r"{^(.+?)(@\d+)?/$}"), &identifier, 0) && let Some(rev) = m.get(2) { (m.get(1).unwrap_or_default().to_string(), rev.to_string()) @@ -306,8 +306,7 @@ impl SvnDriver { )?; for line in self.inner.process.borrow().split_lines(&output) { if !line.is_empty() - && let Some(m) = - Preg::is_match3(php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line) + && let Some(m) = preg_match2(php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line, 0) { let date_str = m.get(1).unwrap_or_default().to_string(); return Ok(shirabe_php_shim::date_create::<Utc>(date_str.trim()) @@ -335,7 +334,7 @@ impl SvnDriver { let line = trim(&line, None); if !line.is_empty() && let Some(m) = - Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line) + preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0) { let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0); let path = m.get(2).unwrap_or_default().to_string(); @@ -378,7 +377,7 @@ impl SvnDriver { let line = trim(&line, None); if !line.is_empty() && let Some(m) = - Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line) + preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0) { let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0); let path = m.get(2).unwrap_or_default().to_string(); @@ -413,7 +412,7 @@ impl SvnDriver { let line = trim(&line, None); if !line.is_empty() && let Some(m) = - Preg::is_match3(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line) + preg_match2(php_regex!(r"{^\s*(\S+).*?(\S+)\s*$}"), &line, 0) { let rev: i64 = m.get(1).and_then(|s| s.parse().ok()).unwrap_or(0); let path = m.get(2).unwrap_or_default().to_string(); @@ -444,7 +443,7 @@ impl SvnDriver { deep: bool, ) -> anyhow::Result<bool> { let url = Self::normalize_url(url); - if Preg::is_match(php_regex!(r"#(^svn://|^svn\+ssh://|svn\.)#i"), &url) { + if preg_match2(php_regex!(r"#(^svn://|^svn\+ssh://|svn\.)#i"), &url, 0).is_some() { return Ok(true); } diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs index a5192937..1a5ee72e 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs @@ -12,9 +12,8 @@ use crate::util::ProcessExecutor; use crate::util::http::Response; use chrono::{DateTime, FixedOffset}; use indexmap::IndexMap; -use shirabe_pcre::Preg; use shirabe_php_shim::Catch as _; -use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex}; +use shirabe_php_shim::{DATE_RFC3339, PhpMixed, extension_loaded, php_regex, preg_match2}; #[derive(Debug)] pub struct VcsDriverBase { @@ -57,7 +56,8 @@ impl VcsDriverBase { } pub fn should_cache(&self, identifier: &str) -> bool { - self.cache.is_some() && Preg::is_match(php_regex!("{^[a-f0-9]{40}$}iD"), identifier) + self.cache.is_some() + && preg_match2(php_regex!("{^[a-f0-9]{40}$}iD"), identifier, 0).is_some() } pub fn get_scheme(&self) -> &str { @@ -202,7 +202,8 @@ 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(php_regex!("{^[a-f0-9]{40}$}iD"), identifier) + self.cache().is_some() + && preg_match2(php_regex!("{^[a-f0-9]{40}$}iD"), identifier, 0).is_some() } fn get_composer_information( |
