From f83228548b0d08cf825d6fe909919e26418eade2 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Wed, 22 Jul 2020 01:54:22 +0200 Subject: [PATCH] use new tag_foreach api --- Cargo.lock | 8 ++++---- asyncgit/Cargo.toml | 2 +- asyncgit/src/sync/tags.rs | 34 +++++++++++++++------------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa5bb2f3..ddcaf03b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -389,9 +389,9 @@ checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" [[package]] name = "git2" -version = "0.13.6" +version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11e4b2082980e751c4bf4273e9cbb4a02c655729c8ee8a79f66cad03c8f4d31e" +checksum = "e6ac22e49b7d886b6802c66662b12609452248b1bc9e87d6d83ecea3db96f557" dependencies = [ "bitflags", "libc", @@ -527,9 +527,9 @@ checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" [[package]] name = "libgit2-sys" -version = "0.12.7+1.0.0" +version = "0.12.9+1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcd07968649bcb7b9351ecfde53ca4d27673cccfdf57c84255ec18710f3153e0" +checksum = "9b33bf3d9d4c45b48ae1ea7c334be69994624dc0a69f833d5d9f7605f24b552b" dependencies = [ "cc", "libc", diff --git a/asyncgit/Cargo.toml b/asyncgit/Cargo.toml index ed3bd764..3bfcaee7 100644 --- a/asyncgit/Cargo.toml +++ b/asyncgit/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["git"] [dependencies] scopetime = { path = "../scopetime", version = "0.1" } -git2 = { version = "0.13.6", default-features = false } +git2 = { version = "0.13.8", default-features = false } rayon-core = "1.7" crossbeam-channel = "0.4" log = "0.4" diff --git a/asyncgit/src/sync/tags.rs b/asyncgit/src/sync/tags.rs index 4a9591da..4c98dc02 100644 --- a/asyncgit/src/sync/tags.rs +++ b/asyncgit/src/sync/tags.rs @@ -23,27 +23,23 @@ pub fn get_tags(repo_path: &str) -> Result { let repo = repo(repo_path)?; - //TODO: use tag_foreach once its released - // see https://github.com/rust-lang/git2-rs/pull/595 - for name in repo.tag_names(None)?.iter() { - if let Some(name) = name { - let reference = repo.find_reference( - format!("refs/tags/{}", name).as_str(), - )?; - let reference = reference.resolve()?; - - let commit_id = if let Ok(tag) = reference.peel_to_tag() { - Some(tag.target_id()) - } else { - reference.target() - }; - - if let Some(commit_id) = commit_id { - let tag_name = String::from(name); - adder(CommitId::new(commit_id), tag_name); + repo.tag_foreach(|id, name| { + if let Ok(name) = + String::from_utf8(name[10..name.len()].into()) + { + //NOTE: find_tag (git_tag_lookup) only works on annotated tags + // lightweight tags `id` already points to the target commit + // see https://github.com/libgit2/libgit2/issues/5586 + if let Ok(tag) = repo.find_tag(id) { + adder(CommitId::new(tag.target_id()), name); + } else if repo.find_commit(id).is_ok() { + adder(CommitId::new(id), name); } + + return true; } - } + false + })?; Ok(res) }