@@ -12,12 +12,6 @@ use crate::{
12
12
pub trait Sealed { }
13
13
impl Sealed for crate :: Reference { }
14
14
15
- pub type FindObjectFn < ' a > = dyn FnMut (
16
- gix_hash:: ObjectId ,
17
- & mut Vec < u8 > ,
18
- ) -> Result < Option < ( gix_object:: Kind , & [ u8 ] ) > , Box < dyn std:: error:: Error + Send + Sync > >
19
- + ' a ;
20
-
21
15
/// A trait to extend [Reference][crate::Reference] with functionality requiring a [file::Store].
22
16
pub trait ReferenceExt : Sealed {
23
17
/// A step towards obtaining forward or reverse iterators on reference logs.
@@ -26,18 +20,22 @@ pub trait ReferenceExt: Sealed {
26
20
/// For details, see [`Reference::log_exists()`].
27
21
fn log_exists ( & self , store : & file:: Store ) -> bool ;
28
22
29
- /// For details, see [`Reference::peel_to_id_in_place()`].
23
+ /// Follow all symbolic targets this reference might point to and peel the underlying object
24
+ /// to the end of the chain, and return it, using `objects` to access them.
25
+ ///
26
+ /// This is useful to learn where this reference is ultimately pointing to.
30
27
fn peel_to_id_in_place (
31
28
& mut self ,
32
29
store : & file:: Store ,
33
- find : & mut FindObjectFn < ' _ > ,
30
+ objects : & dyn gix_object :: Find ,
34
31
) -> Result < ObjectId , peel:: to_id:: Error > ;
35
32
36
- /// For details, see [`Reference::peel_to_id_in_place()`], with support for a known stable packed buffer.
33
+ /// Like [`ReferenceExt::peel_to_id_in_place()`], but with support for a known stable packed buffer
34
+ /// to use for resolving symbolic links.
37
35
fn peel_to_id_in_place_packed (
38
36
& mut self ,
39
37
store : & file:: Store ,
40
- find : & mut FindObjectFn < ' _ > ,
38
+ objects : & dyn gix_object :: Find ,
41
39
packed : Option < & packed:: Buffer > ,
42
40
) -> Result < ObjectId , peel:: to_id:: Error > ;
43
41
@@ -75,18 +73,18 @@ impl ReferenceExt for Reference {
75
73
fn peel_to_id_in_place (
76
74
& mut self ,
77
75
store : & file:: Store ,
78
- find : & mut FindObjectFn < ' _ > ,
76
+ objects : & dyn gix_object :: Find ,
79
77
) -> Result < ObjectId , peel:: to_id:: Error > {
80
78
let packed = store. assure_packed_refs_uptodate ( ) . map_err ( |err| {
81
79
peel:: to_id:: Error :: Follow ( file:: find:: existing:: Error :: Find ( file:: find:: Error :: PackedOpen ( err) ) )
82
80
} ) ?;
83
- self . peel_to_id_in_place_packed ( store, find , packed. as_ref ( ) . map ( |b| & * * * b) )
81
+ self . peel_to_id_in_place_packed ( store, objects , packed. as_ref ( ) . map ( |b| & * * * b) )
84
82
}
85
83
86
84
fn peel_to_id_in_place_packed (
87
85
& mut self ,
88
86
store : & file:: Store ,
89
- find : & mut FindObjectFn < ' _ > ,
87
+ objects : & dyn gix_object :: Find ,
90
88
packed : Option < & packed:: Buffer > ,
91
89
) -> Result < ObjectId , peel:: to_id:: Error > {
92
90
match self . peeled {
@@ -118,10 +116,13 @@ impl ReferenceExt for Reference {
118
116
let mut buf = Vec :: new ( ) ;
119
117
let mut oid = self . target . try_id ( ) . expect ( "peeled ref" ) . to_owned ( ) ;
120
118
let peeled_id = loop {
121
- let ( kind, data) = find ( oid, & mut buf) ?. ok_or_else ( || peel:: to_id:: Error :: NotFound {
122
- oid,
123
- name : self . name . 0 . clone ( ) ,
124
- } ) ?;
119
+ let gix_object:: Data { kind, data } =
120
+ objects
121
+ . try_find ( & oid, & mut buf) ?
122
+ . ok_or_else ( || peel:: to_id:: Error :: NotFound {
123
+ oid,
124
+ name : self . name . 0 . clone ( ) ,
125
+ } ) ?;
125
126
match kind {
126
127
gix_object:: Kind :: Tag => {
127
128
oid = gix_object:: TagRefIter :: from_bytes ( data) . target_id ( ) . map_err ( |_err| {
0 commit comments