blob: d4d9467664b825baeeb93b4988f95736195087ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
use gix_hash::ObjectId;
use gix_traverse::commit::{ancestors, Ancestors};
pub trait Sealed {}
pub type AncestorsIter<Find> = Ancestors<Find, fn(&gix_hash::oid) -> bool, ancestors::State>;
/// An extension trait to add functionality to [`ObjectId`]s.
pub trait ObjectIdExt: Sealed {
/// Create an iterator over the ancestry of the commits reachable from this id, which must be a commit.
fn ancestors<Find>(self, find: Find) -> AncestorsIter<Find>
where
Find: gix_object::Find;
/// Infuse this object id `repo` access.
fn attach(self, repo: &crate::Repository) -> crate::Id<'_>;
}
impl Sealed for ObjectId {}
impl ObjectIdExt for ObjectId {
fn ancestors<Find>(self, find: Find) -> AncestorsIter<Find>
where
Find: gix_object::Find,
{
Ancestors::new(Some(self), ancestors::State::default(), find)
}
fn attach(self, repo: &crate::Repository) -> crate::Id<'_> {
crate::Id::from_id(self, repo)
}
}
|