Collect view-scoped TREE lifecycle events before applying hunk-level TREE mutations. Recording all adds, moves, and deletes, not just deferred Git imports, keeps replay baselines valid when a later foreground change moves the same inode on another view.
(
txn: &T,
change_hash: Hash,
change: &Change,
deleted_paths: &[String],
visible_on_target: Option<&HashSet<Hash>>,
)
| 554 | /// imports, keeps replay baselines valid when a later foreground change moves |
| 555 | /// the same inode on another view. |
| 556 | pub(super) fn collect_tree_ops<T: GraphTxnT + TreeTxnT>( |
| 557 | txn: &T, |
| 558 | change_hash: Hash, |
| 559 | change: &Change, |
| 560 | deleted_paths: &[String], |
| 561 | visible_on_target: Option<&HashSet<Hash>>, |
| 562 | ) -> Result<Vec<DeferredTreeOp>, RepositoryError> { |
| 563 | let mut ops = Vec::new(); |
| 564 | |
| 565 | for graph_op in change.hunks() { |
| 566 | match graph_op { |
| 567 | GraphOp::FileAdd { |
| 568 | add_inode, path, .. |
| 569 | } |
| 570 | | GraphOp::DirAdd { |
| 571 | add_inode, path, .. |
| 572 | } => { |
| 573 | let added_position = Position::new(change_hash, add_inode.start); |
| 574 | let directory = matches!(graph_op, GraphOp::DirAdd { .. }); |
| 575 | push_occupant_baseline( |
| 576 | txn, |
| 577 | change_hash, |
| 578 | path, |
| 579 | Some(added_position), |
| 580 | visible_on_target, |
| 581 | &mut ops, |
| 582 | )?; |
| 583 | push_unique( |
| 584 | &mut ops, |
| 585 | DeferredTreeOp { |
| 586 | change: change_hash, |
| 587 | inode: added_position, |
| 588 | baseline_path: None, |
| 589 | directory: Some(directory), |
| 590 | action: DeferredTreeAction::Set { path: path.clone() }, |
| 591 | }, |
| 592 | ); |
| 593 | } |
| 594 | GraphOp::FileMove { add, path, .. } => { |
| 595 | let external_position = external_position(change_hash, add.inode)?; |
| 596 | push_occupant_baseline( |
| 597 | txn, |
| 598 | change_hash, |
| 599 | path, |
| 600 | Some(external_position), |
| 601 | visible_on_target, |
| 602 | &mut ops, |
| 603 | )?; |
| 604 | let op = DeferredTreeOp { |
| 605 | change: change_hash, |
| 606 | inode: external_position, |
| 607 | baseline_path: current_path_for_position(txn, external_position)?, |
| 608 | directory: Some(false), |
| 609 | action: DeferredTreeAction::Set { path: path.clone() }, |
| 610 | }; |
| 611 | // Keep the event even when TREE already contains `path`. |
| 612 | // `atomic move` updates tracking before the subsequent record, |
| 613 | // and that recorded change must still supersede an older |
no test coverage detected