Skip to content

Commit

Permalink
Upgrade to git2 0.15
Browse files Browse the repository at this point in the history
Since 0.13, a few changes have been made to git2, including
rust-lang/git2-rs#791 which should address the
extensions.worktreeConfig issue in #195.

The upgrade required fixing uses of [ConfigEntries][1] because it's no
longer an iterator.

[1]: https://docs.rs/git2/0.15.0/git2/struct.ConfigEntries.html

However, it provides an API that lends itself well to `while let`
to provide a for loop like experience, so this was an easy fix.
  • Loading branch information
abhinav authored and jpgrayson committed Sep 10, 2022
1 parent 6d09a00 commit 915f629
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bstr = { version = "0.2", default-features = false, features = ["std"] }
chrono = { version = "0.4", default-features = false, features = ["clock"] }
clap = { version = "3.2", default-features = false, features = ["color", "std", "suggestions", "wrap_help"] }
encoding_rs = "0.8"
git2 = { version = "0.13", default-features = false }
git2 = { version = "0.15", default-features = false }
indexmap = "1.8"
lazy_static = "~1.4"
serde = { version = "1.0", features = ["derive"] }
Expand Down
5 changes: 3 additions & 2 deletions src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ where
F: Fn(&str) -> bool,
{
let mut aliases = get_default_aliases();

for entry in config.entries(None)?.flatten() {
let mut iter = config.entries(None)?;
while let Some(entry) = iter.next() {
let entry = entry?;
if let Some(name) = entry.name_bytes().strip_prefix(b"stgit.alias.") {
let name = name.to_str().map_err(|_| {
anyhow!(
Expand Down
14 changes: 8 additions & 6 deletions src/stack/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,17 @@ impl<'repo> Stack<'repo> {
}
state_ref.delete()?;
let mut config_to_delete: Vec<_> = Vec::new();
for entry in config
.entries(Some(&format!("branch.{branch_name}.stgit")))?
.into_iter()

{
let entry = entry?;
if let Some(name) = entry.name() {
config_to_delete.push(name.to_string());
let mut entries = config.entries(Some(&format!("branch.{branch_name}.stgit")))?;
while let Some(entry) = entries.next() {
let entry = entry?;
if let Some(name) = entry.name() {
config_to_delete.push(name.to_string());
}
}
}

for name_to_delete in config_to_delete {
config.remove(&name_to_delete)?;
}
Expand Down

0 comments on commit 915f629

Please sign in to comment.