Skip to content

Commit b36cdf0

Browse files
committed
Use gitoxide in get_commits_info
1 parent 92394ae commit b36cdf0

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

asyncgit/src/sync/commits_info.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ use std::fmt::Display;
33
use super::RepoPath;
44
use crate::{
55
error::Result,
6-
sync::{
7-
commit_details::get_author_of_commit,
8-
repository::{gix_repo, repo},
9-
},
6+
sync::repository::{gix_repo, repo},
107
};
11-
use git2::{Commit, Error, Oid};
8+
use git2::Oid;
129
use scopetime::scope_time;
1310
use unicode_truncate::UnicodeTruncateStr;
1411

@@ -132,34 +129,34 @@ pub fn get_commits_info(
132129
) -> Result<Vec<CommitInfo>> {
133130
scope_time!("get_commits_info");
134131

135-
let repo = repo(repo_path)?;
136-
let mailmap = repo.mailmap()?;
137-
138-
let commits = ids
139-
.iter()
140-
.map(|id| repo.find_commit((*id).into()))
141-
.collect::<std::result::Result<Vec<Commit>, Error>>()?
142-
.into_iter();
143-
144-
let res = commits
145-
.map(|c: Commit| {
146-
let message = get_message(&c, Some(message_length_limit));
147-
let author = get_author_of_commit(&c, &mailmap)
148-
.name()
149-
.map_or_else(
150-
|| String::from("<unknown>"),
151-
String::from,
152-
);
153-
CommitInfo {
132+
let repo: gix::Repository = gix_repo(repo_path)?;
133+
let mailmap = repo.open_mailmap();
134+
135+
ids.iter()
136+
.map(|id| -> Result<_> {
137+
let commit = repo.find_commit(*id)?;
138+
let commit_ref = commit.decode()?;
139+
140+
let message = gix_get_message(
141+
&commit_ref,
142+
Some(message_length_limit),
143+
);
144+
145+
let author = commit_ref.author();
146+
147+
let author = mailmap.try_resolve(author).map_or_else(
148+
|| author.name.into(),
149+
|signature| signature.name,
150+
);
151+
152+
Ok(CommitInfo {
154153
message,
155-
author,
156-
time: c.time().seconds(),
157-
id: CommitId(c.id()),
158-
}
154+
author: author.to_string(),
155+
time: commit_ref.time().seconds,
156+
id: *id,
157+
})
159158
})
160-
.collect::<Vec<_>>();
161-
162-
Ok(res)
159+
.collect()
163160
}
164161

165162
///

0 commit comments

Comments
 (0)