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/mod.rs | |
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/mod.rs')
-rw-r--r-- | vendor/gix/src/object/mod.rs | 19 |
1 files changed, 18 insertions, 1 deletions
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> { |