aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository/vcs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 01:16:50 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 02:22:41 +0900
commitefec43b3b8827820cf35fe1b73d8e33f5fe84eb4 (patch)
treea62bbba72324de48be5f8e689559f8d9e288fc61 /crates/shirabe/src/repository/vcs
parentcac18ef73a39b4ac41fa4d6ccb753804d4c42cb7 (diff)
downloadphp-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.gz
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.zst
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.zip
refactor: auto-fix clippy warnings
Diffstat (limited to 'crates/shirabe/src/repository/vcs')
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs85
-rw-r--r--crates/shirabe/src/repository/vcs/fossil_driver.rs30
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs20
-rw-r--r--crates/shirabe/src/repository/vcs/git_driver.rs47
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs77
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs60
-rw-r--r--crates/shirabe/src/repository/vcs/hg_driver.rs26
-rw-r--r--crates/shirabe/src/repository/vcs/perforce_driver.rs7
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs47
-rw-r--r--crates/shirabe/src/repository/vcs/vcs_driver.rs114
10 files changed, 245 insertions, 268 deletions
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
index df52820..3706e02 100644
--- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs
+++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
@@ -76,7 +76,7 @@ impl ForgejoDriver {
None,
false,
));
- self.inner.cache.as_mut().map(|c| {
+ if let Some(c) = self.inner.cache.as_mut() {
c.set_read_only(
self.inner
.config
@@ -85,7 +85,7 @@ impl ForgejoDriver {
.as_bool()
.unwrap_or(false),
)
- });
+ }
self.fetch_repository_data()?;
@@ -114,11 +114,8 @@ impl ForgejoDriver {
let needs_git_blob = if let PhpMixed::Array(ref arr) = resource {
let content_empty = arr
.get("content")
- .map_or(true, |v| v.as_string().map_or(true, |s| s.is_empty()));
- let encoding_none = arr
- .get("encoding")
- .and_then(|v| v.as_string())
- .map_or(false, |s| s == "none");
+ .is_none_or(|v| v.as_string().is_none_or(|s| s.is_empty()));
+ let encoding_none = arr.get("encoding").and_then(|v| v.as_string()) == Some("none");
let has_git_url = arr.contains_key("git_url");
content_empty && encoding_none && has_git_url
} else {
@@ -143,10 +140,7 @@ impl ForgejoDriver {
let content_b64 = if let PhpMixed::Array(ref arr) = resource {
let has_content = arr.contains_key("content");
- let encoding_ok = arr
- .get("encoding")
- .and_then(|v| v.as_string())
- .map_or(false, |s| s == "base64");
+ let encoding_ok = arr.get("encoding").and_then(|v| v.as_string()) == Some("base64");
if has_content && encoding_ok {
arr.get("content")
.and_then(|v| v.as_string())
@@ -357,25 +351,25 @@ impl ForgejoDriver {
file_content,
|| self.get_change_date(identifier),
)?;
- if self.inner.should_cache(identifier) {
- if let Some(ref composer_map) = c {
- let encoded = JsonFile::encode_with_options(
- &PhpMixed::Array(
- composer_map
- .iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- ),
- JsonEncodeOptions {
- pretty_print: false,
- ..Default::default()
- },
- );
- self.inner
- .cache
- .as_mut()
- .map(|c| c.write(identifier, &encoded));
- }
+ if self.inner.should_cache(identifier)
+ && let Some(ref composer_map) = c
+ {
+ let encoded = JsonFile::encode_with_options(
+ &PhpMixed::Array(
+ composer_map
+ .iter()
+ .map(|(k, v)| (k.clone(), Box::new(v.clone())))
+ .collect(),
+ ),
+ JsonEncodeOptions {
+ pretty_print: false,
+ ..Default::default()
+ },
+ );
+ self.inner
+ .cache
+ .as_mut()
+ .map(|c| c.write(identifier, &encoded));
}
c
}
@@ -392,7 +386,7 @@ impl ForgejoDriver {
// specials for forgejo
let support_not_array = composer_map
.get("support")
- .map_or(false, |v| v.as_array().is_none());
+ .is_some_and(|v| v.as_array().is_none());
if support_not_array {
composer_map.insert("support".to_string(), PhpMixed::Array(IndexMap::new()));
}
@@ -400,7 +394,7 @@ impl ForgejoDriver {
let has_source = composer_map
.get("support")
.and_then(|v| v.as_array())
- .map_or(false, |arr| arr.contains_key("source"));
+ .is_some_and(|arr| arr.contains_key("source"));
if !has_source {
let html_url = self
@@ -437,14 +431,9 @@ impl ForgejoDriver {
let has_issues = composer_map
.get("support")
.and_then(|v| v.as_array())
- .map_or(false, |arr| arr.contains_key("issues"));
+ .is_some_and(|arr| arr.contains_key("issues"));
- if !has_issues
- && self
- .repository_data
- .as_ref()
- .map_or(false, |r| r.has_issues)
- {
+ if !has_issues && self.repository_data.as_ref().is_some_and(|r| r.has_issues) {
let issues_url = format!(
"{}/issues",
self.repository_data
@@ -459,10 +448,7 @@ impl ForgejoDriver {
}
if !composer_map.contains_key("abandoned")
- && self
- .repository_data
- .as_ref()
- .map_or(false, |r| r.is_archived)
+ && self.repository_data.as_ref().is_some_and(|r| r.is_archived)
{
composer_map.insert("abandoned".to_string(), PhpMixed::Bool(true));
}
@@ -520,9 +506,8 @@ impl ForgejoDriver {
let forgejo_domains = config.borrow().get("forgejo-domains");
let in_domains = if let Some(list) = forgejo_domains.as_list() {
list.iter().any(|d| {
- d.as_string().map_or(false, |s| {
- s.to_lowercase() == forgejo_url.origin_url.to_lowercase()
- })
+ d.as_string()
+ .is_some_and(|s| s.to_lowercase() == forgejo_url.origin_url.to_lowercase())
})
} else {
false
@@ -605,10 +590,10 @@ impl ForgejoDriver {
let links = explode(",", &header);
for link in links {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r#"{<(.+?)>; *rel="next"}"#, &link, Some(&mut m)) {
- if let Some(url) = m.get(&CaptureKey::ByIndex(1)) {
- return Some(url.clone());
- }
+ if Preg::match3(r#"{<(.+?)>; *rel="next"}"#, &link, Some(&mut m))
+ && let Some(url) = m.get(&CaptureKey::ByIndex(1))
+ {
+ return Some(url.clone());
}
}
diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs
index c205379..1da7a2a 100644
--- a/crates/shirabe/src/repository/vcs/fossil_driver.rs
+++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs
@@ -101,7 +101,7 @@ impl FossilDriver {
pub(crate) fn check_fossil(&self) -> anyhow::Result<()> {
let mut ignored_output = String::new();
if self.inner.process.borrow_mut().execute_args(
- &["fossil", "version"].map(|s| s.to_string()).to_vec(),
+ ["fossil", "version"].map(|s| s.to_string()).as_ref(),
&mut ignored_output,
(),
) != 0
@@ -141,13 +141,13 @@ impl FossilDriver {
if is_file(&repo_file)
&& is_dir(&self.checkout_dir)
&& self.inner.process.borrow_mut().execute_args(
- &["fossil", "info"].map(|s| s.to_string()).to_vec(),
+ ["fossil", "info"].map(|s| s.to_string()).as_ref(),
&mut String::new(),
Some(self.checkout_dir.clone()),
) == 0
{
if self.inner.process.borrow_mut().execute_args(
- &["fossil", "pull"].map(|s| s.to_string()).to_vec(),
+ ["fossil", "pull"].map(|s| s.to_string()).as_ref(),
&mut String::new(),
Some(self.checkout_dir.clone()),
) != 0
@@ -166,9 +166,9 @@ impl FossilDriver {
let mut output = String::new();
if self.inner.process.borrow_mut().execute_args(
- &["fossil", "clone", "--", &self.inner.url, &repo_file]
+ ["fossil", "clone", "--", &self.inner.url, &repo_file]
.map(|s| s.to_string())
- .to_vec(),
+ .as_ref(),
&mut output,
(),
) != 0
@@ -185,9 +185,9 @@ impl FossilDriver {
}
if self.inner.process.borrow_mut().execute_args(
- &["fossil", "open", "--nested", "--", &repo_file]
+ ["fossil", "open", "--nested", "--", &repo_file]
.map(|s| s.to_string())
- .to_vec(),
+ .as_ref(),
&mut output,
Some(self.checkout_dir.clone()),
) != 0
@@ -244,9 +244,9 @@ impl FossilDriver {
let mut content = String::new();
self.inner.process.borrow_mut().execute_args(
- &["fossil", "cat", "-r", identifier, "--", file]
+ ["fossil", "cat", "-r", identifier, "--", file]
.map(|s| s.to_string())
- .to_vec(),
+ .as_ref(),
&mut content,
Some(self.checkout_dir.clone()),
);
@@ -264,9 +264,9 @@ impl FossilDriver {
) -> anyhow::Result<Option<DateTime<FixedOffset>>> {
let mut output = String::new();
self.inner.process.borrow_mut().execute_args(
- &["fossil", "finfo", "-b", "-n", "1", "composer.json"]
+ ["fossil", "finfo", "-b", "-n", "1", "composer.json"]
.map(|s| s.to_string())
- .to_vec(),
+ .as_ref(),
&mut output,
Some(self.checkout_dir.clone()),
);
@@ -282,7 +282,7 @@ impl FossilDriver {
let mut tags: IndexMap<String, String> = IndexMap::new();
let mut output = String::new();
self.inner.process.borrow_mut().execute_args(
- &["fossil", "tag", "list"].map(|s| s.to_string()).to_vec(),
+ ["fossil", "tag", "list"].map(|s| s.to_string()).as_ref(),
&mut output,
Some(self.checkout_dir.clone()),
);
@@ -299,12 +299,12 @@ impl FossilDriver {
let mut branches: IndexMap<String, String> = IndexMap::new();
let mut output = String::new();
self.inner.process.borrow_mut().execute_args(
- &["fossil", "branch", "list"].map(|s| s.to_string()).to_vec(),
+ ["fossil", "branch", "list"].map(|s| s.to_string()).as_ref(),
&mut output,
Some(self.checkout_dir.clone()),
);
for branch in self.inner.process.borrow().split_lines(&output) {
- let branch = Preg::replace(r"/^\*/", "", &branch.trim());
+ let branch = Preg::replace(r"/^\*/", "", branch.trim());
let branch = branch.trim().to_string();
branches.insert(branch.clone(), branch);
}
@@ -340,7 +340,7 @@ impl FossilDriver {
let mut process = ProcessExecutor::new(Some(io));
let mut output = String::new();
if process.execute_args(
- &["fossil", "info"].map(|s| s.to_string()).to_vec(),
+ ["fossil", "info"].map(|s| s.to_string()).as_ref(),
&mut output,
Some(url),
) == 0
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index b0985e5..44c0d08 100644
--- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
@@ -789,16 +789,16 @@ impl GitBitbucketDriver {
_ => return,
};
for clone_link in list {
- if let PhpMixed::Array(m) = clone_link.as_ref() {
- if m.get("name").and_then(|v| v.as_string()) == Some("https") {
- // Format: https://(user@)bitbucket.org/{user}/{repo}
- // Strip username from URL (only present in clone URL's for private repositories)
- self.clone_https_url = Preg::replace(
- r"/https:\/\/([^@]+@)?/",
- "https://",
- m.get("href").and_then(|v| v.as_string()).unwrap_or(""),
- );
- }
+ if let PhpMixed::Array(m) = clone_link.as_ref()
+ && m.get("name").and_then(|v| v.as_string()) == Some("https")
+ {
+ // Format: https://(user@)bitbucket.org/{user}/{repo}
+ // Strip username from URL (only present in clone URL's for private repositories)
+ self.clone_https_url = Preg::replace(
+ r"/https:\/\/([^@]+@)?/",
+ "https://",
+ m.get("href").and_then(|v| v.as_string()).unwrap_or(""),
+ );
}
}
}
diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs
index 3c950bb..e639649 100644
--- a/crates/shirabe/src/repository/vcs/git_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_driver.rs
@@ -167,7 +167,7 @@ impl GitDriver {
None,
false,
));
- self.inner.cache.as_mut().map(|c| {
+ if let Some(c) = self.inner.cache.as_mut() {
c.set_read_only(
self.inner
.config
@@ -176,7 +176,7 @@ impl GitDriver {
.as_bool()
.unwrap_or(false),
)
- });
+ }
Ok(())
}
@@ -215,11 +215,11 @@ impl GitDriver {
for branch in &branches {
if !branch.is_empty() {
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"{^\* +(\S+)}", branch, Some(&mut caps)) {
- if let Some(name) = caps.get(&CaptureKey::ByIndex(1)) {
- self.root_identifier = Some(name.clone());
- break;
- }
+ if Preg::match3(r"{^\* +(\S+)}", branch, Some(&mut caps))
+ && let Some(name) = caps.get(&CaptureKey::ByIndex(1))
+ {
+ self.root_identifier = Some(name.clone());
+ break;
}
}
}
@@ -338,16 +338,14 @@ impl GitDriver {
r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}",
&tag,
Some(&mut caps),
+ ) && let (Some(hash), Some(name)) = (
+ caps.get(&CaptureKey::ByIndex(1)),
+ caps.get(&CaptureKey::ByIndex(2)),
) {
- if let (Some(hash), Some(name)) = (
- caps.get(&CaptureKey::ByIndex(1)),
- caps.get(&CaptureKey::ByIndex(2)),
- ) {
- self.tags
- .as_mut()
- .unwrap()
- .insert(name.clone(), hash.clone());
- }
+ self.tags
+ .as_mut()
+ .unwrap()
+ .insert(name.clone(), hash.clone());
}
}
}
@@ -379,15 +377,12 @@ impl GitDriver {
r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}",
&branch,
Some(&mut caps),
- ) {
- if let (Some(name), Some(hash)) = (
- caps.get(&CaptureKey::ByIndex(1)),
- caps.get(&CaptureKey::ByIndex(2)),
- ) {
- if !name.starts_with('-') {
- branches.insert(name.clone(), hash.clone());
- }
- }
+ ) && let (Some(name), Some(hash)) = (
+ caps.get(&CaptureKey::ByIndex(1)),
+ caps.get(&CaptureKey::ByIndex(2)),
+ ) && !name.starts_with('-')
+ {
+ branches.insert(name.clone(), hash.clone());
}
}
}
@@ -430,7 +425,7 @@ impl GitDriver {
return Ok(true);
}
GitUtil::check_for_repo_ownership_error(
- &process.borrow().get_error_output(),
+ process.borrow().get_error_output(),
&url,
Some(io.clone()),
)?;
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs
index 696851e..8c8c81a 100644
--- a/crates/shirabe/src/repository/vcs/github_driver.rs
+++ b/crates/shirabe/src/repository/vcs/github_driver.rs
@@ -130,7 +130,7 @@ impl GitHubDriver {
None,
false,
));
- self.inner.cache.as_mut().map(|c| {
+ if let Some(c) = self.inner.cache.as_mut() {
c.set_read_only(
self.inner
.config
@@ -139,7 +139,7 @@ impl GitHubDriver {
.as_bool()
.unwrap_or(false),
)
- });
+ }
if self
.inner
@@ -290,27 +290,27 @@ impl GitHubDriver {
|| self.get_change_date(identifier),
)?;
- if self.inner.should_cache(identifier) {
- if let Some(ref composer_map) = composer {
- let php_value: PhpMixed = PhpMixed::Array(
- composer_map
- .iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- );
- self.inner.cache.as_mut().map(|c| {
- c.write(
- identifier,
- &JsonFile::encode_with_options(
- &php_value,
- JsonEncodeOptions {
- pretty_print: false,
- ..Default::default()
- },
- ),
- )
- });
- }
+ if self.inner.should_cache(identifier)
+ && let Some(ref composer_map) = composer
+ {
+ let php_value: PhpMixed = PhpMixed::Array(
+ composer_map
+ .iter()
+ .map(|(k, v)| (k.clone(), Box::new(v.clone())))
+ .collect(),
+ );
+ self.inner.cache.as_mut().map(|c| {
+ c.write(
+ identifier,
+ &JsonFile::encode_with_options(
+ &php_value,
+ JsonEncodeOptions {
+ pretty_print: false,
+ ..Default::default()
+ },
+ ),
+ )
+ });
}
composer
@@ -379,21 +379,22 @@ impl GitHubDriver {
.and_then(|v| v.as_array())
.map(|m| m.contains_key("issues"))
.unwrap_or(false);
- if issues_missing && self.has_issues {
- if let Some(support) = composer.get_mut("support").and_then(|v| match v {
+ if issues_missing
+ && self.has_issues
+ && let Some(support) = composer.get_mut("support").and_then(|v| match v {
PhpMixed::Array(m) => Some(m),
_ => None,
- }) {
- support.insert(
- "issues".to_string(),
- Box::new(PhpMixed::String(format!(
- "https://{}/{}/{}/issues",
- PhpMixed::String(self.inner.origin_url.clone()),
- PhpMixed::String(self.owner.clone()),
- PhpMixed::String(self.repository.clone()),
- ))),
- );
- }
+ })
+ {
+ support.insert(
+ "issues".to_string(),
+ Box::new(PhpMixed::String(format!(
+ "https://{}/{}/{}/issues",
+ PhpMixed::String(self.inner.origin_url.clone()),
+ PhpMixed::String(self.owner.clone()),
+ PhpMixed::String(self.repository.clone()),
+ ))),
+ );
}
if !composer.contains_key("abandoned") && self.is_archived {
composer.insert("abandoned".to_string(), PhpMixed::Bool(true));
@@ -1066,7 +1067,9 @@ impl GitHubDriver {
let scopes_failed = array_diff(&scopes_needed, &scopes_issued);
// non-authenticated requests get no scopesNeeded, so ask for credentials
// authenticated requests which failed some scopes should ask for new credentials too
- if headers.is_empty() || scopes_needed.is_empty() || scopes_failed.len() > 0
+ if headers.is_empty()
+ || scopes_needed.is_empty()
+ || !scopes_failed.is_empty()
{
git_hub_util.authorize_oauth_interactively(
&self.inner.origin_url,
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index fc09108..a5e6b73 100644
--- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs
+++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
@@ -222,7 +222,7 @@ impl GitLabDriver {
None,
false,
));
- self.inner.cache.as_mut().map(|c| {
+ if let Some(c) = self.inner.cache.as_mut() {
c.set_read_only(
self.inner
.config
@@ -231,7 +231,7 @@ impl GitLabDriver {
.as_bool()
.unwrap_or(false),
)
- });
+ }
self.fetch_project()?;
@@ -283,27 +283,27 @@ impl GitLabDriver {
|| self.get_change_date(identifier),
)?;
- if self.inner.should_cache(identifier) {
- if let Some(ref composer_map) = composer {
- self.inner.cache.as_mut().map(|c| {
- c.write(
- identifier,
- &JsonFile::encode_with_options(
- &PhpMixed::Array(
- composer_map
- .clone()
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
- JsonEncodeOptions {
- pretty_print: false,
- ..Default::default()
- },
+ if self.inner.should_cache(identifier)
+ && let Some(ref composer_map) = composer
+ {
+ self.inner.cache.as_mut().map(|c| {
+ c.write(
+ identifier,
+ &JsonFile::encode_with_options(
+ &PhpMixed::Array(
+ composer_map
+ .clone()
+ .into_iter()
+ .map(|(k, v)| (k, Box::new(v)))
+ .collect(),
),
- )
- });
- }
+ JsonEncodeOptions {
+ pretty_print: false,
+ ..Default::default()
+ },
+ ),
+ )
+ });
}
composer
@@ -615,7 +615,7 @@ impl GitLabDriver {
]),
true,
) {
- format!("%{}", format!("{:02X}", ord(&character)))
+ format!("%{:02X}", ord(&character))
} else {
character
};
@@ -828,14 +828,12 @@ impl GitLabDriver {
json_map.get("permissions").and_then(|v| v.as_array())
{
for (_, permission) in permissions {
- if let Some(perm_map) = permission.as_array() {
- if let Some(level) =
+ if let Some(perm_map) = permission.as_array()
+ && let Some(level) =
perm_map.get("access_level").and_then(|v| v.as_int())
- {
- if level >= 20 {
- more_than_guest_access = true;
- }
- }
+ && level >= 20
+ {
+ more_than_guest_access = true;
}
}
}
@@ -874,7 +872,7 @@ impl GitLabDriver {
}
if !empty(
- &*json_map
+ &json_map
.get("id")
.cloned()
.unwrap_or(Box::new(PhpMixed::Null)),
diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs
index 63a400c..4a6188e 100644
--- a/crates/shirabe/src/repository/vcs/hg_driver.rs
+++ b/crates/shirabe/src/repository/vcs/hg_driver.rs
@@ -85,19 +85,19 @@ impl HgDriver {
let hg_utils = HgUtils::new(
self.inner.io.clone(),
- &*self.inner.config.borrow(),
+ &self.inner.config.borrow(),
&self.inner.process,
);
if is_dir(&self.repo_dir)
&& self.inner.process.borrow_mut().execute_args(
- &["hg", "summary"].map(|s| s.to_string()).to_vec(),
+ ["hg", "summary"].map(|s| s.to_string()).as_ref(),
&mut String::new(),
Some(self.repo_dir.clone()),
) == 0
{
if self.inner.process.borrow_mut().execute_args(
- &["hg", "pull"].map(|s| s.to_string()).to_vec(),
+ ["hg", "pull"].map(|s| s.to_string()).as_ref(),
&mut String::new(),
Some(self.repo_dir.clone()),
) != 0
@@ -134,9 +134,9 @@ impl HgDriver {
if self.root_identifier.is_none() {
let mut output = String::new();
self.inner.process.borrow_mut().execute_args(
- &["hg", "tip", "--template", "{node}"]
+ ["hg", "tip", "--template", "{node}"]
.map(|s| s.to_string())
- .to_vec(),
+ .as_ref(),
&mut output,
Some(self.repo_dir.clone()),
);
@@ -214,7 +214,7 @@ impl HgDriver {
let mut output = String::new();
self.inner.process.borrow_mut().execute_args(
- &[
+ [
"hg",
"log",
"--template",
@@ -223,7 +223,7 @@ impl HgDriver {
identifier,
]
.map(|s| s.to_string())
- .to_vec(),
+ .as_ref(),
&mut output,
Some(self.repo_dir.clone()),
);
@@ -237,7 +237,7 @@ impl HgDriver {
let mut tags: IndexMap<String, String> = IndexMap::new();
let mut output = String::new();
self.inner.process.borrow_mut().execute_args(
- &["hg", "tags"].map(|s| s.to_string()).to_vec(),
+ ["hg", "tags"].map(|s| s.to_string()).as_ref(),
&mut output,
Some(self.repo_dir.clone()),
);
@@ -267,7 +267,7 @@ impl HgDriver {
let mut output = String::new();
self.inner.process.borrow_mut().execute_args(
- &["hg", "branches"].map(|s| s.to_string()).to_vec(),
+ ["hg", "branches"].map(|s| s.to_string()).as_ref(),
&mut output,
Some(self.repo_dir.clone()),
);
@@ -288,7 +288,7 @@ impl HgDriver {
output.clear();
self.inner.process.borrow_mut().execute_args(
- &["hg", "bookmarks"].map(|s| s.to_string()).to_vec(),
+ ["hg", "bookmarks"].map(|s| s.to_string()).as_ref(),
&mut output,
Some(self.repo_dir.clone()),
);
@@ -337,7 +337,7 @@ impl HgDriver {
let mut process = crate::util::ProcessExecutor::new(Some(io.clone()));
let mut output = String::new();
if process.execute_args(
- &["hg", "summary"].map(|s| s.to_string()).to_vec(),
+ ["hg", "summary"].map(|s| s.to_string()).as_ref(),
&mut output,
Some(url),
) == 0
@@ -353,9 +353,9 @@ impl HgDriver {
let mut process = crate::util::ProcessExecutor::new(Some(io));
let mut ignored = String::new();
let exit = process.execute_args(
- &["hg", "identify", "--", url]
+ ["hg", "identify", "--", url]
.map(|s| s.to_string())
- .to_vec(),
+ .as_ref(),
&mut ignored,
(),
);
diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs
index 10cf913..3077cff 100644
--- a/crates/shirabe/src/repository/vcs/perforce_driver.rs
+++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs
@@ -50,10 +50,9 @@ impl PerforceDriver {
.repo_config
.get("branch")
.and_then(|v| v.as_string())
+ && !branch.is_empty()
{
- if !branch.is_empty() {
- self.branch = branch.to_string();
- }
+ self.branch = branch.to_string();
}
let repo_config = self.inner.repo_config.clone();
@@ -171,7 +170,7 @@ impl PerforceDriver {
.as_mut()
.unwrap()
.get_composer_information(&path)
- .map_or(false, |info| info.map_or(false, |i| !i.is_empty()))
+ .is_ok_and(|info| info.is_some_and(|i| !i.is_empty()))
}
pub fn get_contents(&self, _url: &str) -> anyhow::Result<Response> {
diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs
index b48ce99..6346a84 100644
--- a/crates/shirabe/src/repository/vcs/svn_driver.rs
+++ b/crates/shirabe/src/repository/vcs/svn_driver.rs
@@ -168,33 +168,32 @@ impl SvnDriver {
identifier: &str,
) -> Result<Option<IndexMap<String, PhpMixed>>> {
if !self.inner.info_cache.contains_key(identifier) {
- if self.should_cache(identifier) {
- if let Some(mut res) = self
+ if self.should_cache(identifier)
+ && let Some(mut res) = self
.inner
.cache
.as_mut()
.and_then(|c| c.read(&format!("{}.json", identifier)))
- {
- // old cache files had '' stored instead of null due to af3783b5f40bae32a23e353eaf0a00c9b8ce82e2, so we make sure here that we always return null or array
- // and fix outdated invalid cache files
- if res == "\"\"" {
- res = "null".to_string();
- self.inner
- .cache
- .as_mut()
- .unwrap()
- .write(&format!("{}.json", identifier), &res)?;
- }
-
- let parsed = JsonFile::parse_json(Some(res.as_str()), None)?;
- let composer: Option<IndexMap<String, PhpMixed>> = parsed
- .as_array()
- .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect());
+ {
+ // old cache files had '' stored instead of null due to af3783b5f40bae32a23e353eaf0a00c9b8ce82e2, so we make sure here that we always return null or array
+ // and fix outdated invalid cache files
+ if res == "\"\"" {
+ res = "null".to_string();
self.inner
- .info_cache
- .insert(identifier.to_string(), composer.clone());
- return Ok(composer);
+ .cache
+ .as_mut()
+ .unwrap()
+ .write(&format!("{}.json", identifier), &res)?;
}
+
+ let parsed = JsonFile::parse_json(Some(res.as_str()), None)?;
+ let composer: Option<IndexMap<String, PhpMixed>> = parsed
+ .as_array()
+ .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect());
+ self.inner
+ .info_cache
+ .insert(identifier.to_string(), composer.clone());
+ return Ok(composer);
}
let base_result =
@@ -290,7 +289,7 @@ impl SvnDriver {
return Err(e);
}
};
- if trim(&output, None) == "" {
+ if trim(&output, None).is_empty() {
return Ok(None);
}
@@ -506,14 +505,14 @@ impl SvnDriver {
}
// Subversion client 1.7 and older
- if stripos(&process.get_error_output(), "authorization failed:").is_some() {
+ if stripos(process.get_error_output(), "authorization failed:").is_some() {
// This is likely a remote Subversion repository that requires
// authentication. We will handle actual authentication later.
return Ok(true);
}
// Subversion client 1.8 and newer
- if stripos(&process.get_error_output(), "Authentication failed").is_some() {
+ if stripos(process.get_error_output(), "Authentication failed").is_some() {
// This is likely a remote Subversion or newer repository that requires
// authentication. We will handle actual authentication later.
return Ok(true);
diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs
index d1bb3cc..ac7496d 100644
--- a/crates/shirabe/src/repository/vcs/vcs_driver.rs
+++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs
@@ -119,17 +119,16 @@ impl VcsDriverBase {
let mut composer: IndexMap<String, PhpMixed> =
array.into_iter().map(|(k, v)| (k, *v)).collect();
- if !composer.contains_key("time")
+ if (!composer.contains_key("time")
|| composer
.get("time")
- .map_or(true, |v| v.as_string().map_or(true, |s| s.is_empty()))
+ .is_none_or(|v| v.as_string().is_none_or(|s| s.is_empty())))
+ && let Some(d) = change_date()?
{
- if let Some(d) = change_date()? {
- composer.insert(
- "time".to_string(),
- PhpMixed::String(d.format(DATE_RFC3339).to_string()),
- );
- }
+ composer.insert(
+ "time".to_string(),
+ PhpMixed::String(d.format(DATE_RFC3339).to_string()),
+ );
}
Ok(Some(composer))
@@ -150,16 +149,16 @@ impl VcsDriverBase {
self.info_cache.get(identifier).and_then(|v| v.clone()),
));
}
- if self.should_cache(identifier) {
- if let Some(res) = self.cache.as_mut().and_then(|c| c.read(identifier)) {
- let parsed = JsonFile::parse_json(Some(&res), None)?;
- let composer: Option<IndexMap<String, PhpMixed>> = parsed
- .as_array()
- .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect());
- self.info_cache
- .insert(identifier.to_string(), composer.clone());
- return Ok(Some(composer));
- }
+ if self.should_cache(identifier)
+ && let Some(res) = self.cache.as_mut().and_then(|c| c.read(identifier))
+ {
+ let parsed = JsonFile::parse_json(Some(&res), None)?;
+ let composer: Option<IndexMap<String, PhpMixed>> = parsed
+ .as_array()
+ .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect());
+ self.info_cache
+ .insert(identifier.to_string(), composer.clone());
+ return Ok(Some(composer));
}
Ok(None)
}
@@ -215,38 +214,38 @@ pub trait VcsDriver: VcsDriverInterface {
identifier: &str,
) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
if !self.info_cache().contains_key(identifier) {
- if self.should_cache(identifier) {
- if let Some(res) = self.cache_mut().and_then(|c| c.read(identifier)) {
- let parsed = JsonFile::parse_json(Some(&res), None)?;
- let parsed_map: Option<IndexMap<String, PhpMixed>> = match parsed {
- PhpMixed::Array(a) => Some(a.into_iter().map(|(k, v)| (k, *v)).collect()),
- _ => None,
- };
- self.info_cache_mut()
- .insert(identifier.to_string(), parsed_map);
- return Ok(self.info_cache().get(identifier).and_then(|v| v.clone()));
- }
+ if self.should_cache(identifier)
+ && let Some(res) = self.cache_mut().and_then(|c| c.read(identifier))
+ {
+ let parsed = JsonFile::parse_json(Some(&res), None)?;
+ let parsed_map: Option<IndexMap<String, PhpMixed>> = match parsed {
+ PhpMixed::Array(a) => Some(a.into_iter().map(|(k, v)| (k, *v)).collect()),
+ _ => None,
+ };
+ self.info_cache_mut()
+ .insert(identifier.to_string(), parsed_map);
+ return Ok(self.info_cache().get(identifier).and_then(|v| v.clone()));
}
let composer = self.get_base_composer_information(identifier)?;
- if self.should_cache(identifier) {
- if let Some(ref composer_map) = composer {
- let composer_mixed = PhpMixed::Array(
- composer_map
- .iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- );
- let encoded = JsonFile::encode_with_options(
- &composer_mixed,
- JsonEncodeOptions {
- pretty_print: false,
- ..Default::default()
- },
- );
- self.cache_mut().map(|c| c.write(identifier, &encoded));
- }
+ if self.should_cache(identifier)
+ && let Some(ref composer_map) = composer
+ {
+ let composer_mixed = PhpMixed::Array(
+ composer_map
+ .iter()
+ .map(|(k, v)| (k.clone(), Box::new(v.clone())))
+ .collect(),
+ );
+ let encoded = JsonFile::encode_with_options(
+ &composer_mixed,
+ JsonEncodeOptions {
+ pretty_print: false,
+ ..Default::default()
+ },
+ );
+ self.cache_mut().map(|c| c.write(identifier, &encoded));
}
self.info_cache_mut()
@@ -278,27 +277,26 @@ pub trait VcsDriver: VcsDriverInterface {
_ => return Ok(None),
};
- if !composer.contains_key("time")
+ if (!composer.contains_key("time")
|| composer
.get("time")
- .map_or(true, |v| v.as_string().map_or(true, |s| s.is_empty()))
+ .is_none_or(|v| v.as_string().is_none_or(|s| s.is_empty())))
+ && let Some(change_date) = self.get_change_date(identifier)?
{
- if let Some(change_date) = self.get_change_date(identifier)? {
- composer.insert(
- "time".to_string(),
- PhpMixed::String(change_date.format(DATE_RFC3339).to_string()),
- );
- }
+ composer.insert(
+ "time".to_string(),
+ PhpMixed::String(change_date.format(DATE_RFC3339).to_string()),
+ );
}
Ok(Some(composer))
}
fn has_composer_file(&mut self, identifier: &str) -> bool {
- match VcsDriver::get_composer_information(self, identifier) {
- Ok(Some(_)) => true,
- _ => false,
- }
+ matches!(
+ VcsDriver::get_composer_information(self, identifier),
+ Ok(Some(_))
+ )
}
fn get_scheme(&self) -> &str {