From ebc6dc8300998ada3493c01caeb8458641dead6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Sat, 13 Jun 2026 18:50:28 +0200 Subject: [PATCH] Update git2 to 0.21 across crates --- Cargo.lock | 32 ++++-------------------------- asyncgit/Cargo.toml | 2 +- asyncgit/src/sync/branch/mod.rs | 6 ++++-- asyncgit/src/sync/commit.rs | 2 +- asyncgit/src/sync/commit_filter.rs | 18 ++++++++++++----- asyncgit/src/sync/commits_info.rs | 3 ++- asyncgit/src/sync/config.rs | 2 +- asyncgit/src/sync/cred.rs | 18 ++++++++++------- asyncgit/src/sync/hooks.rs | 4 +++- asyncgit/src/sync/remotes/mod.rs | 20 ++++++++++++------- asyncgit/src/sync/remotes/tags.rs | 4 +++- asyncgit/src/sync/submodules.rs | 2 +- asyncgit/src/sync/tree.rs | 6 +++--- git2-hooks/Cargo.toml | 2 +- git2-hooks/src/lib.rs | 2 +- git2-testing/Cargo.toml | 2 +- 16 files changed, 63 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1534622d6a..b345591d41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1273,16 +1273,14 @@ dependencies = [ [[package]] name = "git2" -version = "0.20.4" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b" +checksum = "ddddbf932745a6be37109b6112d3ee09696106f848449069d3a57bba937ab82e" dependencies = [ "bitflags 2.10.0", "libc", "libgit2-sys", "log", - "openssl-probe", - "openssl-sys", "url", ] @@ -2606,15 +2604,13 @@ checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "libgit2-sys" -version = "0.18.3+1.9.2" +version = "0.18.5+1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9b3acc4b91781bb0b3386669d325163746af5f6e4f73e6d2d630e09a35f3487" +checksum = "005d6ae6eac1912906073e069f7db60b1fa98e052a68227824afe3e3a1c59ca2" dependencies = [ "cc", "libc", - "libssh2-sys", "libz-sys", - "openssl-sys", "pkg-config", ] @@ -2635,20 +2631,6 @@ dependencies = [ "redox_syscall", ] -[[package]] -name = "libssh2-sys" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9" -dependencies = [ - "cc", - "libc", - "libz-sys", - "openssl-sys", - "pkg-config", - "vcpkg", -] - [[package]] name = "libz-sys" version = "1.1.21" @@ -2986,12 +2968,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - [[package]] name = "openssl-src" version = "300.4.1+3.4.0" diff --git a/asyncgit/Cargo.toml b/asyncgit/Cargo.toml index 5e77498ae3..79dd4a0c67 100644 --- a/asyncgit/Cargo.toml +++ b/asyncgit/Cargo.toml @@ -17,7 +17,7 @@ crossbeam-channel = "0.5" dirs = "6.0" easy-cast = "0.5" fuzzy-matcher = "0.3" -git2 = "0.20" +git2 = { version = "0.21", features = ["cred"] } git2-hooks = { path = "../git2-hooks", version = "0.7" } gix = { version = "0.78.0", default-features = false, features = [ "mailmap", diff --git a/asyncgit/src/sync/branch/mod.rs b/asyncgit/src/sync/branch/mod.rs index 6490142bf0..0af7b4b10d 100644 --- a/asyncgit/src/sync/branch/mod.rs +++ b/asyncgit/src/sync/branch/mod.rs @@ -160,7 +160,9 @@ pub fn get_branches_info( .branch_upstream_remote(&reference) .ok() .as_ref() - .and_then(git2::Buf::as_str) + .and_then(|upstream_remote| { + git2::Buf::as_str(upstream_remote).ok() + }) .map(String::from); let name_bytes = branch.name_bytes()?; @@ -332,7 +334,7 @@ pub fn checkout_branch( Some(&mut git2::build::CheckoutBuilder::new()), )?; - let branch_ref = branch_ref.name().ok_or_else(|| { + let branch_ref = branch_ref.name().map_err(|_| { Error::Generic(String::from("branch ref not found")) }); diff --git a/asyncgit/src/sync/commit.rs b/asyncgit/src/sync/commit.rs index b88f055c10..1a9ffd11aa 100644 --- a/asyncgit/src/sync/commit.rs +++ b/asyncgit/src/sync/commit.rs @@ -70,7 +70,7 @@ pub(crate) fn signature_allow_undefined_name( config.get_entry("user.name"), config.get_entry("user.email"), ) { - if let Some(email) = email_entry.value() { + if let Ok(email) = email_entry.value() { return Signature::now("unknown", email); } }; diff --git a/asyncgit/src/sync/commit_filter.rs b/asyncgit/src/sync/commit_filter.rs index 229e41d01d..0f0006e062 100644 --- a/asyncgit/src/sync/commit_filter.rs +++ b/asyncgit/src/sync/commit_filter.rs @@ -170,7 +170,11 @@ pub fn filter_commit_by_search( .fields .contains(SearchFields::MESSAGE_SUMMARY) .then(|| { - commit.summary().map(|msg| filter.match_text(msg)) + commit + .summary() + .ok() + .flatten() + .map(|msg| filter.match_text(msg)) }) .flatten() .unwrap_or_default(); @@ -180,7 +184,11 @@ pub fn filter_commit_by_search( .fields .contains(SearchFields::MESSAGE_BODY) .then(|| { - commit.body().map(|msg| filter.match_text(msg)) + commit + .body() + .ok() + .flatten() + .map(|msg| filter.match_text(msg)) }) .flatten() .unwrap_or_default(); @@ -206,9 +214,9 @@ pub fn filter_commit_by_search( let author = get_author_of_commit(&commit, &mailmap); [author.email(), author.name()].iter().any( |opt_haystack| { - opt_haystack.is_some_and(|haystack| { - filter.match_text(haystack) - }) + opt_haystack.as_ref().ok().is_some_and( + |haystack| filter.match_text(haystack), + ) }, ) } else { diff --git a/asyncgit/src/sync/commits_info.rs b/asyncgit/src/sync/commits_info.rs index 89d847c8c2..772b73a040 100644 --- a/asyncgit/src/sync/commits_info.rs +++ b/asyncgit/src/sync/commits_info.rs @@ -20,7 +20,7 @@ pub struct CommitId(Oid); impl Default for CommitId { fn default() -> Self { - Self(Oid::zero()) + Self(Oid::ZERO_SHA1) } } @@ -146,6 +146,7 @@ pub fn get_commits_info( let message = get_message(&c, Some(message_length_limit)); let author = get_author_of_commit(&c, &mailmap) .name() + .ok() .map_or_else( || String::from(""), String::from, diff --git a/asyncgit/src/sync/config.rs b/asyncgit/src/sync/config.rs index cc3761c934..8623b1aa16 100644 --- a/asyncgit/src/sync/config.rs +++ b/asyncgit/src/sync/config.rs @@ -136,7 +136,7 @@ pub fn get_config_string_repo( }; if entry.has_value() { - Ok(entry.value().map(std::string::ToString::to_string)) + Ok(entry.value().ok().map(std::string::ToString::to_string)) } else { Ok(None) } diff --git a/asyncgit/src/sync/cred.rs b/asyncgit/src/sync/cred.rs index 29f6f0ffc9..26fefdae19 100644 --- a/asyncgit/src/sync/cred.rs +++ b/asyncgit/src/sync/cred.rs @@ -42,7 +42,9 @@ pub fn need_username_password(repo_path: &RepoPath) -> Result { repo.find_remote(&get_default_remote_in_repo(&repo)?)?; let url = remote .pushurl() - .or_else(|| remote.url()) + .ok() + .flatten() + .or_else(|| remote.url().ok()) .ok_or(Error::UnknownRemote)? .to_owned(); let is_http = url.starts_with("http"); @@ -58,11 +60,8 @@ pub fn need_username_password_for_fetch( let repo = repo(repo_path)?; let remote = repo .find_remote(&get_default_remote_for_fetch_in_repo(&repo)?)?; - let url = remote - .url() - .or_else(|| remote.url()) - .ok_or(Error::UnknownRemote)? - .to_owned(); + let url = + remote.url().map_err(|_| Error::UnknownRemote)?.to_owned(); let is_http = url.starts_with("http"); Ok(is_http) } @@ -78,7 +77,9 @@ pub fn need_username_password_for_push( .find_remote(&get_default_remote_for_push_in_repo(&repo)?)?; let url = remote .pushurl() - .or_else(|| remote.url()) + .ok() + .flatten() + .or_else(|| remote.url().ok()) .ok_or(Error::UnknownRemote)? .to_owned(); let is_http = url.starts_with("http"); @@ -93,6 +94,7 @@ pub fn extract_username_password( let url = repo .find_remote(&get_default_remote_in_repo(&repo)?)? .url() + .ok() .ok_or(Error::UnknownRemote)? .to_owned(); let mut helper = CredentialHelper::new(&url); @@ -122,6 +124,7 @@ pub fn extract_username_password_for_fetch( let url = repo .find_remote(&get_default_remote_for_fetch_in_repo(&repo)?)? .url() + .ok() .ok_or(Error::UnknownRemote)? .to_owned(); let mut helper = CredentialHelper::new(&url); @@ -151,6 +154,7 @@ pub fn extract_username_password_for_push( let url = repo .find_remote(&get_default_remote_for_push_in_repo(&repo)?)? .url() + .ok() .ok_or(Error::UnknownRemote)? .to_owned(); let mut helper = CredentialHelper::new(&url); diff --git a/asyncgit/src/sync/hooks.rs b/asyncgit/src/sync/hooks.rs index fe3438f6ff..f24d5dd367 100644 --- a/asyncgit/src/sync/hooks.rs +++ b/asyncgit/src/sync/hooks.rs @@ -179,7 +179,9 @@ pub fn hooks_pre_push( let git_remote = repo.find_remote(remote)?; let url = git_remote .pushurl() - .or_else(|| git_remote.url()) + .ok() + .flatten() + .or_else(|| git_remote.url().ok()) .ok_or_else(|| { crate::error::Error::Generic(format!( "remote '{remote}' has no URL configured" diff --git a/asyncgit/src/sync/remotes/mod.rs b/asyncgit/src/sync/remotes/mod.rs index b32810dd9e..be96ebe58d 100644 --- a/asyncgit/src/sync/remotes/mod.rs +++ b/asyncgit/src/sync/remotes/mod.rs @@ -88,8 +88,12 @@ pub fn get_remotes(repo_path: &RepoPath) -> Result> { let repo = repo(repo_path)?; let remotes = repo.remotes()?; - let remotes: Vec = - remotes.iter().flatten().map(String::from).collect(); + let remotes: Vec = remotes + .iter() + .flatten() + .flatten() + .map(String::from) + .collect(); Ok(remotes) } @@ -102,7 +106,7 @@ pub fn get_remote_url( let repo = repo(repo_path)?; let remote = repo.find_remote(remote_name)?.clone(); let url = remote.url(); - if let Some(u) = url { + if let Ok(u) = url { return Ok(Some(u.to_string())); } Ok(None) @@ -241,9 +245,9 @@ pub(crate) fn get_default_remote_in_repo( let remotes = repo.remotes()?; // if `origin` exists return that - let found_origin = remotes - .iter() - .any(|r| r.is_some_and(|r| r == DEFAULT_REMOTE_NAME)); + let found_origin = remotes.iter().any(|r| { + r.ok().flatten().is_some_and(|r| r == DEFAULT_REMOTE_NAME) + }); if found_origin { return Ok(DEFAULT_REMOTE_NAME.into()); } @@ -252,8 +256,9 @@ pub(crate) fn get_default_remote_in_repo( if remotes.len() == 1 { let first_remote = remotes .iter() - .next() .flatten() + .flatten() + .next() .map(String::from) .ok_or_else(|| { Error::Generic("no remote found".into()) @@ -307,6 +312,7 @@ pub fn fetch_all( .remotes()? .iter() .flatten() + .flatten() .map(String::from) .collect::>(); let remotes_count = remotes.len(); diff --git a/asyncgit/src/sync/remotes/tags.rs b/asyncgit/src/sync/remotes/tags.rs index 138977b811..59384d0a3f 100644 --- a/asyncgit/src/sync/remotes/tags.rs +++ b/asyncgit/src/sync/remotes/tags.rs @@ -89,7 +89,9 @@ pub fn tags_missing_remote( let mut local_tags = tags .iter() - .filter_map(|tag| tag.map(|tag| format!("refs/tags/{tag}"))) + .filter_map(|tag| { + tag.ok().flatten().map(|tag| format!("refs/tags/{tag}")) + }) .collect::>(); let remote_tags = remote_tag_refs(repo_path, remote, basic_credential)?; diff --git a/asyncgit/src/sync/submodules.rs b/asyncgit/src/sync/submodules.rs index f3fcfeb0e3..7cd1f69ca6 100644 --- a/asyncgit/src/sync/submodules.rs +++ b/asyncgit/src/sync/submodules.rs @@ -65,7 +65,7 @@ fn submodule_to_info(s: &Submodule, r: &Repository) -> SubmoduleInfo { path: s.path().to_path_buf(), id: s.workdir_id().map(CommitId::from), head_id: s.head_id().map(CommitId::from), - url: s.url().map(String::from), + url: s.url().ok().flatten().map(String::from), status, } } diff --git a/asyncgit/src/sync/tree.rs b/asyncgit/src/sync/tree.rs index a6fdfbe585..4afb3b5bd6 100644 --- a/asyncgit/src/sync/tree.rs +++ b/asyncgit/src/sync/tree.rs @@ -161,7 +161,7 @@ mod tests { .map(|f| TreeFile { path: PathBuf::from(f), filemode: 0, - id: Oid::zero(), + id: Oid::ZERO_SHA1, }) .collect::>(); @@ -186,7 +186,7 @@ mod tests { .map(|f| TreeFile { path: PathBuf::from(f), filemode: 0, - id: Oid::zero(), + id: Oid::ZERO_SHA1, }) .collect::>(); @@ -210,7 +210,7 @@ mod tests { .map(|f| TreeFile { path: PathBuf::from(f), filemode: 0, - id: Oid::zero(), + id: Oid::ZERO_SHA1, }) .collect::>(); diff --git a/git2-hooks/Cargo.toml b/git2-hooks/Cargo.toml index a6aae61155..f421810523 100644 --- a/git2-hooks/Cargo.toml +++ b/git2-hooks/Cargo.toml @@ -13,7 +13,7 @@ categories = ["development-tools"] keywords = ["git"] [dependencies] -git2 = ">=0.17" +git2 = "0.21" gix-path = "0.11" log = "0.4" shellexpand = "3.1" diff --git a/git2-hooks/src/lib.rs b/git2-hooks/src/lib.rs index de0771227a..72716cef7c 100644 --- a/git2-hooks/src/lib.rs +++ b/git2-hooks/src/lib.rs @@ -837,7 +837,7 @@ exit 2 let res = hooks_prepare_commit_msg( &repo, None, - PrepareCommitMsgSource::Commit(git2::Oid::zero()), + PrepareCommitMsgSource::Commit(git2::Oid::ZERO_SHA1), &mut msg, ) .unwrap(); diff --git a/git2-testing/Cargo.toml b/git2-testing/Cargo.toml index dd83204f46..73323492fe 100644 --- a/git2-testing/Cargo.toml +++ b/git2-testing/Cargo.toml @@ -13,6 +13,6 @@ keywords = ["git"] [dependencies] env_logger = "0.11" -git2 = ">=0.17" +git2 = "0.21" log = "0.4" tempfile = "3"