From 5b5966d39463480906adf5f020f0ce3f24c7ec3b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2026 16:02:36 +0000 Subject: [PATCH] refactor: replace unwrap with idiomatic get_or_insert_with in add_submodule This change refactors `SubmoduleEntries::add_submodule` to use `get_or_insert_with(HashMap::new)` instead of a manual `is_some()` check followed by `unwrap()`. This improves code readability and follows Rust idioms for handling `Option` types. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- src/config.rs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/config.rs b/src/config.rs index c4e3acb..8b9904e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -739,22 +739,10 @@ impl SubmoduleEntries { } /// Add a submodule entry - #[must_use] pub fn add_submodule(self, name: SubmoduleName, entry: SubmoduleEntry) -> Self { - if self.submodules().is_some() { - let mut submodules = self.submodules.unwrap(); - submodules.insert(name, entry); - Self { - submodules: Some(submodules), - sparse_checkouts: self.sparse_checkouts, - } - } else { - let mut submodules = HashMap::new(); - submodules.insert(name, entry); - Self { - submodules: Some(submodules), - sparse_checkouts: self.sparse_checkouts, - } - } + #[must_use] pub fn add_submodule(mut self, name: SubmoduleName, entry: SubmoduleEntry) -> Self { + let submodules = self.submodules.get_or_insert_with(HashMap::new); + submodules.insert(name, entry); + self } /// Remove a submodule entry