Skip to content

Commit 02a7b3f

Browse files
cruesslerphilocalyst
authored andcommitted
Impl From<gix::Id<'_>> for CommitId
1 parent 3936125 commit 02a7b3f

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

asyncgit/src/sync/commits_info.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ impl From<Oid> for CommitId {
8888
}
8989
}
9090

91+
impl From<gix::Id<'_>> for CommitId {
92+
fn from(object_id: gix::Id<'_>) -> Self {
93+
#[allow(clippy::expect_used)]
94+
let oid = Oid::from_bytes(object_id.as_bytes()).expect("`Oid::from_bytes(object_id.as_bytes())` is expected to never fail");
95+
96+
Self::new(oid)
97+
}
98+
}
99+
91100
impl From<gix::ObjectId> for CommitId {
92101
fn from(object_id: gix::ObjectId) -> Self {
93102
#[allow(clippy::expect_used)]
@@ -162,7 +171,7 @@ pub fn get_commits_info(
162171
parents: c
163172
.parents()
164173
.take(2)
165-
.map(|p| CommitId::new(p.id()))
174+
.map(|p| CommitId(p.id()))
166175
.collect(),
167176
}
168177
})
@@ -198,13 +207,11 @@ pub fn get_commit_info(
198207
author: author.to_string(),
199208
time: commit_ref.time()?.seconds,
200209
id: commit.id().detach().into(),
201-
parents: commit_ref
202-
.parents
203-
.iter()
210+
parents: commit
211+
.parent_ids()
204212
.take(2)
205-
.map(|p| CommitId::from_str_unchecked(&p.to_string()))
206-
.collect::<std::result::Result<Vec<_>, _>>()?
207-
.into(),
213+
.map(Into::into)
214+
.collect(),
208215
})
209216
}
210217

0 commit comments

Comments
 (0)