diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-17 06:43:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-17 06:43:52 +0900 |
| commit | 52a0665acbbe5bf5b8c6875118fb9cdf7952453b (patch) | |
| tree | 7302b0b87f7b0d406126da734ef82c80abf64204 /crates/shirabe/src/util/git.rs | |
| parent | c81e9f89d9e4388f36a4427bbaa95eced659d2ce (diff) | |
| download | php-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/util/git.rs')
| -rw-r--r-- | crates/shirabe/src/util/git.rs | 16 |
1 files changed, 8 insertions, 8 deletions
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<CaptureKey, String> = 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<CaptureKey, String> = 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<CaptureKey, String> = 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<IndexMap<CaptureKey, String>> { - let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); + fn get_authentication_failure(&self, url: &str) -> Option<PregMatchedGroups> { + 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<CaptureKey, String> = 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<CaptureKey, String> = IndexMap::new(); + let mut matches = PregMatchedGroups::new(); if Preg::is_match3( php_regex!(r"/^git version (\d+(?:\.\d+)+)/m"), &output, |
