diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
commit | 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch) | |
tree | bdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/gix/src/ext | |
parent | Releasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff) | |
download | rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.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')
-rw-r--r-- | vendor/gix/src/ext/mod.rs | 9 | ||||
-rw-r--r-- | vendor/gix/src/ext/object_id.rs | 34 | ||||
-rw-r--r-- | vendor/gix/src/ext/reference.rs | 15 | ||||
-rw-r--r-- | vendor/gix/src/ext/rev_spec.rs | 20 | ||||
-rw-r--r-- | vendor/gix/src/ext/tree.rs | 44 |
5 files changed, 122 insertions, 0 deletions
diff --git a/vendor/gix/src/ext/mod.rs b/vendor/gix/src/ext/mod.rs new file mode 100644 index 000000000..beb9007fa --- /dev/null +++ b/vendor/gix/src/ext/mod.rs @@ -0,0 +1,9 @@ +pub use object_id::ObjectIdExt; +pub use reference::ReferenceExt; +pub use rev_spec::RevSpecExt; +pub use tree::TreeIterExt; + +mod object_id; +mod reference; +mod rev_spec; +mod tree; 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) + } +} diff --git a/vendor/gix/src/ext/reference.rs b/vendor/gix/src/ext/reference.rs new file mode 100644 index 000000000..57e4e4fe7 --- /dev/null +++ b/vendor/gix/src/ext/reference.rs @@ -0,0 +1,15 @@ +pub trait Sealed {} + +impl Sealed for gix_ref::Reference {} + +/// Extensions for [references][gix_ref::Reference]. +pub trait ReferenceExt { + /// Attach [`Repository`][crate::Repository] to the given reference. It can be detached later with [`detach()]`. + fn attach(self, repo: &crate::Repository) -> crate::Reference<'_>; +} + +impl ReferenceExt for gix_ref::Reference { + fn attach(self, repo: &crate::Repository) -> crate::Reference<'_> { + crate::Reference::from_ref(self, repo) + } +} diff --git a/vendor/gix/src/ext/rev_spec.rs b/vendor/gix/src/ext/rev_spec.rs new file mode 100644 index 000000000..ed7dc0460 --- /dev/null +++ b/vendor/gix/src/ext/rev_spec.rs @@ -0,0 +1,20 @@ +pub trait Sealed {} + +impl Sealed for gix_ref::Reference {} + +/// Extensions for [revision specifications][gix_revision::Spec]. +pub trait RevSpecExt { + /// Attach [`Repository`][crate::Repository] to the given rev-spec. + fn attach(self, repo: &crate::Repository) -> crate::revision::Spec<'_>; +} + +impl RevSpecExt for gix_revision::Spec { + fn attach(self, repo: &crate::Repository) -> crate::revision::Spec<'_> { + crate::revision::Spec { + inner: self, + first_ref: None, + second_ref: None, + repo, + } + } +} diff --git a/vendor/gix/src/ext/tree.rs b/vendor/gix/src/ext/tree.rs new file mode 100644 index 000000000..09220fc40 --- /dev/null +++ b/vendor/gix/src/ext/tree.rs @@ -0,0 +1,44 @@ +use std::borrow::BorrowMut; + +use gix_hash::oid; +use gix_object::TreeRefIter; +use gix_traverse::tree::breadthfirst; + +pub trait Sealed {} + +/// An extension trait for tree iterators +pub trait TreeIterExt: Sealed { + /// Traverse this tree with `state` being provided to potentially reuse allocations, and `find` being a function to lookup trees + /// and turn them into iterators. + /// + /// The `delegate` implements a way to store details about the traversal to allow paying only for what's actually used. + /// Since it is expected to store the operation result, _unit_ is returned. + fn traverse<StateMut, Find, V>( + &self, + state: StateMut, + find: Find, + delegate: &mut V, + ) -> Result<(), breadthfirst::Error> + where + Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<TreeRefIter<'a>>, + StateMut: BorrowMut<breadthfirst::State>, + V: gix_traverse::tree::Visit; +} + +impl<'d> Sealed for TreeRefIter<'d> {} + +impl<'d> TreeIterExt for TreeRefIter<'d> { + fn traverse<StateMut, Find, V>( + &self, + state: StateMut, + find: Find, + delegate: &mut V, + ) -> Result<(), breadthfirst::Error> + where + Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<TreeRefIter<'a>>, + StateMut: BorrowMut<breadthfirst::State>, + V: gix_traverse::tree::Visit, + { + breadthfirst(self.clone(), state, find, delegate) + } +} |