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

Function apply_restore

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

Applies a Restore operation to restore a deleted line. # Behavior 1. Verifies the branch exists 2. Verifies the branch is currently deleted 3. Updates the branch's state to Alive # Errors - `BranchNotFound` - The branch doesn't exist - `InvalidBranchState` - The branch is not deleted

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

Source from the content-addressed store, hash-verified

324/// - `BranchNotFound` - The branch doesn't exist
325/// - `InvalidBranchState` - The branch is not deleted
326fn apply_restore<T: MutCrdtTxnT>(
327 txn: &mut T,
328 context: &mut ApplyContext,
329 branch_id: BranchId,
330) -> ApplyResult<()> {
331 // Verify branch exists
332 let branch = txn
333 .get_branch(branch_id)
334 .map_err(|e| storage_err(e, "getting branch"))?
335 .ok_or_else(|| ApplyError::branch_not_found(branch_id))?;
336
337 // Check current state
338 if !branch.state().is_deleted() {
339 if context.options().allow_duplicate_ids() {
340 context.record_skipped();
341 return Ok(());
342 }
343 return Err(ApplyError::invalid_branch_state(
344 branch_id, "alive", "restore",
345 ));
346 }
347
348 // Update state to alive
349 txn.update_branch_state(branch_id, BranchState::Alive)
350 .map_err(|e| storage_err(e, "updating branch state"))?;
351
352 context.record_branch_restored();
353 Ok(())
354}
355
356// Reparent Operation
357

Callers 2

apply_branch_opFunction · 0.70
apply_branch_op_onlyFunction · 0.70

Calls 9

storage_errFunction · 0.85
allow_duplicate_idsMethod · 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