diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:35 +0000 |
commit | 7e5d7eea9c580ef4b41a765bde624af431942b96 (patch) | |
tree | 2c0d9ca12878fc4525650aa4e54d77a81a07cc09 /vendor/gix/src/ext/object_id.rs | |
parent | Adding debian version 1.70.0+dfsg1-9. (diff) | |
download | rustc-7e5d7eea9c580ef4b41a765bde624af431942b96.tar.xz rustc-7e5d7eea9c580ef4b41a765bde624af431942b96.zip |
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix/src/ext/object_id.rs')
-rw-r--r-- | vendor/gix/src/ext/object_id.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/gix/src/ext/object_id.rs b/vendor/gix/src/ext/object_id.rs new file mode 100644 index 000000000..a4515022b --- /dev/null +++ b/vendor/gix/src/ext/object_id.rs @@ -0,0 +1,34 @@ +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, E>(self, find: Find) -> AncestorsIter<Find> + where + Find: for<'a> FnMut(&gix_hash::oid, &'a mut Vec<u8>) -> Result<gix_object::CommitRefIter<'a>, E>, + E: std::error::Error + Send + Sync + 'static; + + /// 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, E>(self, find: Find) -> AncestorsIter<Find> + where + Find: for<'a> FnMut(&gix_hash::oid, &'a mut Vec<u8>) -> Result<gix_object::CommitRefIter<'a>, E>, + E: std::error::Error + Send + Sync + 'static, + { + Ancestors::new(Some(self), ancestors::State::default(), find) + } + + fn attach(self, repo: &crate::Repository) -> crate::Id<'_> { + crate::Id::from_id(self, repo) + } +} |