aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src')
-rw-r--r--crates/shirabe/src/command/init_command.rs19
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs15
-rw-r--r--crates/shirabe/src/package/version/version_bumper.rs9
3 files changed, 27 insertions, 16 deletions
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index c348fa6f..1ca3e428 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -175,17 +175,20 @@ impl InitCommand {
) == 0
{
*self.git_config.borrow_mut() = Some(IndexMap::new());
- let mut m: IndexMap<CaptureKey, Vec<String>> = IndexMap::new();
+ let mut m: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new();
if Preg::is_match_all3(php_regex!(r"{^([^=]+)=(.*)$}m"), &output, Some(&mut m)) {
- let keys: Vec<String> = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
- let values: Vec<String> =
+ let keys: Vec<Option<String>> =
+ m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
+ let values: Vec<Option<String>> =
m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
for (key, value) in keys.iter().zip(values.iter()) {
- self.git_config
- .borrow_mut()
- .as_mut()
- .unwrap()
- .insert(key.clone(), value.clone());
+ self.git_config.borrow_mut().as_mut().unwrap().insert(
+ key.clone()
+ .expect("group 1 participates whenever the pattern matches"),
+ value
+ .clone()
+ .expect("group 2 participates whenever the pattern matches"),
+ );
}
}
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index 4394cc95..b34f7800 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -109,7 +109,7 @@ impl GitDownloader {
.cloned()
.unwrap_or_default();
- let mut branches_match: IndexMap<CaptureKey, Vec<String>> = IndexMap::new();
+ let mut branches_match: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new();
if !Preg::is_match_all3(
format!("{{^{} refs/heads/(.+)$}}mi", preg_quote(&head_ref, None)),
&refs,
@@ -121,7 +121,10 @@ impl GitDownloader {
let candidate_branches: Vec<String> = branches_match
.get(&CaptureKey::ByIndex(1))
.cloned()
- .unwrap_or_default();
+ .unwrap_or_default()
+ .into_iter()
+ .map(|branch| branch.expect("group 1 participates whenever the pattern matches"))
+ .collect();
// use the first match as branch name for now
let mut branch = candidate_branches[0].clone();
@@ -134,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<String>> = IndexMap::new();
+ let mut m: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new();
if Preg::is_match_all3(
format!(
"{{^[a-f0-9]+ refs/remotes/((?:[^/]+)/{})$}}mi",
@@ -143,11 +146,13 @@ impl GitDownloader {
&refs,
Some(&mut m),
) {
- let matches: Vec<String> =
+ let matches: Vec<Option<String>> =
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
for match_ in matches {
branch = candidate.clone();
- remote_branches.push(match_);
+ remote_branches.push(
+ match_.expect("group 1 participates whenever the pattern matches"),
+ );
}
break;
}
diff --git a/crates/shirabe/src/package/version/version_bumper.rs b/crates/shirabe/src/package/version/version_bumper.rs
index fcdbf246..83df211a 100644
--- a/crates/shirabe/src/package/version/version_bumper.rs
+++ b/crates/shirabe/src/package/version/version_bumper.rs
@@ -78,7 +78,7 @@ impl VersionBumper {
major = major
);
- let mut matches: IndexMap<CaptureKey, Vec<(String, usize)>> = IndexMap::new();
+ let mut matches: IndexMap<CaptureKey, Vec<(Option<String>, i64)>> = IndexMap::new();
if Preg::is_match_all_with_offsets3(&pattern, &pretty_constraint, Some(&mut matches)) {
let mut modified = pretty_constraint.clone();
let constraint_matches = matches
@@ -86,8 +86,11 @@ impl VersionBumper {
.cloned()
.unwrap_or_default();
for match_ in constraint_matches.iter().rev() {
- let match_str = &match_.0;
- let match_offset = match_.1 as i64;
+ let match_str = match_
+ .0
+ .as_deref()
+ .expect("the `constraint` group participates whenever the pattern matches");
+ let match_offset = match_.1;
let suffix = if match_str.matches('.').count() == 2
&& version_without_suffix.matches('.').count() == 1
{