Skip to content

Commit ebc6dc8

Browse files
committed
Update git2 to 0.21 across crates
1 parent 4f97fb5 commit ebc6dc8

16 files changed

Lines changed: 63 additions & 62 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

asyncgit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ crossbeam-channel = "0.5"
1717
dirs = "6.0"
1818
easy-cast = "0.5"
1919
fuzzy-matcher = "0.3"
20-
git2 = "0.20"
20+
git2 = { version = "0.21", features = ["cred"] }
2121
git2-hooks = { path = "../git2-hooks", version = "0.7" }
2222
gix = { version = "0.78.0", default-features = false, features = [
2323
"mailmap",

asyncgit/src/sync/branch/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ pub fn get_branches_info(
160160
.branch_upstream_remote(&reference)
161161
.ok()
162162
.as_ref()
163-
.and_then(git2::Buf::as_str)
163+
.and_then(|upstream_remote| {
164+
git2::Buf::as_str(upstream_remote).ok()
165+
})
164166
.map(String::from);
165167

166168
let name_bytes = branch.name_bytes()?;
@@ -332,7 +334,7 @@ pub fn checkout_branch(
332334
Some(&mut git2::build::CheckoutBuilder::new()),
333335
)?;
334336

335-
let branch_ref = branch_ref.name().ok_or_else(|| {
337+
let branch_ref = branch_ref.name().map_err(|_| {
336338
Error::Generic(String::from("branch ref not found"))
337339
});
338340

asyncgit/src/sync/commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn signature_allow_undefined_name(
7070
config.get_entry("user.name"),
7171
config.get_entry("user.email"),
7272
) {
73-
if let Some(email) = email_entry.value() {
73+
if let Ok(email) = email_entry.value() {
7474
return Signature::now("unknown", email);
7575
}
7676
};

asyncgit/src/sync/commit_filter.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ pub fn filter_commit_by_search(
170170
.fields
171171
.contains(SearchFields::MESSAGE_SUMMARY)
172172
.then(|| {
173-
commit.summary().map(|msg| filter.match_text(msg))
173+
commit
174+
.summary()
175+
.ok()
176+
.flatten()
177+
.map(|msg| filter.match_text(msg))
174178
})
175179
.flatten()
176180
.unwrap_or_default();
@@ -180,7 +184,11 @@ pub fn filter_commit_by_search(
180184
.fields
181185
.contains(SearchFields::MESSAGE_BODY)
182186
.then(|| {
183-
commit.body().map(|msg| filter.match_text(msg))
187+
commit
188+
.body()
189+
.ok()
190+
.flatten()
191+
.map(|msg| filter.match_text(msg))
184192
})
185193
.flatten()
186194
.unwrap_or_default();
@@ -206,9 +214,9 @@ pub fn filter_commit_by_search(
206214
let author = get_author_of_commit(&commit, &mailmap);
207215
[author.email(), author.name()].iter().any(
208216
|opt_haystack| {
209-
opt_haystack.is_some_and(|haystack| {
210-
filter.match_text(haystack)
211-
})
217+
opt_haystack.as_ref().ok().is_some_and(
218+
|haystack| filter.match_text(haystack),
219+
)
212220
},
213221
)
214222
} else {

asyncgit/src/sync/commits_info.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct CommitId(Oid);
2020

2121
impl Default for CommitId {
2222
fn default() -> Self {
23-
Self(Oid::zero())
23+
Self(Oid::ZERO_SHA1)
2424
}
2525
}
2626

@@ -146,6 +146,7 @@ pub fn get_commits_info(
146146
let message = get_message(&c, Some(message_length_limit));
147147
let author = get_author_of_commit(&c, &mailmap)
148148
.name()
149+
.ok()
149150
.map_or_else(
150151
|| String::from("<unknown>"),
151152
String::from,

asyncgit/src/sync/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn get_config_string_repo(
136136
};
137137

138138
if entry.has_value() {
139-
Ok(entry.value().map(std::string::ToString::to_string))
139+
Ok(entry.value().ok().map(std::string::ToString::to_string))
140140
} else {
141141
Ok(None)
142142
}

asyncgit/src/sync/cred.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ pub fn need_username_password(repo_path: &RepoPath) -> Result<bool> {
4242
repo.find_remote(&get_default_remote_in_repo(&repo)?)?;
4343
let url = remote
4444
.pushurl()
45-
.or_else(|| remote.url())
45+
.ok()
46+
.flatten()
47+
.or_else(|| remote.url().ok())
4648
.ok_or(Error::UnknownRemote)?
4749
.to_owned();
4850
let is_http = url.starts_with("http");
@@ -58,11 +60,8 @@ pub fn need_username_password_for_fetch(
5860
let repo = repo(repo_path)?;
5961
let remote = repo
6062
.find_remote(&get_default_remote_for_fetch_in_repo(&repo)?)?;
61-
let url = remote
62-
.url()
63-
.or_else(|| remote.url())
64-
.ok_or(Error::UnknownRemote)?
65-
.to_owned();
63+
let url =
64+
remote.url().map_err(|_| Error::UnknownRemote)?.to_owned();
6665
let is_http = url.starts_with("http");
6766
Ok(is_http)
6867
}
@@ -78,7 +77,9 @@ pub fn need_username_password_for_push(
7877
.find_remote(&get_default_remote_for_push_in_repo(&repo)?)?;
7978
let url = remote
8079
.pushurl()
81-
.or_else(|| remote.url())
80+
.ok()
81+
.flatten()
82+
.or_else(|| remote.url().ok())
8283
.ok_or(Error::UnknownRemote)?
8384
.to_owned();
8485
let is_http = url.starts_with("http");
@@ -93,6 +94,7 @@ pub fn extract_username_password(
9394
let url = repo
9495
.find_remote(&get_default_remote_in_repo(&repo)?)?
9596
.url()
97+
.ok()
9698
.ok_or(Error::UnknownRemote)?
9799
.to_owned();
98100
let mut helper = CredentialHelper::new(&url);
@@ -122,6 +124,7 @@ pub fn extract_username_password_for_fetch(
122124
let url = repo
123125
.find_remote(&get_default_remote_for_fetch_in_repo(&repo)?)?
124126
.url()
127+
.ok()
125128
.ok_or(Error::UnknownRemote)?
126129
.to_owned();
127130
let mut helper = CredentialHelper::new(&url);
@@ -151,6 +154,7 @@ pub fn extract_username_password_for_push(
151154
let url = repo
152155
.find_remote(&get_default_remote_for_push_in_repo(&repo)?)?
153156
.url()
157+
.ok()
154158
.ok_or(Error::UnknownRemote)?
155159
.to_owned();
156160
let mut helper = CredentialHelper::new(&url);

asyncgit/src/sync/hooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ pub fn hooks_pre_push(
179179
let git_remote = repo.find_remote(remote)?;
180180
let url = git_remote
181181
.pushurl()
182-
.or_else(|| git_remote.url())
182+
.ok()
183+
.flatten()
184+
.or_else(|| git_remote.url().ok())
183185
.ok_or_else(|| {
184186
crate::error::Error::Generic(format!(
185187
"remote '{remote}' has no URL configured"

asyncgit/src/sync/remotes/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ pub fn get_remotes(repo_path: &RepoPath) -> Result<Vec<String>> {
8888

8989
let repo = repo(repo_path)?;
9090
let remotes = repo.remotes()?;
91-
let remotes: Vec<String> =
92-
remotes.iter().flatten().map(String::from).collect();
91+
let remotes: Vec<String> = remotes
92+
.iter()
93+
.flatten()
94+
.flatten()
95+
.map(String::from)
96+
.collect();
9397

9498
Ok(remotes)
9599
}
@@ -102,7 +106,7 @@ pub fn get_remote_url(
102106
let repo = repo(repo_path)?;
103107
let remote = repo.find_remote(remote_name)?.clone();
104108
let url = remote.url();
105-
if let Some(u) = url {
109+
if let Ok(u) = url {
106110
return Ok(Some(u.to_string()));
107111
}
108112
Ok(None)
@@ -241,9 +245,9 @@ pub(crate) fn get_default_remote_in_repo(
241245
let remotes = repo.remotes()?;
242246

243247
// if `origin` exists return that
244-
let found_origin = remotes
245-
.iter()
246-
.any(|r| r.is_some_and(|r| r == DEFAULT_REMOTE_NAME));
248+
let found_origin = remotes.iter().any(|r| {
249+
r.ok().flatten().is_some_and(|r| r == DEFAULT_REMOTE_NAME)
250+
});
247251
if found_origin {
248252
return Ok(DEFAULT_REMOTE_NAME.into());
249253
}
@@ -252,8 +256,9 @@ pub(crate) fn get_default_remote_in_repo(
252256
if remotes.len() == 1 {
253257
let first_remote = remotes
254258
.iter()
255-
.next()
256259
.flatten()
260+
.flatten()
261+
.next()
257262
.map(String::from)
258263
.ok_or_else(|| {
259264
Error::Generic("no remote found".into())
@@ -307,6 +312,7 @@ pub fn fetch_all(
307312
.remotes()?
308313
.iter()
309314
.flatten()
315+
.flatten()
310316
.map(String::from)
311317
.collect::<Vec<_>>();
312318
let remotes_count = remotes.len();

0 commit comments

Comments
 (0)