@@ -10,7 +10,7 @@ use gix_ref::{
10
10
} ;
11
11
use smallvec:: SmallVec ;
12
12
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 } ;
14
14
15
15
/// Methods related to object creation.
16
16
impl crate :: Repository {
@@ -38,6 +38,35 @@ impl crate::Repository {
38
38
Ok ( Object :: from_data ( id, kind, buf, self ) )
39
39
}
40
40
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
+
41
70
/// Obtain information about an object without fully decoding it, or fail if the object doesn't exist.
42
71
///
43
72
/// Note that despite being cheaper than [`Self::find_object()`], there is still some effort traversing delta-chains.
0 commit comments