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/util/git.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'crates/shirabe/src/util/git.rs') diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index f8fea562..0f463aea 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -14,7 +14,7 @@ use crate::util::ProcessExecutor; use crate::util::Url; use crate::util::{AuthHelper, StoreAuth}; use indexmap::IndexMap; -use shirabe_pcre::{CaptureKey, Preg}; +use shirabe_pcre::{CaptureKey, Preg, PregMatchedGroups}; use shirabe_php_shim::{ AnyThrowable, CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, clearstatcache, explode, implode, in_array_loose, in_array_strict, is_dir, php_regex, @@ -226,7 +226,7 @@ impl Git { &mut output, cwd, )?; - let mut m: IndexMap = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im"), &output, @@ -248,7 +248,7 @@ impl Git { let protocols = self.config.borrow_mut().get("github-protocols"); // public github, autoswitch protocols // @phpstan-ignore composerPcre.maybeUnsafeStrictGroups - let mut m: IndexMap = IndexMap::new(); + let mut m = PregMatchedGroups::new(); if Preg::is_match3( format!( "{{^(?:https?|git)://{}/(.*)}}", @@ -344,7 +344,7 @@ impl Git { let mut error_msg = self.process.borrow().get_error_output().to_string(); // private github repository without ssh key access, try https with auth // @phpstan-ignore composerPcre.maybeUnsafeStrictGroups - let mut m: IndexMap = IndexMap::new(); + let mut m = PregMatchedGroups::new(); let github_matched = Preg::is_match3( format!( "{{^git@{}:(.+?)\\.git$}}i", @@ -1089,8 +1089,8 @@ impl Git { Ok(false) } - fn get_authentication_failure(&self, url: &str) -> Option> { - let mut m: IndexMap = IndexMap::new(); + fn get_authentication_failure(&self, url: &str) -> Option { + let mut m = PregMatchedGroups::new(); if !Preg::is_match3( php_regex!(r"{^(https?://)([^/]+)(.*)$}i"), url, @@ -1179,7 +1179,7 @@ impl Git { .borrow() .split_lines(output_mixed.as_string().unwrap_or("")); for line in lines { - let mut matches: IndexMap = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"{^\s*HEAD branch:\s(.+)\s*$}m"), &line, @@ -1308,7 +1308,7 @@ impl Git { Option::<&str>::None, ); if exit_code == 0 { - let mut matches: IndexMap = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"), &output, -- cgit v1.3.1-4-g156e