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

Function check_can_unrecord

atomic-repository/src/unrecord.rs:437–488  ·  view source on GitHub ↗

Check if a change can be unrecorded from a view. This verifies that: 1. The change is in the view 2. No other changes in the view depend on it (unless cascade is enabled) # Arguments `txn` - Read transaction `view` - View to check `hash` - Hash of the change to check `options` - Unrecord options # Returns `UnrecordDependencyInfo` with details about dependencies.

(
    txn: &T,
    view: &ViewState,
    hash: &Hash,
    options: &UnrecordOptions,
)

Source from the content-addressed store, hash-verified

435///
436/// `UnrecordDependencyInfo` with details about dependencies.
437pub fn check_can_unrecord<T: ViewTxnT>(
438 txn: &T,
439 view: &ViewState,
440 hash: &Hash,
441 options: &UnrecordOptions,
442) -> UnrecordResult<UnrecordDependencyInfo> {
443 // Get internal ID
444 let node_id = txn
445 .get_internal(hash)
446 .map_err(|e| UnrecordError::Database(e.to_string()))?
447 .ok_or_else(|| UnrecordError::ChangeNotFound {
448 hash: hash.to_base32(),
449 })?;
450
451 // Check if change is in view
452 let _seq = txn
453 .get_change_seq(view, node_id)
454 .map_err(|e| UnrecordError::Database(e.to_string()))?
455 .ok_or_else(|| UnrecordError::NotInView {
456 hash: hash.to_base32(),
457 view: view.name.clone(),
458 })?;
459
460 let mut info = UnrecordDependencyInfo::new(*hash);
461
462 // Find dependents in the view
463 // This requires checking all changes after this one to see if they depend on it
464 let iter = txn
465 .iter_changes(view, 0)
466 .map_err(|e| UnrecordError::Database(e.to_string()))?;
467
468 for result in iter {
469 let (_, change_id, _) = result.map_err(|e| UnrecordError::Database(e.to_string()))?;
470
471 // Skip the change itself
472 if change_id == node_id {
473 continue;
474 }
475
476 // Note: In a full implementation, we'd check the change's dependencies
477 // by loading it from the change store. For now, we rely on the deps table.
478 // This is a simplified check.
479 }
480
481 // If cascade is enabled, we can always unrecord
482 if options.cascade {
483 info.can_unrecord = true;
484 info.block_reason = None;
485 }
486
487 Ok(info)
488}
489
490/// Find all changes that would need to be unrecorded to safely remove a change.
491///

Callers 2

preview_unrecordFunction · 0.85
can_unrecordMethod · 0.85

Calls 5

get_internalMethod · 0.45
to_base32Method · 0.45
get_change_seqMethod · 0.45
cloneMethod · 0.45
iter_changesMethod · 0.45

Tested by

no test coverage detected