diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/gix/src/object | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix/src/object')
-rw-r--r-- | vendor/gix/src/object/blob.rs | 26 | ||||
-rw-r--r-- | vendor/gix/src/object/commit.rs | 8 | ||||
-rw-r--r-- | vendor/gix/src/object/impls.rs | 56 | ||||
-rw-r--r-- | vendor/gix/src/object/mod.rs | 19 | ||||
-rw-r--r-- | vendor/gix/src/object/tag.rs | 26 | ||||
-rw-r--r-- | vendor/gix/src/object/tree/mod.rs | 26 |
6 files changed, 148 insertions, 13 deletions
diff --git a/vendor/gix/src/object/blob.rs b/vendor/gix/src/object/blob.rs index 00b3519ed..ef19c302a 100644 --- a/vendor/gix/src/object/blob.rs +++ b/vendor/gix/src/object/blob.rs @@ -1,3 +1,5 @@ +use crate::{Blob, ObjectDetached}; + /// #[cfg(feature = "blob-diff")] pub mod diff { @@ -147,3 +149,27 @@ pub mod diff { } } } + +/// Remove Lifetime +impl Blob<'_> { + /// Create an owned instance of this object, copying our data in the process. + pub fn detached(&self) -> ObjectDetached { + ObjectDetached { + id: self.id, + kind: gix_object::Kind::Blob, + data: self.data.clone(), + } + } + + /// Sever the connection to the `Repository` and turn this instance into a standalone object. + pub fn detach(self) -> ObjectDetached { + self.into() + } + + /// Retrieve this instance's data, leaving its own data empty. + /// + /// This method works around the immovability of members of this type. + pub fn take_data(&mut self) -> Vec<u8> { + std::mem::take(&mut self.data) + } +} diff --git a/vendor/gix/src/object/commit.rs b/vendor/gix/src/object/commit.rs index 1fb9eff67..bb2e3a99e 100644 --- a/vendor/gix/src/object/commit.rs +++ b/vendor/gix/src/object/commit.rs @@ -20,6 +20,7 @@ mod error { pub use error::Error; +/// Remove Lifetime impl<'repo> Commit<'repo> { /// Create an owned instance of this object, copying our data in the process. pub fn detached(&self) -> ObjectDetached { @@ -34,6 +35,13 @@ impl<'repo> Commit<'repo> { pub fn detach(self) -> ObjectDetached { self.into() } + + /// Retrieve this instance's encoded data, leaving its own data empty. + /// + /// This method works around the immovability of members of this type. + pub fn take_data(&mut self) -> Vec<u8> { + std::mem::take(&mut self.data) + } } impl<'repo> Commit<'repo> { diff --git a/vendor/gix/src/object/impls.rs b/vendor/gix/src/object/impls.rs index 3453b1b3c..5d2ad8160 100644 --- a/vendor/gix/src/object/impls.rs +++ b/vendor/gix/src/object/impls.rs @@ -1,13 +1,13 @@ use std::convert::TryFrom; -use crate::{object, Commit, Object, ObjectDetached, Tag, Tree}; +use crate::{object, Blob, 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), + data: steal_from_freelist(&mut v.data), } } } @@ -17,7 +17,7 @@ impl<'repo> From<Commit<'repo>> for ObjectDetached { ObjectDetached { id: v.id, kind: gix_object::Kind::Commit, - data: std::mem::take(&mut v.data), + data: steal_from_freelist(&mut v.data), } } } @@ -27,7 +27,27 @@ impl<'repo> From<Tag<'repo>> for ObjectDetached { ObjectDetached { id: v.id, kind: gix_object::Kind::Tag, - data: std::mem::take(&mut v.data), + data: steal_from_freelist(&mut v.data), + } + } +} + +impl<'repo> From<Blob<'repo>> for ObjectDetached { + fn from(mut v: Blob<'repo>) -> Self { + ObjectDetached { + id: v.id, + kind: gix_object::Kind::Blob, + data: steal_from_freelist(&mut v.data), + } + } +} + +impl<'repo> From<Tree<'repo>> for ObjectDetached { + fn from(mut v: Tree<'repo>) -> Self { + ObjectDetached { + id: v.id, + kind: gix_object::Kind::Tree, + data: steal_from_freelist(&mut v.data), } } } @@ -59,11 +79,11 @@ 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; + let repo = value.repo; match value.kind { object::Kind::Commit => Ok(Commit { id: value.id, - repo: handle, + repo, data: steal_from_freelist(&mut value.data), }), _ => Err(value), @@ -75,11 +95,11 @@ 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; + let repo = value.repo; match value.kind { object::Kind::Tag => Ok(Tag { id: value.id, - repo: handle, + repo, data: steal_from_freelist(&mut value.data), }), _ => Err(value), @@ -91,11 +111,27 @@ 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; + let repo = value.repo; match value.kind { object::Kind::Tree => Ok(Tree { id: value.id, - repo: handle, + repo, + data: steal_from_freelist(&mut value.data), + }), + _ => Err(value), + } + } +} + +impl<'repo> TryFrom<Object<'repo>> for Blob<'repo> { + type Error = Object<'repo>; + + fn try_from(mut value: Object<'repo>) -> Result<Self, Self::Error> { + let repo = value.repo; + match value.kind { + object::Kind::Blob => Ok(Blob { + id: value.id, + repo, data: steal_from_freelist(&mut value.data), }), _ => Err(value), diff --git a/vendor/gix/src/object/mod.rs b/vendor/gix/src/object/mod.rs index d0a37db6c..ca2b07f8b 100644 --- a/vendor/gix/src/object/mod.rs +++ b/vendor/gix/src/object/mod.rs @@ -4,7 +4,7 @@ use std::convert::TryInto; use gix_hash::ObjectId; pub use gix_object::Kind; -use crate::{Commit, Id, Object, ObjectDetached, Tag, Tree}; +use crate::{Blob, Commit, Id, Object, ObjectDetached, Tag, Tree}; mod errors; pub(crate) mod cache { @@ -74,6 +74,14 @@ impl<'repo> Object<'repo> { } } + /// Transform this object into a blob, or panic if it is none. + pub fn into_blob(self) -> Blob<'repo> { + match self.try_into() { + Ok(tree) => tree, + Err(this) => panic!("Tried to use {} as tree, but was {}", this.id, this.kind), + } + } + /// Transform this object into a tree, or panic if it is none. pub fn into_tree(self) -> Tree<'repo> { match self.try_into() { @@ -124,6 +132,15 @@ impl<'repo> Object<'repo> { expected: gix_object::Kind::Tree, }) } + + /// Transform this object into a blob, or return it as part of the `Err` if it is no blob. + pub fn try_into_blob(self) -> Result<Blob<'repo>, try_into::Error> { + self.try_into().map_err(|this: Self| try_into::Error { + id: this.id, + actual: this.kind, + expected: gix_object::Kind::Blob, + }) + } } impl<'repo> Object<'repo> { diff --git a/vendor/gix/src/object/tag.rs b/vendor/gix/src/object/tag.rs index 77eaaa259..1a7a3de86 100644 --- a/vendor/gix/src/object/tag.rs +++ b/vendor/gix/src/object/tag.rs @@ -1,4 +1,4 @@ -use crate::{ext::ObjectIdExt, Tag}; +use crate::{ext::ObjectIdExt, ObjectDetached, Tag}; impl<'repo> Tag<'repo> { /// Decode the entire tag object and return it for accessing all tag information. @@ -24,3 +24,27 @@ impl<'repo> Tag<'repo> { gix_object::TagRefIter::from_bytes(&self.data).tagger() } } + +/// Remove Lifetime +impl Tag<'_> { + /// Create an owned instance of this object, copying our data in the process. + pub fn detached(&self) -> ObjectDetached { + ObjectDetached { + id: self.id, + kind: gix_object::Kind::Tag, + data: self.data.clone(), + } + } + + /// Sever the connection to the `Repository` and turn this instance into a standalone object. + pub fn detach(self) -> ObjectDetached { + self.into() + } + + /// Retrieve this instance's encoded data, leaving its own data empty. + /// + /// This method works around the immovability of members of this type. + pub fn take_data(&mut self) -> Vec<u8> { + std::mem::take(&mut self.data) + } +} diff --git a/vendor/gix/src/object/tree/mod.rs b/vendor/gix/src/object/tree/mod.rs index 5bf59a25c..e4dac24f8 100644 --- a/vendor/gix/src/object/tree/mod.rs +++ b/vendor/gix/src/object/tree/mod.rs @@ -4,7 +4,7 @@ pub use gix_object::tree::EntryMode; use gix_object::{bstr::BStr, TreeRefIter}; use gix_odb::FindExt; -use crate::{object::find, Id, Tree}; +use crate::{object::find, Id, ObjectDetached, Tree}; /// Initialization impl<'repo> Tree<'repo> { @@ -250,3 +250,27 @@ mod _impls { } } } + +/// Remove Lifetime +impl Tree<'_> { + /// Create an owned instance of this object, copying our data in the process. + pub fn detached(&self) -> ObjectDetached { + ObjectDetached { + id: self.id, + kind: gix_object::Kind::Tree, + data: self.data.clone(), + } + } + + /// Sever the connection to the `Repository` and turn this instance into a standalone object. + pub fn detach(self) -> ObjectDetached { + self.into() + } + + /// Retrieve this instance's encoded data, leaving its own data empty. + /// + /// This method works around the immovability of members of this type. + pub fn take_data(&mut self) -> Vec<u8> { + std::mem::take(&mut self.data) + } +} |