mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-08 21:55:47 +00:00
dag_walk: simply pass callback function by value
This commit is contained in:
parent
864c17b8c4
commit
522308bb9c
4 changed files with 17 additions and 17 deletions
|
@ -110,8 +110,8 @@ where
|
||||||
|
|
||||||
pub fn leaves<T, ID, II, NI>(
|
pub fn leaves<T, ID, II, NI>(
|
||||||
start: II,
|
start: II,
|
||||||
neighbors_fn: &mut impl FnMut(&T) -> NI,
|
mut neighbors_fn: impl FnMut(&T) -> NI,
|
||||||
id_fn: &impl Fn(&T) -> ID,
|
id_fn: impl Fn(&T) -> ID,
|
||||||
) -> HashSet<T>
|
) -> HashSet<T>
|
||||||
where
|
where
|
||||||
T: Hash + Eq + Clone,
|
T: Hash + Eq + Clone,
|
||||||
|
@ -147,8 +147,8 @@ where
|
||||||
/// start set.
|
/// start set.
|
||||||
pub fn heads<T, ID, II, NI>(
|
pub fn heads<T, ID, II, NI>(
|
||||||
start: II,
|
start: II,
|
||||||
neighbors_fn: &impl Fn(&T) -> NI,
|
neighbors_fn: impl Fn(&T) -> NI,
|
||||||
id_fn: &impl Fn(&T) -> ID,
|
id_fn: impl Fn(&T) -> ID,
|
||||||
) -> HashSet<T>
|
) -> HashSet<T>
|
||||||
where
|
where
|
||||||
T: Hash + Eq + Clone,
|
T: Hash + Eq + Clone,
|
||||||
|
@ -175,8 +175,8 @@ where
|
||||||
pub fn closest_common_node<T, ID, II1, II2, NI>(
|
pub fn closest_common_node<T, ID, II1, II2, NI>(
|
||||||
set1: II1,
|
set1: II1,
|
||||||
set2: II2,
|
set2: II2,
|
||||||
neighbors_fn: &impl Fn(&T) -> NI,
|
neighbors_fn: impl Fn(&T) -> NI,
|
||||||
id_fn: &impl Fn(&T) -> ID,
|
id_fn: impl Fn(&T) -> ID,
|
||||||
) -> Option<T>
|
) -> Option<T>
|
||||||
where
|
where
|
||||||
T: Hash + Eq + Clone,
|
T: Hash + Eq + Clone,
|
||||||
|
@ -341,8 +341,8 @@ mod tests {
|
||||||
let common = closest_common_node(
|
let common = closest_common_node(
|
||||||
vec!['E'],
|
vec!['E'],
|
||||||
vec!['H'],
|
vec!['H'],
|
||||||
&|node| neighbors[node].clone(),
|
|node| neighbors[node].clone(),
|
||||||
&|node| *node,
|
|node| *node,
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: fix the implementation to return B
|
// TODO: fix the implementation to return B
|
||||||
|
@ -372,16 +372,16 @@ mod tests {
|
||||||
|
|
||||||
let actual = heads(
|
let actual = heads(
|
||||||
vec!['A', 'C', 'D', 'F'],
|
vec!['A', 'C', 'D', 'F'],
|
||||||
&|node| neighbors[node].clone(),
|
|node| neighbors[node].clone(),
|
||||||
&|node| *node,
|
|node| *node,
|
||||||
);
|
);
|
||||||
assert_eq!(actual, hashset!['D', 'F']);
|
assert_eq!(actual, hashset!['D', 'F']);
|
||||||
|
|
||||||
// Check with a different order in the start set
|
// Check with a different order in the start set
|
||||||
let actual = heads(
|
let actual = heads(
|
||||||
vec!['F', 'D', 'C', 'A'],
|
vec!['F', 'D', 'C', 'A'],
|
||||||
&|node| neighbors[node].clone(),
|
|node| neighbors[node].clone(),
|
||||||
&|node| *node,
|
|node| *node,
|
||||||
);
|
);
|
||||||
assert_eq!(actual, hashset!['D', 'F']);
|
assert_eq!(actual, hashset!['D', 'F']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub trait OpHeadsStore: Send + Sync + Debug {
|
||||||
let neighbors_fn = |op: &Operation| op.parents();
|
let neighbors_fn = |op: &Operation| op.parents();
|
||||||
// Remove ancestors so we don't create merge operation with an operation and its
|
// Remove ancestors so we don't create merge operation with an operation and its
|
||||||
// ancestor
|
// ancestor
|
||||||
let op_heads = dag_walk::heads(op_heads, &neighbors_fn, &|op: &Operation| op.id().clone());
|
let op_heads = dag_walk::heads(op_heads, neighbors_fn, |op: &Operation| op.id().clone());
|
||||||
let op_head_ids_after: HashSet<_> = op_heads.iter().map(|op| op.id().clone()).collect();
|
let op_head_ids_after: HashSet<_> = op_heads.iter().map(|op| op.id().clone()).collect();
|
||||||
for removed_op_head in op_head_ids_before.difference(&op_head_ids_after) {
|
for removed_op_head in op_head_ids_before.difference(&op_head_ids_after) {
|
||||||
self.remove_op_head(removed_op_head);
|
self.remove_op_head(removed_op_head);
|
||||||
|
|
|
@ -68,8 +68,8 @@ impl Transaction {
|
||||||
let ancestor_op = closest_common_node(
|
let ancestor_op = closest_common_node(
|
||||||
self.parent_ops.clone(),
|
self.parent_ops.clone(),
|
||||||
vec![other_op.clone()],
|
vec![other_op.clone()],
|
||||||
&|op: &Operation| op.parents(),
|
|op: &Operation| op.parents(),
|
||||||
&|op: &Operation| op.id().clone(),
|
|op: &Operation| op.id().clone(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let repo_loader = self.base_repo().loader();
|
let repo_loader = self.base_repo().loader();
|
||||||
|
|
|
@ -1457,8 +1457,8 @@ pub fn check_stale_working_copy(
|
||||||
let maybe_ancestor_op = dag_walk::closest_common_node(
|
let maybe_ancestor_op = dag_walk::closest_common_node(
|
||||||
[wc_operation.clone()],
|
[wc_operation.clone()],
|
||||||
[repo_operation.clone()],
|
[repo_operation.clone()],
|
||||||
&|op: &Operation| op.parents(),
|
|op: &Operation| op.parents(),
|
||||||
&|op: &Operation| op.id().clone(),
|
|op: &Operation| op.id().clone(),
|
||||||
);
|
);
|
||||||
if let Some(ancestor_op) = maybe_ancestor_op {
|
if let Some(ancestor_op) = maybe_ancestor_op {
|
||||||
if ancestor_op.id() == repo_operation.id() {
|
if ancestor_op.id() == repo_operation.id() {
|
||||||
|
|
Loading…
Reference in a new issue