ok/jj
1
0
Fork 0
forked from mirrors/jj

op_walk: make walk_ancestors() sort head ops to stabilize output

I thought this would be done by dag_walk::topo_order_reverse_lazy_ok(), but
apparently I made it preserve the input order in a way topo_order_reverse()
would do.
This commit is contained in:
Yuya Nishihara 2024-01-12 20:53:44 +09:00
parent e8900123d2
commit 831a530283

View file

@ -207,13 +207,17 @@ impl PartialOrd for OperationByEndTime {
/// Walks `head_ops` and their ancestors in reverse topological order. /// Walks `head_ops` and their ancestors in reverse topological order.
pub fn walk_ancestors(head_ops: &[Operation]) -> impl Iterator<Item = OpStoreResult<Operation>> { pub fn walk_ancestors(head_ops: &[Operation]) -> impl Iterator<Item = OpStoreResult<Operation>> {
// Emit the latest head first to stabilize the order.
let mut head_ops = head_ops
.iter()
.cloned()
.map(OperationByEndTime)
.collect_vec();
head_ops.sort_unstable_by(|op1, op2| op1.cmp(op2).reverse());
// Lazily load operations based on timestamp-based heuristic. This works so long // Lazily load operations based on timestamp-based heuristic. This works so long
// as the operation history is mostly linear. // as the operation history is mostly linear.
dag_walk::topo_order_reverse_lazy_ok( dag_walk::topo_order_reverse_lazy_ok(
head_ops head_ops.into_iter().map(Ok),
.iter()
.map(|op| Ok(OperationByEndTime(op.clone())))
.collect_vec(),
|OperationByEndTime(op)| op.id().clone(), |OperationByEndTime(op)| op.id().clone(),
|OperationByEndTime(op)| op.parents().map_ok(OperationByEndTime).collect_vec(), |OperationByEndTime(op)| op.parents().map_ok(OperationByEndTime).collect_vec(),
) )