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

Function apply_branch_op

atomic-core/src/crdt/apply/branch.rs:93–131  ·  view source on GitHub ↗

Applies a BranchOp to the pristine database. This is the main entry point for applying line-level operations. # Arguments `txn` - The transaction to apply the operation in `context` - The apply context for tracking state and conflicts `trunk_id` - The parent trunk (file) this branch belongs to `branch_id` - The ID for the branch (for Insert ops, this is the new ID) `op` - The operation to apply

(
    txn: &mut T,
    context: &mut ApplyContext,
    trunk_id: TrunkId,
    branch_id: BranchId,
    op: &BranchOp,
    content: &[u8],
)

Source from the content-addressed store, hash-verified

91/// apply_branch_op(&mut txn, &mut context, trunk_id, branch_id, &op, &content)?;
92/// ```
93pub fn apply_branch_op<T: MutCrdtTxnT>(
94 txn: &mut T,
95 context: &mut ApplyContext,
96 trunk_id: TrunkId,
97 branch_id: BranchId,
98 op: &BranchOp,
99 content: &[u8],
100) -> ApplyResult<()> {
101 match op {
102 BranchOp::Insert {
103 after,
104 content: leaf_ops,
105 } => apply_insert(txn, context, trunk_id, branch_id, *after, leaf_ops, content),
106 BranchOp::Delete { branch, .. } => apply_delete(txn, context, *branch),
107 BranchOp::Modify {
108 branch,
109 new_content,
110 ..
111 } => {
112 // A Modify is semantically a delete-then-insert at the graph
113 // layer. Delete the old branch and insert a new one with the
114 // new content.
115 apply_delete(txn, context, *branch)?;
116 apply_insert(
117 txn,
118 context,
119 trunk_id,
120 branch_id,
121 Some(*branch),
122 new_content,
123 content,
124 )
125 }
126 BranchOp::Restore { branch } => apply_restore(txn, context, *branch),
127 BranchOp::Reparent { branch, new_after } => {
128 apply_reparent(txn, context, *branch, *new_after)
129 }
130 }
131}
132
133/// Applies a BranchOp without leaf operations.
134///

Calls 4

apply_reparentFunction · 0.85
apply_insertFunction · 0.70
apply_deleteFunction · 0.70
apply_restoreFunction · 0.70