aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-17 06:43:52 +0900
committernsfisis <nsfisis@gmail.com>2026-08-17 06:43:52 +0900
commit52a0665acbbe5bf5b8c6875118fb9cdf7952453b (patch)
tree7302b0b87f7b0d406126da734ef82c80abf64204 /crates/shirabe/src/downloader
parentc81e9f89d9e4388f36a4427bbaa95eced659d2ce (diff)
downloadphp-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.tar.gz
php-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.tar.zst
php-shirabe-52a0665acbbe5bf5b8c6875118fb9cdf7952453b.zip
refactor(preg): wrap the preg_* $matches maps in newtypes
The five IndexMap shapes that the preg_* functions and Preg fill in are now distinct types generated by preg_match_map!, so a matches map no longer interchanges with any other map of the same key and value type. Index<usize> is kept alongside Index<&Q> because call sites such as config_command and event_dispatcher reach for a group by its position in the map rather than by its capture key.
Diffstat (limited to 'crates/shirabe/src/downloader')
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs14
-rw-r--r--crates/shirabe/src/downloader/svn_downloader.rs4
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs4
3 files changed, 11 insertions, 11 deletions
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index 90a962a2..f60b231d 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -17,7 +17,7 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Url;
use indexmap::IndexMap;
-use shirabe_pcre::{CaptureKey, Preg};
+use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups, PregMatchesAll};
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,
@@ -95,7 +95,7 @@ impl GitDownloader {
}
let mut refs = trim(&output, None);
- let mut head_match: IndexMap<CaptureKey, String> = IndexMap::new();
+ let mut head_match = PregMatchedGroups::new();
if !Preg::is_match3(
php_regex!(r"{^([a-f0-9]+) HEAD$}mi"),
&refs,
@@ -109,7 +109,7 @@ impl GitDownloader {
.cloned()
.unwrap_or_default();
- let mut branches_match: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new();
+ let mut branches_match = PregMatchesAll::new();
if !Preg::is_match_all(
format!("{{^{} refs/heads/(.+)$}}mi", preg_quote(&head_ref, None)),
&refs,
@@ -137,7 +137,7 @@ impl GitDownloader {
// try to find matching branch names in remote repos
for candidate in &candidate_branches {
- let mut m: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new();
+ let mut m = PregMatchesAll::new();
if Preg::is_match_all(
format!(
"{{^[a-f0-9]+ refs/remotes/((?:[^/]+)/{})$}}mi",
@@ -510,7 +510,7 @@ impl GitDownloader {
fn set_push_url(&self, path: &str, url: &str) {
// set push url for github projects
- let mut match_: IndexMap<CaptureKey, String> = IndexMap::new();
+ let mut match_ = PregMatchedGroups::new();
if Preg::is_match3(
format!(
"{{^(?:https?|git)://{}/([^/]+)/([^/]+?)(?:\\.git)?$}}",
@@ -1115,8 +1115,8 @@ impl VcsDownloader for GitDownloader {
Some(&path),
) == 0
{
- let mut origin_match: IndexMap<CaptureKey, String> = IndexMap::new();
- let mut composer_match: IndexMap<CaptureKey, String> = IndexMap::new();
+ let mut origin_match = PregMatchedGroups::new();
+ let mut composer_match = PregMatchedGroups::new();
if Preg::is_match3(
php_regex!(r"{^origin\s+(?P<url>\S+)}m"),
&output,
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs
index d5087d10..29662be8 100644
--- a/crates/shirabe/src/downloader/svn_downloader.rs
+++ b/crates/shirabe/src/downloader/svn_downloader.rs
@@ -15,7 +15,7 @@ use crate::util::Filesystem;
use crate::util::ProcessExecutor;
use crate::util::Svn as SvnUtil;
use indexmap::IndexMap;
-use shirabe_pcre::{CaptureKey, Preg};
+use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups};
use shirabe_php_shim::{
CmpOp, PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, preg_split,
version_compare,
@@ -383,7 +383,7 @@ impl VcsDownloader for SvnDownloader {
}
let url_pattern = "#<url>(.*)</url>#";
- let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
+ let mut matches = PregMatchedGroups::new();
let base_url = if Preg::match3(url_pattern, &output, Some(&mut matches)) {
matches
.get(&CaptureKey::ByIndex(1))
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index e7f3facf..91078dc9 100644
--- a/crates/shirabe/src/downloader/zip_downloader.rs
+++ b/crates/shirabe/src/downloader/zip_downloader.rs
@@ -8,7 +8,7 @@ use crate::package::PackageInterfaceHandle;
use crate::util::IniHelper;
use crate::util::Platform;
use indexmap::IndexMap;
-use shirabe_pcre::{CaptureKey, Preg};
+use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups};
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
CmpOp, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException, ZipArchive,
@@ -114,7 +114,7 @@ impl ZipDownloader {
.unwrap_or(1)
== 0
{
- let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
+ let mut m = PregMatchedGroups::new();
if Preg::is_match3(
php_regex!(r"{^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)}"),
&output,