Skip to content

Commit f832285

Browse files
author
Stephan Dilly
committed
use new tag_foreach api
1 parent 0c53fed commit f832285

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

Cargo.lock

Lines changed: 4 additions & 4 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
@@ -13,7 +13,7 @@ keywords = ["git"]
1313

1414
[dependencies]
1515
scopetime = { path = "../scopetime", version = "0.1" }
16-
git2 = { version = "0.13.6", default-features = false }
16+
git2 = { version = "0.13.8", default-features = false }
1717
rayon-core = "1.7"
1818
crossbeam-channel = "0.4"
1919
log = "0.4"

asyncgit/src/sync/tags.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,23 @@ pub fn get_tags(repo_path: &str) -> Result<Tags> {
2323

2424
let repo = repo(repo_path)?;
2525

26-
//TODO: use tag_foreach once its released
27-
// see https://github.com/rust-lang/git2-rs/pull/595
28-
for name in repo.tag_names(None)?.iter() {
29-
if let Some(name) = name {
30-
let reference = repo.find_reference(
31-
format!("refs/tags/{}", name).as_str(),
32-
)?;
33-
let reference = reference.resolve()?;
34-
35-
let commit_id = if let Ok(tag) = reference.peel_to_tag() {
36-
Some(tag.target_id())
37-
} else {
38-
reference.target()
39-
};
40-
41-
if let Some(commit_id) = commit_id {
42-
let tag_name = String::from(name);
43-
adder(CommitId::new(commit_id), tag_name);
26+
repo.tag_foreach(|id, name| {
27+
if let Ok(name) =
28+
String::from_utf8(name[10..name.len()].into())
29+
{
30+
//NOTE: find_tag (git_tag_lookup) only works on annotated tags
31+
// lightweight tags `id` already points to the target commit
32+
// see https://github.com/libgit2/libgit2/issues/5586
33+
if let Ok(tag) = repo.find_tag(id) {
34+
adder(CommitId::new(tag.target_id()), name);
35+
} else if repo.find_commit(id).is_ok() {
36+
adder(CommitId::new(id), name);
4437
}
38+
39+
return true;
4540
}
46-
}
41+
false
42+
})?;
4743

4844
Ok(res)
4945
}

0 commit comments

Comments
 (0)