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

Function validate_branch_parent

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

Validates that a branch belongs to the specified trunk. # Arguments `txn` - The transaction `branch_id` - The branch to validate `expected_trunk` - The expected parent trunk # Returns `Ok(())` if the branch belongs to the trunk.

(
    txn: &T,
    branch_id: BranchId,
    expected_trunk: TrunkId,
)

Source from the content-addressed store, hash-verified

444///
445/// `Ok(())` if the branch belongs to the trunk.
446pub fn validate_branch_parent<T: MutCrdtTxnT>(
447 txn: &T,
448 branch_id: BranchId,
449 expected_trunk: TrunkId,
450) -> ApplyResult<()> {
451 let branch = txn
452 .get_branch(branch_id)
453 .map_err(|e| storage_err(e, "getting branch"))?
454 .ok_or_else(|| ApplyError::branch_not_found(branch_id))?;
455
456 if branch.trunk() != expected_trunk {
457 return Err(ApplyError::internal(format!(
458 "Branch {} belongs to trunk {}, not {}",
459 branch_id,
460 branch.trunk(),
461 expected_trunk
462 )));
463 }
464
465 Ok(())
466}
467
468// Tests
469

Callers 1

Calls 3

storage_errFunction · 0.85
get_branchMethod · 0.45
trunkMethod · 0.45

Tested by 1