Skip to content

Commit 1c44e41

Browse files
committed
feat: add Graph::clear_commit_data() for when commits are stored and data is attached.
These graphs have the advantage of being able to be re-usable, as generally all information about commits is kept.
1 parent 2972ea8 commit 1c44e41

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

gix-revwalk/src/graph/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ impl<'find, 'cache, T> Graph<'find, 'cache, T> {
225225
}
226226
}
227227

228-
/// commit access
229-
impl<'find, 'cache, T> Graph<'find, 'cache, Commit<T>> {
228+
/// Commit based methods
229+
impl<'find, 'cache, T> Graph<'find, 'cache, crate::graph::Commit<T>> {
230230
/// Lookup `id` without failing if the commit doesn't exist, and assure that `id` is inserted into our set
231231
/// with a commit with `new_data()` assigned.
232232
/// `update_data(data)` gets run either on existing or on new data.
@@ -255,9 +255,14 @@ impl<'find, 'cache, T> Graph<'find, 'cache, Commit<T>> {
255255
};
256256
Ok(self.map.get_mut(&id))
257257
}
258+
259+
/// For each stored commit, call `clear` on its data.
260+
pub fn clear_commit_data(&mut self, mut clear: impl FnMut(&mut T)) {
261+
self.map.values_mut().for_each(|c| clear(&mut c.data));
262+
}
258263
}
259264

260-
/// commit access
265+
/// Commit based methods
261266
impl<'find, 'cache, T: Default> Graph<'find, 'cache, Commit<T>> {
262267
/// Lookup `id` without failing if the commit doesn't exist or `id` isn't a commit,
263268
/// and assure that `id` is inserted into our set with a commit and default data assigned.

0 commit comments

Comments
 (0)