From 6a024b9c5449c9b7e7a22a360a8cdde8f6c9b5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Sat, 17 May 2025 17:59:54 +0200 Subject: [PATCH] Use gitoxide in get_commits_info --- asyncgit/src/sync/commits_info.rs | 55 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/asyncgit/src/sync/commits_info.rs b/asyncgit/src/sync/commits_info.rs index 0c31b470..d1727cdf 100644 --- a/asyncgit/src/sync/commits_info.rs +++ b/asyncgit/src/sync/commits_info.rs @@ -3,12 +3,9 @@ use std::fmt::Display; use super::RepoPath; use crate::{ error::Result, - sync::{ - commit_details::get_author_of_commit, - repository::{gix_repo, repo}, - }, + sync::repository::{gix_repo, repo}, }; -use git2::{Commit, Error, Oid}; +use git2::Oid; use scopetime::scope_time; use unicode_truncate::UnicodeTruncateStr; @@ -132,34 +129,34 @@ pub fn get_commits_info( ) -> Result> { scope_time!("get_commits_info"); - let repo = repo(repo_path)?; - let mailmap = repo.mailmap()?; + let repo: gix::Repository = gix_repo(repo_path)?; + let mailmap = repo.open_mailmap(); - let commits = ids - .iter() - .map(|id| repo.find_commit((*id).into())) - .collect::, Error>>()? - .into_iter(); + ids.iter() + .map(|id| -> Result<_> { + let commit = repo.find_commit(*id)?; + let commit_ref = commit.decode()?; - let res = commits - .map(|c: Commit| { - let message = get_message(&c, Some(message_length_limit)); - let author = get_author_of_commit(&c, &mailmap) - .name() - .map_or_else( - || String::from(""), - String::from, - ); - CommitInfo { + let message = gix_get_message( + &commit_ref, + Some(message_length_limit), + ); + + let author = commit_ref.author(); + + let author = mailmap.try_resolve(author).map_or_else( + || author.name.into(), + |signature| signature.name, + ); + + Ok(CommitInfo { message, - author, - time: c.time().seconds(), - id: CommitId(c.id()), - } + author: author.to_string(), + time: commit_ref.time().seconds, + id: *id, + }) }) - .collect::>(); - - Ok(res) + .collect() } ///