@@ -53,13 +53,13 @@ use gix_date::SecondsSinceUnixEpoch;
53
53
/// This number is only available natively if there is a commit-graph.
54
54
pub type Generation = u32 ;
55
55
56
- impl < ' find , T : std:: fmt:: Debug > std:: fmt:: Debug for Graph < ' find , T > {
56
+ impl < ' find , ' cache , T : std:: fmt:: Debug > std:: fmt:: Debug for Graph < ' find , ' cache , T > {
57
57
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
58
58
std:: fmt:: Debug :: fmt ( & self . map , f)
59
59
}
60
60
}
61
61
62
- impl < ' find , T : Default > Graph < ' find , T > {
62
+ impl < ' find , ' cache , T : Default > Graph < ' find , ' cache , T > {
63
63
/// Lookup `id` without failing if the commit doesn't exist, and assure that `id` is inserted into our set.
64
64
/// If it wasn't, associate it with the default value. Assure `update_data(data)` gets run.
65
65
/// Return the commit when done.
@@ -68,13 +68,13 @@ impl<'find, T: Default> Graph<'find, T> {
68
68
& mut self ,
69
69
id : gix_hash:: ObjectId ,
70
70
update_data : impl FnOnce ( & mut T ) ,
71
- ) -> Result < Option < LazyCommit < ' _ > > , try_lookup_or_insert_default:: Error > {
71
+ ) -> Result < Option < LazyCommit < ' _ , ' cache > > , try_lookup_or_insert_default:: Error > {
72
72
self . try_lookup_or_insert_default ( id, T :: default, update_data)
73
73
}
74
74
}
75
75
76
76
/// Access and mutation
77
- impl < ' find , T > Graph < ' find , T > {
77
+ impl < ' find , ' cache , T > Graph < ' find , ' cache , T > {
78
78
/// Returns true if `id` has data associated with it, meaning that we processed it already.
79
79
pub fn contains ( & self , id : & gix_hash:: oid ) -> bool {
80
80
self . map . contains_key ( id. as_ref ( ) )
@@ -101,7 +101,7 @@ impl<'find, T> Graph<'find, T> {
101
101
pub fn insert_data < E > (
102
102
& mut self ,
103
103
id : gix_hash:: ObjectId ,
104
- mut make_data : impl FnMut ( LazyCommit < ' _ > ) -> Result < T , E > ,
104
+ mut make_data : impl FnMut ( LazyCommit < ' _ , ' cache > ) -> Result < T , E > ,
105
105
) -> Result < Option < T > , E >
106
106
where
107
107
E : From < gix_object:: find:: existing_iter:: Error > ,
@@ -132,7 +132,7 @@ impl<'find, T> Graph<'find, T> {
132
132
let parent_id = parent_id?;
133
133
match self . map . entry ( parent_id) {
134
134
gix_hashtable:: hash_map:: Entry :: Vacant ( entry) => {
135
- let parent = match try_lookup ( & parent_id, & * self . find , self . cache . as_ref ( ) , & mut self . parent_buf ) ? {
135
+ let parent = match try_lookup ( & parent_id, & * self . find , self . cache , & mut self . parent_buf ) ? {
136
136
Some ( p) => p,
137
137
None => continue , // skip missing objects, this is due to shallow clones for instance.
138
138
} ;
@@ -160,7 +160,7 @@ impl<'find, T> Graph<'find, T> {
160
160
pub fn insert_parents_with_lookup < E > (
161
161
& mut self ,
162
162
id : & gix_hash:: oid ,
163
- parent_data : & mut dyn FnMut ( gix_hash:: ObjectId , LazyCommit < ' _ > , Option < & mut T > ) -> Result < T , E > ,
163
+ parent_data : & mut dyn FnMut ( gix_hash:: ObjectId , LazyCommit < ' _ , ' cache > , Option < & mut T > ) -> Result < T , E > ,
164
164
) -> Result < ( ) , E >
165
165
where
166
166
E : From < gix_object:: find:: existing_iter:: Error >
@@ -171,9 +171,7 @@ impl<'find, T> Graph<'find, T> {
171
171
let parents: SmallVec < [ _ ; 2 ] > = commit. iter_parents ( ) . collect ( ) ;
172
172
for parent_id in parents {
173
173
let parent_id = parent_id. map_err ( E :: from) ?;
174
- let parent = match try_lookup ( & parent_id, & * self . find , self . cache . as_ref ( ) , & mut self . parent_buf )
175
- . map_err ( E :: from) ?
176
- {
174
+ let parent = match try_lookup ( & parent_id, & * self . find , self . cache , & mut self . parent_buf ) . map_err ( E :: from) ? {
177
175
Some ( p) => p,
178
176
None => continue , // skip missing objects, this is due to shallow clones for instance.
179
177
} ;
@@ -197,7 +195,7 @@ impl<'find, T> Graph<'find, T> {
197
195
}
198
196
199
197
/// Initialization
200
- impl < ' find , T > Graph < ' find , T > {
198
+ impl < ' find , ' cache , T > Graph < ' find , ' cache , T > {
201
199
/// Create a new instance with `objects` to retrieve commits and optionally `cache` to accelerate commit access.
202
200
///
203
201
/// ### Performance
@@ -206,7 +204,7 @@ impl<'find, T> Graph<'find, T> {
206
204
/// most recently used commits.
207
205
/// Furthermore, **none-existing commits should not trigger the pack-db to be refreshed.** Otherwise, performance may be sub-optimal
208
206
/// in shallow repositories as running into non-existing commits will trigger a refresh of the `packs` directory.
209
- pub fn new ( objects : impl gix_object:: Find + ' find , cache : impl Into < Option < gix_commitgraph:: Graph > > ) -> Self {
207
+ pub fn new ( objects : impl gix_object:: Find + ' find , cache : Option < & ' cache gix_commitgraph:: Graph > ) -> Self {
210
208
Graph {
211
209
find : Box :: new ( objects) ,
212
210
cache : cache. into ( ) ,
@@ -218,7 +216,7 @@ impl<'find, T> Graph<'find, T> {
218
216
}
219
217
220
218
/// commit access
221
- impl < ' find , T > Graph < ' find , Commit < T > > {
219
+ impl < ' find , ' cache , T > Graph < ' find , ' cache , Commit < T > > {
222
220
/// Lookup `id` without failing if the commit doesn't exist, and assure that `id` is inserted into our set
223
221
/// with a commit with `new_data()` assigned.
224
222
/// `update_data(data)` gets run either on existing or on new data.
@@ -232,7 +230,7 @@ impl<'find, T> Graph<'find, Commit<T>> {
232
230
) -> Result < Option < & mut Commit < T > > , try_lookup_or_insert_default:: Error > {
233
231
match self . map . entry ( id) {
234
232
gix_hashtable:: hash_map:: Entry :: Vacant ( entry) => {
235
- let res = try_lookup ( & id, & * self . find , self . cache . as_ref ( ) , & mut self . buf ) ?;
233
+ let res = try_lookup ( & id, & * self . find , self . cache , & mut self . buf ) ?;
236
234
let commit = match res {
237
235
None => return Ok ( None ) ,
238
236
Some ( commit) => commit,
@@ -250,7 +248,7 @@ impl<'find, T> Graph<'find, Commit<T>> {
250
248
}
251
249
252
250
/// commit access
253
- impl < ' find , T : Default > Graph < ' find , Commit < T > > {
251
+ impl < ' find , ' cache , T : Default > Graph < ' find , ' cache , Commit < T > > {
254
252
/// Lookup `id` without failing if the commit doesn't exist or `id` isn't a commit,
255
253
/// and assure that `id` is inserted into our set with a commit and default data assigned.
256
254
/// `update_data(data)` gets run either on existing or on new data.
@@ -269,7 +267,7 @@ impl<'find, T: Default> Graph<'find, Commit<T>> {
269
267
}
270
268
271
269
/// Lazy commit access
272
- impl < ' find , T > Graph < ' find , T > {
270
+ impl < ' find , ' cache , T > Graph < ' find , ' cache , T > {
273
271
/// Lookup `id` without failing if the commit doesn't exist or `id` isn't a commit,
274
272
/// and assure that `id` is inserted into our set
275
273
/// with a `default` value assigned to it.
@@ -285,8 +283,8 @@ impl<'find, T> Graph<'find, T> {
285
283
id : gix_hash:: ObjectId ,
286
284
default : impl FnOnce ( ) -> T ,
287
285
update_data : impl FnOnce ( & mut T ) ,
288
- ) -> Result < Option < LazyCommit < ' _ > > , try_lookup_or_insert_default:: Error > {
289
- let res = try_lookup ( & id, & * self . find , self . cache . as_ref ( ) , & mut self . buf ) ?;
286
+ ) -> Result < Option < LazyCommit < ' _ , ' cache > > , try_lookup_or_insert_default:: Error > {
287
+ let res = try_lookup ( & id, & * self . find , self . cache , & mut self . buf ) ?;
290
288
Ok ( res. map ( |commit| {
291
289
match self . map . entry ( id) {
292
290
gix_hashtable:: hash_map:: Entry :: Vacant ( entry) => {
@@ -309,23 +307,26 @@ impl<'find, T> Graph<'find, T> {
309
307
pub fn try_lookup (
310
308
& mut self ,
311
309
id : & gix_hash:: oid ,
312
- ) -> Result < Option < LazyCommit < ' _ > > , gix_object:: find:: existing_iter:: Error > {
313
- try_lookup ( id, & * self . find , self . cache . as_ref ( ) , & mut self . buf )
310
+ ) -> Result < Option < LazyCommit < ' _ , ' cache > > , gix_object:: find:: existing_iter:: Error > {
311
+ try_lookup ( id, & * self . find , self . cache , & mut self . buf )
314
312
}
315
313
316
314
/// Lookup `id` and return a handle to it, or fail if it doesn't exist or is no commit.
317
- pub fn lookup ( & mut self , id : & gix_hash:: oid ) -> Result < LazyCommit < ' _ > , gix_object:: find:: existing_iter:: Error > {
315
+ pub fn lookup (
316
+ & mut self ,
317
+ id : & gix_hash:: oid ,
318
+ ) -> Result < LazyCommit < ' _ , ' cache > , gix_object:: find:: existing_iter:: Error > {
318
319
self . try_lookup ( id) ?
319
320
. ok_or ( gix_object:: find:: existing_iter:: Error :: NotFound { oid : id. to_owned ( ) } )
320
321
}
321
322
}
322
323
323
- fn try_lookup < ' graph > (
324
+ fn try_lookup < ' graph , ' cache > (
324
325
id : & gix_hash:: oid ,
325
326
objects : & dyn gix_object:: Find ,
326
- cache : Option < & ' graph gix_commitgraph:: Graph > ,
327
+ cache : Option < & ' cache gix_commitgraph:: Graph > ,
327
328
buf : & ' graph mut Vec < u8 > ,
328
- ) -> Result < Option < LazyCommit < ' graph > > , gix_object:: find:: existing_iter:: Error > {
329
+ ) -> Result < Option < LazyCommit < ' graph , ' cache > > , gix_object:: find:: existing_iter:: Error > {
329
330
if let Some ( cache) = cache {
330
331
if let Some ( pos) = cache. lookup ( id) {
331
332
return Ok ( Some ( LazyCommit {
@@ -347,7 +348,7 @@ fn try_lookup<'graph>(
347
348
)
348
349
}
349
350
350
- impl < ' a , ' find , T > Index < & ' a gix_hash:: oid > for Graph < ' find , T > {
351
+ impl < ' a , ' find , ' cache , T > Index < & ' a gix_hash:: oid > for Graph < ' find , ' cache , T > {
351
352
type Output = T ;
352
353
353
354
fn index ( & self , index : & ' a oid ) -> & Self :: Output {
@@ -398,8 +399,8 @@ where
398
399
/// A commit that provides access to graph-related information, on demand.
399
400
///
400
401
/// The owned version of this type is called [`Commit`] and can be obtained by calling [`LazyCommit::to_owned()`].
401
- pub struct LazyCommit < ' graph > {
402
- backing : Either < & ' graph [ u8 ] , ( & ' graph gix_commitgraph:: Graph , gix_commitgraph:: Position ) > ,
402
+ pub struct LazyCommit < ' graph , ' cache > {
403
+ backing : Either < & ' graph [ u8 ] , ( & ' cache gix_commitgraph:: Graph , gix_commitgraph:: Position ) > ,
403
404
}
404
405
405
406
enum Either < T , U > {
0 commit comments