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/object/impls.rs | |
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/object/impls.rs')
-rw-r--r-- | vendor/gix/src/object/impls.rs | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/vendor/gix/src/object/impls.rs b/vendor/gix/src/object/impls.rs new file mode 100644 index 000000000..3453b1b3c --- /dev/null +++ b/vendor/gix/src/object/impls.rs @@ -0,0 +1,123 @@ +use std::convert::TryFrom; + +use crate::{object, Commit, Object, ObjectDetached, Tag, Tree}; + +impl<'repo> From<Object<'repo>> for ObjectDetached { + fn from(mut v: Object<'repo>) -> Self { + ObjectDetached { + id: v.id, + kind: v.kind, + data: std::mem::take(&mut v.data), + } + } +} + +impl<'repo> From<Commit<'repo>> for ObjectDetached { + fn from(mut v: Commit<'repo>) -> Self { + ObjectDetached { + id: v.id, + kind: gix_object::Kind::Commit, + data: std::mem::take(&mut v.data), + } + } +} + +impl<'repo> From<Tag<'repo>> for ObjectDetached { + fn from(mut v: Tag<'repo>) -> Self { + ObjectDetached { + id: v.id, + kind: gix_object::Kind::Tag, + data: std::mem::take(&mut v.data), + } + } +} + +impl<'repo> From<Commit<'repo>> for Object<'repo> { + fn from(mut v: Commit<'repo>) -> Self { + Object { + id: v.id, + kind: gix_object::Kind::Commit, + data: steal_from_freelist(&mut v.data), + repo: v.repo, + } + } +} + +impl<'repo> AsRef<[u8]> for Object<'repo> { + fn as_ref(&self) -> &[u8] { + &self.data + } +} + +impl AsRef<[u8]> for ObjectDetached { + fn as_ref(&self) -> &[u8] { + &self.data + } +} + +impl<'repo> TryFrom<Object<'repo>> for Commit<'repo> { + type Error = Object<'repo>; + + fn try_from(mut value: Object<'repo>) -> Result<Self, Self::Error> { + let handle = value.repo; + match value.kind { + object::Kind::Commit => Ok(Commit { + id: value.id, + repo: handle, + data: steal_from_freelist(&mut value.data), + }), + _ => Err(value), + } + } +} + +impl<'repo> TryFrom<Object<'repo>> for Tag<'repo> { + type Error = Object<'repo>; + + fn try_from(mut value: Object<'repo>) -> Result<Self, Self::Error> { + let handle = value.repo; + match value.kind { + object::Kind::Tag => Ok(Tag { + id: value.id, + repo: handle, + data: steal_from_freelist(&mut value.data), + }), + _ => Err(value), + } + } +} + +impl<'repo> TryFrom<Object<'repo>> for Tree<'repo> { + type Error = Object<'repo>; + + fn try_from(mut value: Object<'repo>) -> Result<Self, Self::Error> { + let handle = value.repo; + match value.kind { + object::Kind::Tree => Ok(Tree { + id: value.id, + repo: handle, + data: steal_from_freelist(&mut value.data), + }), + _ => Err(value), + } + } +} + +impl<'r> std::fmt::Debug for Object<'r> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use gix_object::Kind::*; + let type_name = match self.kind { + Blob => "Blob", + Commit => "Commit", + Tree => "Tree", + Tag => "Tag", + }; + write!(f, "{}({})", type_name, self.id) + } +} + +/// In conjunction with the handles free list, leaving an empty Vec in place of the original causes it to not be +/// returned to the free list. +fn steal_from_freelist(data: &mut Vec<u8>) -> Vec<u8> { + std::mem::take(data) +} |