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,
)
| 324 | /// - `BranchNotFound` - The branch doesn't exist |
| 325 | /// - `InvalidBranchState` - The branch is not deleted |
| 326 | fn 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 |
no test coverage detected