@@ -10,7 +10,7 @@ use gix_ref::{
1010} ;
1111use smallvec:: SmallVec ;
1212
13- use crate :: { commit, ext:: ObjectIdExt , object, tag, Blob , Id , Object , Reference , Tree } ;
13+ use crate :: { commit, ext:: ObjectIdExt , object, tag, Blob , Commit , Id , Object , Reference , Tag , Tree } ;
1414
1515/// Methods related to object creation.
1616impl crate :: Repository {
@@ -38,6 +38,35 @@ impl crate::Repository {
3838 Ok ( Object :: from_data ( id, kind, buf, self ) )
3939 }
4040
41+ /// Find a commit with `id` or fail if there was no object or the object wasn't a commit.
42+ pub fn find_commit (
43+ & self ,
44+ id : impl Into < ObjectId > ,
45+ ) -> Result < Commit < ' _ > , object:: find:: existing:: with_conversion:: Error > {
46+ Ok ( self . find_object ( id) ?. try_into_commit ( ) ?)
47+ }
48+
49+ /// Find a tree with `id` or fail if there was no object or the object wasn't a tree.
50+ pub fn find_tree (
51+ & self ,
52+ id : impl Into < ObjectId > ,
53+ ) -> Result < Tree < ' _ > , object:: find:: existing:: with_conversion:: Error > {
54+ Ok ( self . find_object ( id) ?. try_into_tree ( ) ?)
55+ }
56+
57+ /// Find an annotated tag with `id` or fail if there was no object or the object wasn't a tag.
58+ pub fn find_tag ( & self , id : impl Into < ObjectId > ) -> Result < Tag < ' _ > , object:: find:: existing:: with_conversion:: Error > {
59+ Ok ( self . find_object ( id) ?. try_into_tag ( ) ?)
60+ }
61+
62+ /// Find a blob with `id` or fail if there was no object or the object wasn't a blob.
63+ pub fn find_blob (
64+ & self ,
65+ id : impl Into < ObjectId > ,
66+ ) -> Result < Blob < ' _ > , object:: find:: existing:: with_conversion:: Error > {
67+ Ok ( self . find_object ( id) ?. try_into_blob ( ) ?)
68+ }
69+
4170 /// Obtain information about an object without fully decoding it, or fail if the object doesn't exist.
4271 ///
4372 /// Note that despite being cheaper than [`Self::find_object()`], there is still some effort traversing delta-chains.
0 commit comments