From 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:41:41 +0200 Subject: Merging upstream version 1.70.0+dfsg2. Signed-off-by: Daniel Baumann --- vendor/gix/src/ext/mod.rs | 9 +++++++++ vendor/gix/src/ext/object_id.rs | 34 +++++++++++++++++++++++++++++++ vendor/gix/src/ext/reference.rs | 15 ++++++++++++++ vendor/gix/src/ext/rev_spec.rs | 20 +++++++++++++++++++ vendor/gix/src/ext/tree.rs | 44 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 vendor/gix/src/ext/mod.rs create mode 100644 vendor/gix/src/ext/object_id.rs create mode 100644 vendor/gix/src/ext/reference.rs create mode 100644 vendor/gix/src/ext/rev_spec.rs create mode 100644 vendor/gix/src/ext/tree.rs (limited to 'vendor/gix/src/ext') 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 = Ancestors 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(self, find: Find) -> AncestorsIter + where + Find: for<'a> FnMut(&gix_hash::oid, &'a mut Vec) -> Result, 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(self, find: Find) -> AncestorsIter + where + Find: for<'a> FnMut(&gix_hash::oid, &'a mut Vec) -> Result, 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( + &self, + state: StateMut, + find: Find, + delegate: &mut V, + ) -> Result<(), breadthfirst::Error> + where + Find: for<'a> FnMut(&oid, &'a mut Vec) -> Option>, + StateMut: BorrowMut, + V: gix_traverse::tree::Visit; +} + +impl<'d> Sealed for TreeRefIter<'d> {} + +impl<'d> TreeIterExt for TreeRefIter<'d> { + fn traverse( + &self, + state: StateMut, + find: Find, + delegate: &mut V, + ) -> Result<(), breadthfirst::Error> + where + Find: for<'a> FnMut(&oid, &'a mut Vec) -> Option>, + StateMut: BorrowMut, + V: gix_traverse::tree::Visit, + { + breadthfirst(self.clone(), state, find, delegate) + } +} -- cgit v1.2.3