@@ -42,21 +42,32 @@ pub mod into_id {
42
42
pub mod to_commit {
43
43
use crate :: object;
44
44
45
- /// The error returned by [`Head::peel_to_commit_in_place()`][super::Head::peel_to_commit_in_place()].
45
+ /// The error returned by [`Head::peel_to_commit_in_place()`](super::Head::peel_to_commit_in_place()).
46
+ #[ derive( Debug , thiserror:: Error ) ]
47
+ #[ allow( missing_docs) ]
48
+ pub enum Error {
49
+ #[ error( transparent) ]
50
+ PeelToObject ( #[ from] super :: to_object:: Error ) ,
51
+ #[ error( transparent) ]
52
+ ObjectKind ( #[ from] object:: try_into:: Error ) ,
53
+ }
54
+ }
55
+
56
+ ///
57
+ pub mod to_object {
58
+ /// The error returned by [`Head::peel_to_object_in_place()`](super::Head::peel_to_object_in_place()).
46
59
#[ derive( Debug , thiserror:: Error ) ]
47
60
#[ allow( missing_docs) ]
48
61
pub enum Error {
49
62
#[ error( transparent) ]
50
63
Peel ( #[ from] super :: Error ) ,
51
64
#[ error( "Branch '{name}' does not have any commits" ) ]
52
65
Unborn { name : gix_ref:: FullName } ,
53
- #[ error( transparent) ]
54
- ObjectKind ( #[ from] object:: try_into:: Error ) ,
55
66
}
56
67
}
57
68
58
69
impl < ' repo > Head < ' repo > {
59
- /// Peel this instance and consume to make obtaining its final target id possible, while returning an error on unborn heads.
70
+ /// Peel this instance and consume it to make obtaining its final target id possible, while returning an error on unborn heads.
60
71
///
61
72
/// The final target is obtained by following symbolic references and peeling tags to their final destination, which
62
73
/// typically is a commit, but can be any object.
@@ -68,6 +79,14 @@ impl<'repo> Head<'repo> {
68
79
} )
69
80
}
70
81
82
+ /// Peel this instance and consume it to make obtaining its final target object possible, while returning an error on unborn heads.
83
+ ///
84
+ /// The final target is obtained by following symbolic references and peeling tags to their final destination, which
85
+ /// typically is a commit, but can be any object as well.
86
+ pub fn into_peeled_object ( mut self ) -> Result < crate :: Object < ' repo > , to_object:: Error > {
87
+ self . peel_to_object_in_place ( )
88
+ }
89
+
71
90
/// Consume this instance and transform it into the final object that it points to, or `Ok(None)` if the `HEAD`
72
91
/// reference is yet to be born.
73
92
///
@@ -120,15 +139,21 @@ impl<'repo> Head<'repo> {
120
139
/// more object to follow, transform the id into a commit if possible and return that.
121
140
///
122
141
/// Returns an error if the head is unborn or if it doesn't point to a commit.
123
- pub fn peel_to_commit_in_place ( & mut self ) -> Result < crate :: Commit < ' repo > , to_commit :: Error > {
142
+ pub fn peel_to_object_in_place ( & mut self ) -> Result < crate :: Object < ' repo > , to_object :: Error > {
124
143
let id = self
125
144
. try_peel_to_id_in_place ( ) ?
126
- . ok_or_else ( || to_commit :: Error :: Unborn {
145
+ . ok_or_else ( || to_object :: Error :: Unborn {
127
146
name : self . referent_name ( ) . expect ( "unborn" ) . to_owned ( ) ,
128
147
} ) ?;
129
- Ok ( id
130
- . object ( )
131
- . map_err ( |err| to_commit:: Error :: Peel ( Error :: FindExistingObject ( err) ) ) ?
132
- . try_into_commit ( ) ?)
148
+ id. object ( )
149
+ . map_err ( |err| to_object:: Error :: Peel ( Error :: FindExistingObject ( err) ) )
150
+ }
151
+
152
+ /// Follow the symbolic reference of this head until its target object and peel it by following tag objects until there is no
153
+ /// more object to follow, transform the id into a commit if possible and return that.
154
+ ///
155
+ /// Returns an error if the head is unborn or if it doesn't point to a commit.
156
+ pub fn peel_to_commit_in_place ( & mut self ) -> Result < crate :: Commit < ' repo > , to_commit:: Error > {
157
+ Ok ( self . peel_to_object_in_place ( ) ?. try_into_commit ( ) ?)
133
158
}
134
159
}
0 commit comments