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

Function apply_delete

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

Applies a Delete operation to mark a line as deleted. # Behavior 1. Verifies the branch exists 2. Verifies the branch is not already deleted 3. Updates the branch's state to Deleted Note: The branch entry remains in the database (tombstone). Associated leaves are not automatically deleted. # Errors - `BranchNotFound` - The branch doesn't exist - `InvalidBranchState` - The branch is already de

(
    txn: &mut T,
    context: &mut ApplyContext,
    branch_id: BranchId,
)

Source from the content-addressed store, hash-verified

280/// - `BranchNotFound` - The branch doesn't exist
281/// - `InvalidBranchState` - The branch is already deleted
282fn apply_delete<T: MutCrdtTxnT>(
283 txn: &mut T,
284 context: &mut ApplyContext,
285 branch_id: BranchId,
286) -> ApplyResult<()> {
287 // Verify branch exists
288 let branch = txn
289 .get_branch(branch_id)
290 .map_err(|e| storage_err(e, "getting branch"))?
291 .ok_or_else(|| ApplyError::branch_not_found(branch_id))?;
292
293 // Check current state
294 if branch.state().is_deleted() {
295 if context.options().allow_duplicate_ids() {
296 context.record_skipped();
297 return Ok(());
298 }
299 return Err(ApplyError::invalid_branch_state(
300 branch_id, "deleted", "delete",
301 ));
302 }
303
304 // Update state to deleted
305 txn.update_branch_state(branch_id, BranchState::Deleted)
306 .map_err(|e| storage_err(e, "updating branch state"))?;
307
308 context.record_branch_deleted();
309 Ok(())
310}
311
312// Restore Operation
313

Callers 2

apply_branch_opFunction · 0.70
apply_branch_op_onlyFunction · 0.70

Calls 9

storage_errFunction · 0.85
allow_duplicate_idsMethod · 0.80
record_branch_deletedMethod · 0.80
get_branchMethod · 0.45
is_deletedMethod · 0.45
stateMethod · 0.45
optionsMethod · 0.45
record_skippedMethod · 0.45
update_branch_stateMethod · 0.45

Tested by

no test coverage detected