@@ -11,7 +11,7 @@ pub mod iter;
1111pub mod remote;
1212
1313mod errors;
14- pub use errors:: { edit, find, head_commit, head_id, head_tree_id, peel} ;
14+ pub use errors:: { edit, find, follow , head_commit, head_id, head_tree_id, peel} ;
1515
1616use crate :: ext:: ObjectIdExt ;
1717
@@ -153,6 +153,33 @@ impl<'repo> Reference<'repo> {
153153 Ok ( target. object ( ) ?. peel_to_kind ( kind) ?)
154154 }
155155
156+ /// Follow all symbolic references we point to up to the first object, which is typically (but not always) a tag,
157+ /// returning its id.
158+ /// After this call, this ref will be pointing to an object directly, but may still not consider itself 'peeled' unless
159+ /// a symbolic target ref was looked up from packed-refs.
160+ #[ doc( alias = "resolve" , alias = "git2" ) ]
161+ pub fn follow_to_object ( & mut self ) -> Result < Id < ' repo > , follow:: to_object:: Error > {
162+ let packed = self . repo . refs . cached_packed_buffer ( ) . map_err ( |err| {
163+ follow:: to_object:: Error :: FollowToObject ( gix_ref:: peel:: to_object:: Error :: Follow (
164+ file:: find:: existing:: Error :: Find ( file:: find:: Error :: PackedOpen ( err) ) ,
165+ ) )
166+ } ) ?;
167+ self . follow_to_object_packed ( packed. as_ref ( ) . map ( |p| & * * * p) )
168+ }
169+
170+ /// Like [`follow_to_object`](Self::follow_to_object), but can be used for repeated calls as it won't
171+ /// look up `packed` each time, but can reuse it instead.
172+ #[ doc( alias = "resolve" , alias = "git2" ) ]
173+ pub fn follow_to_object_packed (
174+ & mut self ,
175+ packed : Option < & gix_ref:: packed:: Buffer > ,
176+ ) -> Result < Id < ' repo > , follow:: to_object:: Error > {
177+ Ok ( self
178+ . inner
179+ . follow_to_object_in_place_packed ( & self . repo . refs , packed) ?
180+ . attach ( self . repo ) )
181+ }
182+
156183 /// Follow this symbolic reference one level and return the ref it refers to.
157184 ///
158185 /// Returns `None` if this is not a symbolic reference, hence the leaf of the chain.
0 commit comments