From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix/src/object/mod.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'vendor/gix/src/object/mod.rs') 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, 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> { -- cgit v1.2.3