Insert a change into the current view. This is the high-level method for inserting a single change into the repository. It loads the change from the change store, validates dependencies, applies atoms to the graph, and updates the view state. # Arguments `hash` - The hash of the change to insert `options` - Options controlling insertion behavior # Returns An `InsertOutcome` containing the new
(
&self,
hash: &Hash,
options: InsertOptions,
)
| 2418 | /// println!("New state: {}", result.new_state.to_base32()); |
| 2419 | /// ``` |
| 2420 | pub fn insert_change( |
| 2421 | &self, |
| 2422 | hash: &Hash, |
| 2423 | options: InsertOptions, |
| 2424 | ) -> Result<InsertOutcome, RepositoryError> { |
| 2425 | let change = self.load_change(hash)?; |
| 2426 | let view_name = options |
| 2427 | .view |
| 2428 | .as_deref() |
| 2429 | .unwrap_or(&self.current_view) |
| 2430 | .to_string(); |
| 2431 | let _span_lock = if self.span_in_closure(std::slice::from_ref(hash))? { |
| 2432 | let working_copy = self.require_working_copy_id()?; |
| 2433 | let lock = self.try_lock_workspace_operation(working_copy)?; |
| 2434 | self.preflight_span_references(&view_name, std::slice::from_ref(hash), true)?; |
| 2435 | Some(lock) |
| 2436 | } else { |
| 2437 | None |
| 2438 | }; |
| 2439 | self.ensure_project_identity(atomic_core::kg::project_id::MintReason::Upgrade)?; |
| 2440 | let trace_insert = std::env::var_os("ATOMIC_TRACE_INSERT").is_some(); |
| 2441 | let t0 = std::time::Instant::now(); |
| 2442 | |
| 2443 | // The change was checked before any repository mutation. |
| 2444 | // CB-12B: trusted provenance publication gate. Before any metadata |
| 2445 | // operation or mutation on a Shared target, the complete reachable |
| 2446 | // closure of this change must carry trusted managed-session evidence. |
| 2447 | // Draft targets are unaffected (work stays local until promotion). |
| 2448 | if !options.skip_publication_gate { |
| 2449 | let shared_target = { |
| 2450 | let txn = self |
| 2451 | .pristine |
| 2452 | .read_txn() |
| 2453 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 2454 | txn.get_view(&view_name) |
| 2455 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 2456 | .map(|view| view.kind == atomic_core::pristine::ViewScope::Shared) |
| 2457 | .unwrap_or(false) |
| 2458 | }; |
| 2459 | if shared_target { |
| 2460 | let closure = |
| 2461 | super::provenance_gate::reachable_closure(self, std::slice::from_ref(hash))?; |
| 2462 | let provider = super::provenance_gate::local_session_mac_key_provider(self); |
| 2463 | let did_provider = super::provenance_gate::local_did_key_provider(self); |
| 2464 | self.enforce_publication_gate( |
| 2465 | "shared-view insertion", |
| 2466 | &closure, |
| 2467 | Some(&provider), |
| 2468 | Some(&did_provider), |
| 2469 | )?; |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | let operation_context = if let Some(working_copy) = self.working_copy_id() { |
| 2474 | let operation_lock = self.try_lock_operation(working_copy)?; |
| 2475 | if let OperationHeadState::Diverged(heads) = |
| 2476 | self.consolidate_operation_heads_locked(&operation_lock)? |
| 2477 | { |