From 844097edf44bf1424d28e2d5fbefda90c1c8f46c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 01:57:02 +0900 Subject: refactor(pcre): hand back the match instead of copying it out Preg::match4 and Preg::replace_callback gave callers a PregMatchedGroups: an IndexMap rebuilt from the match with an owned String per group, plus a second String for a named group's name key. That is the copy PregMatches shed when it started wrapping regex::Captures, reinstated one layer up -- and nearly every regex call in the tree goes through Preg rather than the shim's preg_* directly, so almost nothing saw the borrow. PregMatchedGroups existed only to drop the null (unmatched) groups the old PregMatches held as Option values. PregMatches::get reports a non-participating group as None on its own, so the two read alike and the type collapses into it. Call sites still reach groups through get(&CaptureKey::ByIndex(N)); what changes is that the value arrives as a &str borrowed from the subject, which the signatures now carry as a lifetime. Three places needed the borrow reckoned with rather than a mechanical rewrite: PhpFileCleaner::clean and Problem::get_messages read their groups out before mutating what the match borrows, and Git::get_authentication_failure names the lifetime of its url argument, which the result borrows instead of self. Co-Authored-By: Claude Opus 5 (1M context) --- .../shirabe/src/repository/composer_repository.rs | 17 +-- .../shirabe/src/repository/platform_repository.rs | 145 ++++++++------------- .../shirabe/src/repository/vcs/forgejo_driver.rs | 2 +- .../src/repository/vcs/git_bitbucket_driver.rs | 10 +- crates/shirabe/src/repository/vcs/git_driver.rs | 6 +- crates/shirabe/src/repository/vcs/github_driver.rs | 47 ++++--- crates/shirabe/src/repository/vcs/gitlab_driver.rs | 37 +++--- crates/shirabe/src/repository/vcs/hg_driver.rs | 26 +++- crates/shirabe/src/repository/vcs/svn_driver.rs | 20 ++- 9 files changed, 157 insertions(+), 153 deletions(-) (limited to 'crates/shirabe/src/repository') diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 6feb4359..d42a9778 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -251,8 +251,8 @@ impl ComposerRepository { ) { let proto = match_packagist .get(&CaptureKey::ByName("proto".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); url = format!("{}://repo.packagist.org", proto); } @@ -786,12 +786,12 @@ impl ComposerRepository { { let q = match_groups .get(&CaptureKey::ByName("query".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); let vendor = match_groups .get(&CaptureKey::ByName("vendor".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); let url = format!( "{}?vendor={}&filter={}", list_url, @@ -2429,10 +2429,7 @@ impl ComposerRepository { if let Some(matches) = Preg::is_match3(php_regex!(r"{^[^:]++://[^/]*+}"), &self.url) { return Ok(format!( "{}{}", - matches - .get(&CaptureKey::ByIndex(0)) - .cloned() - .unwrap_or_default(), + matches.get(&CaptureKey::ByIndex(0)).unwrap_or_default(), url )); } diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index 29f66647..94ecc015 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -323,9 +323,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-librabbitmq", name), - librabbitmq_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + librabbitmq_matches.get(&CaptureKey::ByName("version".to_string())), Some("AMQP librabbitmq version"), &[], &[], @@ -339,8 +337,8 @@ impl PlatformRepository { ) { let version_str = protocol_matches .get(&CaptureKey::ByName("version".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); self.add_library( &mut libraries, &format!("{}-protocol", name), @@ -362,9 +360,7 @@ impl PlatformRepository { self.add_library( &mut libraries, name, - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), None, &[], &[], @@ -392,12 +388,12 @@ impl PlatformRepository { ) { let ssl_library_raw = ssl_matches .get(&CaptureKey::ByName("library".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); let ssl_version = ssl_matches .get(&CaptureKey::ByName("version".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); let library = strtolower(&ssl_library_raw); if library == "openssl" { let mut is_fips = false; @@ -426,8 +422,8 @@ impl PlatformRepository { shortlib = "securetransport".to_string(); let m1 = securetransport_matches .get(&CaptureKey::ByIndex(1)) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); ssl_lib = format!("curl-{}", m1); } else { shortlib = library.clone(); @@ -457,12 +453,12 @@ impl PlatformRepository { ) { let ssh_library = ssh_matches .get(&CaptureKey::ByName("library".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); let ssh_version = ssh_matches .get(&CaptureKey::ByName("version".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); self.add_library( &mut libraries, &format!("{}-{}", name, strtolower(&ssh_library)), @@ -480,9 +476,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-zlib", name), - zlib_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + zlib_matches.get(&CaptureKey::ByName("version".to_string())), Some("curl zlib version"), &[], &[], @@ -500,9 +494,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-timelib", name), - timelib_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + timelib_matches.get(&CaptureKey::ByName("version".to_string())), Some("date timelib version"), &[], &[], @@ -526,8 +518,8 @@ impl PlatformRepository { ) { let zoneinfo_version = zoneinfo_matches .get(&CaptureKey::ByName("version".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); // If the timezonedb is provided by ext/timezonedb, register that version as a replacement if external && loaded_extensions.iter().any(|n| n == "timezonedb") { self.add_library( @@ -564,9 +556,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libmagic", name), - magic_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + magic_matches.get(&CaptureKey::ByName("version".to_string())), Some("fileinfo libmagic version"), &[], &[], @@ -597,8 +587,8 @@ impl PlatformRepository { ) { let libjpeg_version = libjpeg_matches .get(&CaptureKey::ByName("version".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); let parsed = Version::parse_libjpeg(&libjpeg_version).unwrap_or_default(); self.add_library( &mut libraries, @@ -616,9 +606,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libpng", name), - libpng_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + libpng_matches.get(&CaptureKey::ByName("version".to_string())), Some("libpng version for gd"), &[], &[], @@ -632,9 +620,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-freetype", name), - freetype_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + freetype_matches.get(&CaptureKey::ByName("version".to_string())), Some("freetype version for gd"), &[], &[], @@ -719,9 +705,7 @@ impl PlatformRepository { self.add_library( &mut libraries, "icu", - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), Some(description), &[], &[], @@ -736,8 +720,8 @@ impl PlatformRepository { ) { let zi_version = zoneinfo_matches .get(&CaptureKey::ByName("version".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); if let Some(parsed) = Version::parse_zoneinfo_version(&zi_version) { self.add_library( &mut libraries, @@ -799,8 +783,8 @@ impl PlatformRepository { ) { let mut version_built = matches .get(&CaptureKey::ByName("version".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); if let Some(patch) = matches.get(&CaptureKey::ByName("patch".to_string())) { version_built = format!("{}.{}", version_built, patch); } @@ -832,8 +816,8 @@ impl PlatformRepository { let converted = Version::convert_openldap_version_id(version_id); let vendor = vendor_matches .get(&CaptureKey::ByName("vendor".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); self.add_library( &mut libraries, &format!("{}-{}", name, strtolower(&vendor)), @@ -880,9 +864,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libmbfl", name), - libmbfl_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + libmbfl_matches.get(&CaptureKey::ByName("version".to_string())), Some("mbstring libmbfl version"), &[], &[], @@ -916,9 +898,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-oniguruma", name), - oniguruma_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + oniguruma_matches.get(&CaptureKey::ByName("version".to_string())), Some("mbstring oniguruma version"), &[], &[], @@ -938,9 +918,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libmemcached", name), - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), Some("libmemcached version"), &[], &[], @@ -961,8 +939,8 @@ impl PlatformRepository { ) { let version = matches .get(&CaptureKey::ByName("version".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); let mut is_fips = false; let parsed_version = Version::parse_openssl(&version, &mut is_fips).unwrap_or_default(); @@ -1001,9 +979,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-unicode", name), - pcre_unicode_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + pcre_unicode_matches.get(&CaptureKey::ByName("version".to_string())), Some("PCRE Unicode version support"), &[], &[], @@ -1023,9 +999,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-mysqlnd", name), - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), Some(&format!("mysqlnd library version for {}", name)), &[], &[], @@ -1043,9 +1017,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libmongoc", name), - libmongoc_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + libmongoc_matches.get(&CaptureKey::ByName("version".to_string())), Some("libmongoc version of mongodb"), &[], &[], @@ -1059,9 +1031,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libbson", name), - libbson_matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + libbson_matches.get(&CaptureKey::ByName("version".to_string())), Some("libbson version of mongodb"), &[], &[], @@ -1095,9 +1065,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libpq", name), - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), Some(&format!("libpq for {}", name)), &[], &[], @@ -1116,9 +1084,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libpq", name), - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), Some(&format!("libpq for {}", name)), &[], &[], @@ -1138,9 +1104,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libpq", name), - matches - .get(&CaptureKey::ByName("linked".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("linked".to_string())), Some(&format!("libpq for {}", name)), &[], &[], @@ -1213,9 +1177,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-sqlite", name), - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), None, &[], &[], @@ -1232,9 +1194,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libssh2", name), - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), None, &[], &[], @@ -1268,9 +1228,7 @@ impl PlatformRepository { self.add_library( &mut libraries, "libxslt-libxml", - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), Some("libxml version libxslt is compiled against"), &[], &[], @@ -1287,9 +1245,7 @@ impl PlatformRepository { self.add_library( &mut libraries, &format!("{}-libyaml", name), - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), Some("libyaml version of yaml"), &[], &[], @@ -1342,9 +1298,7 @@ impl PlatformRepository { self.add_library( &mut libraries, name, - matches - .get(&CaptureKey::ByName("version".to_string())) - .map(|s| s.as_str()), + matches.get(&CaptureKey::ByName("version".to_string())), None, &[], &[], @@ -1540,7 +1494,10 @@ impl PlatformRepository { php_regex!("{^(\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)}"), &pretty_version, ) { - pretty_version = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); + pretty_version = m + .get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(); } else { pretty_version = "0".to_string(); } diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 9e156418..8aa72a6c 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -587,7 +587,7 @@ impl ForgejoDriver { if let Some(m) = Preg::match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), &link) && let Some(url) = m.get(&CaptureKey::ByIndex(1)) { - return Some(url.clone()); + return Some(url.to_string()); } } diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index cf1f5f98..e053cadf 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -95,8 +95,14 @@ impl GitBitbucketDriver { .into()); }; - self.owner = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); - self.repository = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); + self.owner = m + .get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(); + self.repository = m + .get(&CaptureKey::ByIndex(2)) + .unwrap_or_default() + .to_string(); self.inner.origin_url = "bitbucket.org".to_string(); self.inner.cache = Some(Cache::new( self.inner.io.clone(), diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index 99275e98..bd56766b 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -202,7 +202,7 @@ impl GitDriver { && let Some(caps) = Preg::match3(php_regex!(r"{^\* +(\S+)}"), branch) && let Some(name) = caps.get(&CaptureKey::ByIndex(1)) { - self.root_identifier = Some(name.clone()); + self.root_identifier = Some(name.to_string()); break; } } @@ -321,7 +321,7 @@ impl GitDriver { self.tags .as_mut() .unwrap() - .insert(name.clone(), hash.clone()); + .insert(name.to_string(), hash.to_string()); } } } @@ -358,7 +358,7 @@ impl GitDriver { ) && !name.starts_with('-') { - branches.insert(name.clone(), hash.clone()); + branches.insert(name.to_string(), hash.to_string()); } } diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index 7cbceaf2..08561171 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -85,22 +85,22 @@ impl GitHubDriver { self.owner = match_ .get(&CaptureKey::ByIndex(3)) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); self.repository = match_ .get(&CaptureKey::ByIndex(4)) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); self.inner.origin_url = strtolower( &match_ .get(&CaptureKey::ByIndex(1)) - .cloned() .filter(|s| !s.is_empty()) + .map(str::to_string) .unwrap_or_else(|| { match_ .get(&CaptureKey::ByIndex(2)) - .cloned() .unwrap_or_default() + .to_string() }), ); if self.inner.origin_url == "www.github.com" { @@ -494,14 +494,23 @@ impl GitHubDriver { for line in preg_split(php_regex!(r"{\r?\n}"), &funding) { let line = trim(&line, None); if let Some(m) = Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*(.+)$}"), &line) { - let g1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); - let g2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); + let g1 = m + .get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(); + let g2 = m + .get(&CaptureKey::ByIndex(2)) + .unwrap_or_default() + .to_string(); if g2 == "[" { key = Some(g1); continue; } if let Some(m2) = Preg::is_match3(php_regex!(r"{^\[(.*?)\](?:\s*#.*)?$}"), &g2) { - let inner = m2.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); + let inner = m2 + .get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(); for item in array_map( |s: &String| trim(s, None), &preg_split(php_regex!(r#"{[\'\"]?\s*,\s*[\'\"]?}"#), &inner), @@ -522,7 +531,7 @@ impl GitHubDriver { entry.insert( "url".to_string(), PhpMixed::String(trim( - &m2.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(), + m2.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), Some("\"' "), )), ); @@ -530,7 +539,11 @@ impl GitHubDriver { } key = None; } else if let Some(m) = Preg::is_match3(php_regex!(r"{^(\w+)\s*:\s*#\s*$}"), &line) { - key = Some(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default()); + key = Some( + m.get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(), + ); } else if key.is_some() && let Some(m) = Preg::is_match3(php_regex!(r"{^-\s*(.+)(?:\s+#.*)?$}"), &line) .or_else(|| Preg::is_match3(php_regex!(r"{^(.+),(?:\s*#.*)?$}"), &line)) @@ -543,7 +556,7 @@ impl GitHubDriver { entry.insert( "url".to_string(), PhpMixed::String(trim( - &m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(), + m.get(&CaptureKey::ByIndex(1)).unwrap_or_default(), Some("\"' "), )), ); @@ -936,13 +949,13 @@ impl GitHubDriver { let origin_url = matches .get(&CaptureKey::ByIndex(2)) - .cloned() .filter(|s| !s.is_empty()) + .map(str::to_string) .unwrap_or_else(|| { matches .get(&CaptureKey::ByIndex(3)) - .cloned() .unwrap_or_default() + .to_string() }); if !in_array_loose( strtolower(&Preg::replace(php_regex!(r"{^www\.}i"), "", &origin_url)), @@ -1272,7 +1285,11 @@ impl GitHubDriver { let links = explode(",", &header); for link in &links { if let Some(m) = Preg::is_match3(php_regex!(r#"{<(.+?)>; *rel="next"}"#), link) { - return Some(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default()); + return Some( + m.get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(), + ); } } diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 1887ddc4..5494feed 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -91,27 +91,26 @@ impl GitLabDriver { let guessed_domain = match_ .get(&CaptureKey::ByName("domain".to_string())) - .cloned() .filter(|s| !s.is_empty()) + .map(str::to_string) .unwrap_or_else(|| { match_ .get(&CaptureKey::ByName("domain2".to_string())) - .cloned() .unwrap_or_default() + .to_string() }); let configured_domains = self.inner.config.borrow_mut().get("gitlab-domains"); let mut url_parts: Vec = explode( "/", - &match_ + match_ .get(&CaptureKey::ByName("parts".to_string())) - .cloned() .unwrap_or_default(), ); let scheme_match = match_ .get(&CaptureKey::ByName("scheme".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); self.scheme = if matches!(scheme_match.as_str(), "https" | "http") { scheme_match } else if self @@ -125,7 +124,9 @@ impl GitLabDriver { } else { "https".to_string() }; - let port = match_.get(&CaptureKey::ByName("port".to_string())).cloned(); + let port = match_ + .get(&CaptureKey::ByName("port".to_string())) + .map(str::to_string); let origin = Self::determine_origin(&configured_domains, guessed_domain, &mut url_parts, port); let origin = match origin { @@ -169,9 +170,8 @@ impl GitLabDriver { self.repository = Preg::replace( php_regex!(r"#(\.git)$#"), "", - &match_ + match_ .get(&CaptureKey::ByName("repo".to_string())) - .cloned() .unwrap_or_default(), ); @@ -950,23 +950,22 @@ impl GitLabDriver { let scheme = match_ .get(&CaptureKey::ByName("scheme".to_string())) - .cloned() - .unwrap_or_default(); + .unwrap_or_default() + .to_string(); let guessed_domain = match_ .get(&CaptureKey::ByName("domain".to_string())) - .cloned() .filter(|s| !s.is_empty()) + .map(str::to_string) .unwrap_or_else(|| { match_ .get(&CaptureKey::ByName("domain2".to_string())) - .cloned() .unwrap_or_default() + .to_string() }); let mut url_parts: Vec = explode( "/", - &match_ + match_ .get(&CaptureKey::ByName("parts".to_string())) - .cloned() .unwrap_or_default(), ); @@ -974,7 +973,9 @@ impl GitLabDriver { &config.borrow().get("gitlab-domains"), guessed_domain, &mut url_parts, - match_.get(&CaptureKey::ByName("port".to_string())).cloned(), + match_ + .get(&CaptureKey::ByName("port".to_string())) + .map(str::to_string), ) .is_none() { @@ -1013,8 +1014,8 @@ impl GitLabDriver { return Some( match_ .get(&CaptureKey::ByIndex(1)) - .cloned() - .unwrap_or_default(), + .unwrap_or_default() + .to_string(), ); } } diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index 0933a643..aae9c7cb 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -236,8 +236,12 @@ impl HgDriver { && let Some(m) = Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:(.*)$)"), &tag) { tags.insert( - m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(), - m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(), + m.get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(), + m.get(&CaptureKey::ByIndex(2)) + .unwrap_or_default() + .to_string(), ); } } @@ -265,11 +269,16 @@ impl HgDriver { && let Some(m) = Preg::match3(php_regex!(r"(^([^\s]+)\s+\d+:([a-f0-9]+))"), &branch) { - let name = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); + let name = m + .get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(); if !name.starts_with('-') { branches.insert( name, - m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(), + m.get(&CaptureKey::ByIndex(2)) + .unwrap_or_default() + .to_string(), ); } } @@ -286,11 +295,16 @@ impl HgDriver { && let Some(m) = Preg::match3(php_regex!(r"(^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$)"), &branch) { - let name = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); + let name = m + .get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(); if !name.starts_with('-') { bookmarks.insert( name, - m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(), + m.get(&CaptureKey::ByIndex(2)) + .unwrap_or_default() + .to_string(), ); } } diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index 05380a17..9426e1f3 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -321,7 +321,10 @@ impl SvnDriver { && let Some(m) = Preg::is_match3(php_regex!(r"{^Last Changed Date: ([^(]+)}"), &line) { - let date_str = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); + let date_str = m + .get(&CaptureKey::ByIndex(1)) + .unwrap_or_default() + .to_string(); return Ok(shirabe_php_shim::date_create::(date_str.trim()) .ok() .map(|d| d.fixed_offset())); @@ -353,7 +356,10 @@ impl SvnDriver { .get(&CaptureKey::ByIndex(1)) .and_then(|s| s.parse().ok()) .unwrap_or(0); - let path = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); + let path = m + .get(&CaptureKey::ByIndex(2)) + .unwrap_or_default() + .to_string(); if path == "./" { last_rev = rev; } else { @@ -399,7 +405,10 @@ impl SvnDriver { .get(&CaptureKey::ByIndex(1)) .and_then(|s| s.parse().ok()) .unwrap_or(0); - let path = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); + let path = m + .get(&CaptureKey::ByIndex(2)) + .unwrap_or_default() + .to_string(); if path == "./" { let identifier = self.build_identifier( &format!("/{}", self.trunk_path.clone().unwrap_or_default()), @@ -437,7 +446,10 @@ impl SvnDriver { .get(&CaptureKey::ByIndex(1)) .and_then(|s| s.parse().ok()) .unwrap_or(0); - let path = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(); + let path = m + .get(&CaptureKey::ByIndex(2)) + .unwrap_or_default() + .to_string(); if path == "./" { last_rev = rev; } else { -- cgit v1.3.1-4-g156e