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

op_walk: allow walk_ancestors() from more than one head operations

This commit is contained in:
Yuya Nishihara 2023-12-31 11:06:07 +09:00
parent 51691ea22c
commit c53748d732
2 changed files with 7 additions and 4 deletions

View file

@ -125,7 +125,7 @@ fn cmd_op_log(
ui.request_pager(); ui.request_pager();
let mut formatter = ui.stdout_formatter(); let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut(); let formatter = formatter.as_mut();
let iter = op_walk::walk_ancestors(&head_op).take(args.limit.unwrap_or(usize::MAX)); let iter = op_walk::walk_ancestors(&[head_op]).take(args.limit.unwrap_or(usize::MAX));
if !args.no_graph { if !args.no_graph {
let mut graph = get_graphlog(command.settings(), formatter.raw()); let mut graph = get_graphlog(command.settings(), formatter.raw());
let default_node_symbol = graph.default_node_symbol().to_owned(); let default_node_symbol = graph.default_node_symbol().to_owned();

View file

@ -195,12 +195,15 @@ impl PartialOrd for OperationByEndTime {
} }
} }
/// Walks `head_op` and its ancestors in reverse topological order. /// Walks `head_ops` and their ancestors in reverse topological order.
pub fn walk_ancestors(head_op: &Operation) -> impl Iterator<Item = OpStoreResult<Operation>> { pub fn walk_ancestors(head_ops: &[Operation]) -> impl Iterator<Item = OpStoreResult<Operation>> {
// 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(
[Ok(OperationByEndTime(head_op.clone()))], head_ops
.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(),
) )