diff options
Diffstat (limited to 'crates/shirabe/src/repository/vcs')
| -rw-r--r-- | crates/shirabe/src/repository/vcs/forgejo_driver.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/fossil_driver.rs | 12 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/git_driver.rs | 16 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/github_driver.rs | 47 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/gitlab_driver.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/hg_driver.rs | 27 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/perforce_driver.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/svn_driver.rs | 34 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/vcs_driver.rs | 6 |
10 files changed, 110 insertions, 62 deletions
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( |
