aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader/git_downloader.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
commit530d085d4f3e19f94ac3cf8f8ac3b17000214b2e (patch)
treeb4de2c2443e2bb2cfc692454ac284dc1d2313e59 /crates/shirabe/src/downloader/git_downloader.rs
parent0caac63bacefb9a1f62848636d47fca07f592bba (diff)
downloadphp-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/downloader/git_downloader.rs')
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs47
1 files changed, 27 insertions, 20 deletions
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index b816aa18..d3dea453 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -17,11 +17,10 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Url;
use indexmap::IndexMap;
-use shirabe_pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- CmpOp, PhpMixed, RuntimeException, array_map, basename, dirname, impl_php_class, implode,
- in_array_strict, is_dir, php_regex, preg_quote, preg_split, realpath, rtrim, strlen, strpos,
- substr, trim, version_compare,
+ CaptureKey, CmpOp, PhpMixed, RuntimeException, array_map, basename, dirname, impl_php_class,
+ implode, in_array_strict, is_dir, php_regex, preg_match_all2, preg_match2, preg_quote,
+ preg_replace, preg_split, realpath, rtrim, strlen, strpos, substr, trim, version_compare,
};
#[derive(Debug)]
@@ -95,13 +94,13 @@ impl GitDownloader {
}
let mut refs = trim(&output, None);
- let Some(head_match) = Preg::is_match3(php_regex!(r"{^([a-f0-9]+) HEAD$}mi"), &refs) else {
+ let Some(head_match) = preg_match2(php_regex!(r"{^([a-f0-9]+) HEAD$}mi"), &refs, 0) else {
// could not match the HEAD for some reason
return Ok(None);
};
let head_ref = head_match.get(1).unwrap_or_default().to_string();
- let branches_match = Preg::is_match_all(
+ let branches_match = preg_match_all2(
format!("{{^{} refs/heads/(.+)$}}mi", preg_quote(&head_ref, None)),
&refs,
);
@@ -128,7 +127,7 @@ impl GitDownloader {
// try to find matching branch names in remote repos
for candidate in &candidate_branches {
- let m = Preg::is_match_all(
+ let m = preg_match_all2(
format!(
"{{^[a-f0-9]+ refs/remotes/((?:[^/]+)/{})$}}mi",
preg_quote(candidate, None)
@@ -275,7 +274,7 @@ impl GitDownloader {
// If the non-existent branch is actually the name of a file, the file
// is checked out.
- let mut branch = Preg::replace(
+ let mut branch = preg_replace(
php_regex!(r"{(?:^dev-|(?:\.x)?-dev$)}i"),
"",
pretty_version,
@@ -299,12 +298,14 @@ impl GitDownloader {
// check whether non-commitish are branches or tags, and fetch branches with the remote name
let git_ref = reference.to_string();
- if !Preg::is_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference)
+ if preg_match2(php_regex!(r"{^[a-f0-9]{40}$}"), reference, 0).is_none()
&& branches.is_some()
- && Preg::is_match(
+ && preg_match2(
format!("{{^\\s+composer/{}$}}m", preg_quote(reference, None)),
branches.as_deref().unwrap_or(""),
+ 0,
)
+ .is_some()
{
let mut command1: Vec<String> = vec!["git".to_string(), "checkout".to_string()];
command1.extend(force.clone());
@@ -345,17 +346,21 @@ impl GitDownloader {
}
// try to checkout branch by name and then reset it so it's on the proper branch name
- if Preg::is_match(php_regex!(r"{^[a-f0-9]{40}$}"), reference) {
+ if preg_match2(php_regex!(r"{^[a-f0-9]{40}$}"), reference, 0).is_some() {
// add 'v' in front of the branch if it was stripped when generating the pretty name
if branches.is_some()
- && !Preg::is_match(
+ && preg_match2(
format!("{{^\\s+composer/{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
+ 0,
)
- && Preg::is_match(
+ .is_none()
+ && preg_match2(
format!("{{^\\s+composer/v{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
+ 0,
)
+ .is_some()
{
branch = format!("v{}", branch);
}
@@ -500,12 +505,13 @@ impl GitDownloader {
fn set_push_url(&self, path: &str, url: &str) {
// set push url for github projects
- if let Some(match_) = Preg::is_match3(
+ if let Some(match_) = preg_match2(
format!(
"{{^(?:https?|git)://{}/([^/]+)/([^/]+?)(?:\\.git)?$}}",
GitUtil::get_github_domains_regex(&self.inner.config.borrow())
),
url,
+ 0,
) {
let protocols = self.inner.config.borrow_mut().get("github-protocols");
let m1 = match_.get(1).unwrap_or_default().to_string();
@@ -640,7 +646,8 @@ impl GitDownloader {
}
fn get_short_hash(&self, reference: &str) -> String {
- if !self.inner.io.is_verbose() && Preg::is_match(php_regex!(r"{^[0-9a-f]{40}$}"), reference)
+ if !self.inner.io.is_verbose()
+ && preg_match2(php_regex!(r"{^[0-9a-f]{40}$}"), reference, 0).is_some()
{
return substr(reference, 0, Some(10));
}
@@ -769,7 +776,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
+ preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let git_version = GitUtil::get_version(&self.inner.process);
@@ -834,7 +841,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
+ preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let r#ref = package.get_source_reference().unwrap_or_default();
@@ -994,7 +1001,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
+ preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let r#ref = target.get_source_reference().unwrap_or_default();
@@ -1094,9 +1101,9 @@ impl VcsDownloader for GitDownloader {
Some(&path),
) == 0
&& let Some(origin_match) =
- Preg::is_match3(php_regex!(r"{^origin\s+(?P<url>\S+)}m"), &output)
+ preg_match2(php_regex!(r"{^origin\s+(?P<url>\S+)}m"), &output, 0)
&& let Some(composer_match) =
- Preg::is_match3(php_regex!(r"{^composer\s+(?P<url>\S+)}m"), &output)
+ preg_match2(php_regex!(r"{^composer\s+(?P<url>\S+)}m"), &output, 0)
{
let origin_url = origin_match.name("url").unwrap_or_default().to_string();
let composer_url = composer_match.name("url").unwrap_or_default().to_string();