MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / collect_tree_ops

Function collect_tree_ops

atomic-repository/src/repository/deferred_tree.rs:556–703  ·  view source on GitHub ↗

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>>,
)

Source from the content-addressed store, hash-verified

554/// imports, keeps replay baselines valid when a later foreground change moves
555/// the same inode on another view.
556pub(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

Callers 1

plan_tree_projectionMethod · 0.85

Calls 10

push_occupant_baselineFunction · 0.85
push_uniqueFunction · 0.85
external_positionFunction · 0.85
push_delete_for_pathFunction · 0.85
hunksMethod · 0.45
cloneMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected