|
1 | 1 | use super::{get_commits_info, CommitId, RepoPath}; |
2 | | -use crate::{ |
3 | | - error::Result, |
4 | | - sync::{repository::repo, utils::bytes2string}, |
5 | | -}; |
| 2 | +use crate::{error::Result, sync::repository::repo}; |
6 | 3 | use scopetime::scope_time; |
7 | | -use std::{ |
8 | | - collections::{BTreeMap, HashMap, HashSet}, |
9 | | - ops::Not, |
10 | | -}; |
| 4 | +use std::collections::{BTreeMap, HashMap, HashSet}; |
11 | 5 |
|
12 | 6 | /// |
13 | 7 | #[derive(Clone, Hash, PartialEq, Eq, Debug)] |
@@ -64,52 +58,29 @@ pub fn get_tags(repo_path: &RepoPath) -> Result<Tags> { |
64 | 58 | } |
65 | 59 | }; |
66 | 60 |
|
67 | | - let repo = repo(repo_path)?; |
68 | | - |
69 | | - repo.tag_foreach(|id, name| { |
70 | | - if let Ok(name) = |
71 | | - // skip the `refs/tags/` part |
72 | | - String::from_utf8(name[10..name.len()].into()) |
73 | | - { |
74 | | - //NOTE: find_tag (using underlying git_tag_lookup) only |
75 | | - // works on annotated tags lightweight tags `id` already |
76 | | - // points to the target commit |
77 | | - // see https://github.com/libgit2/libgit2/issues/5586 |
78 | | - let commit = repo |
79 | | - .find_tag(id) |
80 | | - .and_then(|tag| tag.target()) |
81 | | - .and_then(|target| target.peel_to_commit()) |
82 | | - .map_or_else( |
83 | | - |_| { |
84 | | - if repo.find_commit(id).is_ok() { |
85 | | - Some(CommitId::new(id)) |
86 | | - } else { |
87 | | - None |
88 | | - } |
89 | | - }, |
90 | | - |commit| Some(CommitId::new(commit.id())), |
91 | | - ); |
92 | | - |
93 | | - let annotation = repo |
94 | | - .find_tag(id) |
95 | | - .ok() |
96 | | - .as_ref() |
97 | | - .and_then(git2::Tag::message_bytes) |
98 | | - .and_then(|msg| { |
99 | | - msg.is_empty() |
100 | | - .not() |
101 | | - .then(|| bytes2string(msg).ok()) |
102 | | - .flatten() |
103 | | - }); |
104 | | - |
105 | | - if let Some(commit) = commit { |
106 | | - adder(commit, Tag { name, annotation }); |
107 | | - } |
108 | | - |
109 | | - return true; |
| 61 | + let gix_repo: gix::Repository = |
| 62 | + gix::ThreadSafeRepository::discover_with_environment_overrides(repo_path.gitpath()) |
| 63 | + .map(Into::into)?; |
| 64 | + let platform = gix_repo.references()?; |
| 65 | + for mut reference in (platform.tags()?).flatten() { |
| 66 | + let commit = reference.peel_to_commit(); |
| 67 | + let tag = reference.peel_to_tag(); |
| 68 | + |
| 69 | + if let Ok(commit) = commit { |
| 70 | + let tag_ref = tag.as_ref().map(gix::Tag::decode); |
| 71 | + |
| 72 | + let name = match tag_ref { |
| 73 | + Ok(Ok(tag)) => tag.name.to_string(), |
| 74 | + _ => reference.name().shorten().to_string(), |
| 75 | + }; |
| 76 | + let annotation = match tag_ref { |
| 77 | + Ok(Ok(tag)) => Some(tag.message.to_string()), |
| 78 | + _ => None, |
| 79 | + }; |
| 80 | + |
| 81 | + adder(commit.into(), Tag { name, annotation }); |
110 | 82 | } |
111 | | - false |
112 | | - })?; |
| 83 | + } |
113 | 84 |
|
114 | 85 | Ok(res) |
115 | 86 | } |
|
0 commit comments