mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
Use gitoxide for get_tags (#2664)
This commit is contained in:
parent
fdd5a19d20
commit
fd46b9a0c1
3 changed files with 51 additions and 51 deletions
|
|
@ -17,7 +17,7 @@ pub enum GixError {
|
|||
|
||||
///
|
||||
#[error("gix::object::find::existing::with_conversion::Error error: {0}")]
|
||||
ObjectFindExistingWithConversionError(
|
||||
ObjectFindExistingWithConversion(
|
||||
#[from] gix::object::find::existing::with_conversion::Error,
|
||||
),
|
||||
|
||||
|
|
@ -39,6 +39,14 @@ pub enum GixError {
|
|||
#[error("gix::reference::head_tree_id::Error error: {0}")]
|
||||
ReferenceHeadTreeId(#[from] gix::reference::head_tree_id::Error),
|
||||
|
||||
///
|
||||
#[error("gix::reference::iter::Error error: {0}")]
|
||||
ReferenceIter(#[from] gix::reference::iter::Error),
|
||||
|
||||
///
|
||||
#[error("gix::reference::iter::init::Error error: {0}")]
|
||||
ReferenceIterInit(#[from] gix::reference::iter::init::Error),
|
||||
|
||||
///
|
||||
#[error("gix::revision::walk error: {0}")]
|
||||
RevisionWalk(#[from] gix::revision::walk::Error),
|
||||
|
|
@ -251,6 +259,18 @@ impl From<gix::reference::head_tree_id::Error> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<gix::reference::iter::Error> for Error {
|
||||
fn from(error: gix::reference::iter::Error) -> Self {
|
||||
Self::Gix(GixError::from(error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gix::reference::iter::init::Error> for Error {
|
||||
fn from(error: gix::reference::iter::init::Error) -> Self {
|
||||
Self::Gix(GixError::from(error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gix::revision::walk::Error> for Error {
|
||||
fn from(error: gix::revision::walk::Error) -> Self {
|
||||
Self::Gix(GixError::from(error))
|
||||
|
|
|
|||
|
|
@ -96,6 +96,15 @@ impl From<gix::ObjectId> for CommitId {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<gix::Commit<'_>> for CommitId {
|
||||
fn from(commit: gix::Commit<'_>) -> Self {
|
||||
#[allow(clippy::expect_used)]
|
||||
let oid = Oid::from_bytes(commit.id().as_bytes()).expect("`Oid::from_bytes(commit.id().as_bytes())` is expected to never fail");
|
||||
|
||||
Self::new(oid)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CommitId> for gix::ObjectId {
|
||||
fn from(id: CommitId) -> Self {
|
||||
Self::from_bytes_or_panic(id.0.as_bytes())
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
use super::{get_commits_info, CommitId, RepoPath};
|
||||
use crate::{
|
||||
error::Result,
|
||||
sync::{repository::repo, utils::bytes2string},
|
||||
};
|
||||
use crate::{error::Result, sync::repository::repo};
|
||||
use scopetime::scope_time;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
ops::Not,
|
||||
};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
|
||||
///
|
||||
#[derive(Clone, Hash, PartialEq, Eq, Debug)]
|
||||
|
|
@ -64,52 +58,29 @@ pub fn get_tags(repo_path: &RepoPath) -> Result<Tags> {
|
|||
}
|
||||
};
|
||||
|
||||
let repo = repo(repo_path)?;
|
||||
let gix_repo: gix::Repository =
|
||||
gix::ThreadSafeRepository::discover_with_environment_overrides(repo_path.gitpath())
|
||||
.map(Into::into)?;
|
||||
let platform = gix_repo.references()?;
|
||||
for mut reference in (platform.tags()?).flatten() {
|
||||
let commit = reference.peel_to_commit();
|
||||
let tag = reference.peel_to_tag();
|
||||
|
||||
repo.tag_foreach(|id, name| {
|
||||
if let Ok(name) =
|
||||
// skip the `refs/tags/` part
|
||||
String::from_utf8(name[10..name.len()].into())
|
||||
{
|
||||
//NOTE: find_tag (using underlying 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
|
||||
let commit = repo
|
||||
.find_tag(id)
|
||||
.and_then(|tag| tag.target())
|
||||
.and_then(|target| target.peel_to_commit())
|
||||
.map_or_else(
|
||||
|_| {
|
||||
if repo.find_commit(id).is_ok() {
|
||||
Some(CommitId::new(id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
|commit| Some(CommitId::new(commit.id())),
|
||||
);
|
||||
if let Ok(commit) = commit {
|
||||
let tag_ref = tag.as_ref().map(gix::Tag::decode);
|
||||
|
||||
let annotation = repo
|
||||
.find_tag(id)
|
||||
.ok()
|
||||
.as_ref()
|
||||
.and_then(git2::Tag::message_bytes)
|
||||
.and_then(|msg| {
|
||||
msg.is_empty()
|
||||
.not()
|
||||
.then(|| bytes2string(msg).ok())
|
||||
.flatten()
|
||||
});
|
||||
let name = match tag_ref {
|
||||
Ok(Ok(tag)) => tag.name.to_string(),
|
||||
_ => reference.name().shorten().to_string(),
|
||||
};
|
||||
let annotation = match tag_ref {
|
||||
Ok(Ok(tag)) => Some(tag.message.to_string()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(commit) = commit {
|
||||
adder(commit, Tag { name, annotation });
|
||||
}
|
||||
|
||||
return true;
|
||||
adder(commit.into(), Tag { name, annotation });
|
||||
}
|
||||
false
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue