@@ -226,9 +226,9 @@ impl<'find, 'cache, T> Graph<'find, 'cache, T> {
226
226
}
227
227
228
228
/// Commit based methods
229
- impl < ' find , ' cache , T > Graph < ' find , ' cache , crate :: graph :: Commit < T > > {
230
- /// Lookup `id` without failing if the commit doesn't exist, and assure that `id` is inserted into our set
231
- /// with a commit with `new_data()` assigned .
229
+ impl < ' find , ' cache , T > Graph < ' find , ' cache , Commit < T > > {
230
+ /// Lookup `id` in the graph, but insert it if it's not yet present by looking it up without failing if the commit doesn't exist.
231
+ /// Call `new_data()` to obtain data for a newly inserted commit .
232
232
/// `update_data(data)` gets run either on existing or on new data.
233
233
///
234
234
/// Note that none of the data updates happen if `id` didn't exist.
@@ -264,8 +264,8 @@ impl<'find, 'cache, T> Graph<'find, 'cache, crate::graph::Commit<T>> {
264
264
265
265
/// Commit based methods
266
266
impl < ' find , ' cache , T : Default > Graph < ' find , ' cache , Commit < T > > {
267
- /// Lookup `id` without failing if the commit doesn't exist or `id` isn't a commit,
268
- /// and assure that `id` is inserted into our set with a commit and default data assigned .
267
+ /// Lookup `id` in the graph, but insert it if it's not yet present by looking it up without failing if the commit doesn't exist.
268
+ /// Newly inserted commits are populated with default data.
269
269
/// `update_data(data)` gets run either on existing or on new data.
270
270
///
271
271
/// Note that none of the data updates happen if `id` didn't exist.
@@ -279,6 +279,33 @@ impl<'find, 'cache, T: Default> Graph<'find, 'cache, Commit<T>> {
279
279
) -> Result < Option < & mut Commit < T > > , try_lookup_or_insert_default:: Error > {
280
280
self . try_lookup_or_insert_commit_default ( id, T :: default, update_data)
281
281
}
282
+
283
+ /// Lookup `id` in the graph, but insert it if it's not yet present by looking it up without failing if the commit doesn't exist.
284
+ /// `update_commit(commit)` gets run either on existing or on new data.
285
+ ///
286
+ /// Note that none of the data updates happen if `id` didn't exist in the graph.
287
+ pub fn get_or_insert_full_commit (
288
+ & mut self ,
289
+ id : gix_hash:: ObjectId ,
290
+ update_commit : impl FnOnce ( & mut Commit < T > ) ,
291
+ ) -> Result < Option < & mut Commit < T > > , try_lookup_or_insert_default:: Error > {
292
+ match self . map . entry ( id) {
293
+ gix_hashtable:: hash_map:: Entry :: Vacant ( entry) => {
294
+ let res = try_lookup ( & id, & * self . find , self . cache , & mut self . buf ) ?;
295
+ let commit = match res {
296
+ None => return Ok ( None ) ,
297
+ Some ( commit) => commit,
298
+ } ;
299
+ let mut commit = commit. to_owned ( T :: default) ?;
300
+ update_commit ( & mut commit) ;
301
+ entry. insert ( commit) ;
302
+ }
303
+ gix_hashtable:: hash_map:: Entry :: Occupied ( mut entry) => {
304
+ update_commit ( entry. get_mut ( ) ) ;
305
+ }
306
+ } ;
307
+ Ok ( self . map . get_mut ( & id) )
308
+ }
282
309
}
283
310
284
311
/// Lazy commit access
0 commit comments