From 52a0665acbbe5bf5b8c6875118fb9cdf7952453b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 17 Aug 2026 06:43:52 +0900 Subject: 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 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. --- crates/shirabe/src/downloader/git_downloader.rs | 14 +++++++------- crates/shirabe/src/downloader/svn_downloader.rs | 4 ++-- crates/shirabe/src/downloader/zip_downloader.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'crates/shirabe/src/downloader') 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 = 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>> = 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>> = 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 = 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 = IndexMap::new(); - let mut composer_match: IndexMap = IndexMap::new(); + let mut origin_match = PregMatchedGroups::new(); + let mut composer_match = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^origin\s+(?P\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 = "#(.*)#"; - let mut matches: IndexMap = 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 = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)}"), &output, -- cgit v1.3.1-4-g156e