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

Function write_change_to_graph_inner

atomic-repository/src/apply/mod.rs:283–383  ·  view source on GitHub ↗
(
    txn: &mut WriteTxn<'_>,
    view_name: &str,
    change_id: NodeId,
    change_hash: &Hash,
    change: &Change,
    options: &InsertOptions,
    already_in_graph: bool,
)

Source from the content-addressed store, hash-verified

281
282#[allow(clippy::too_many_arguments)]
283fn write_change_to_graph_inner(
284 txn: &mut WriteTxn<'_>,
285 view_name: &str,
286 change_id: NodeId,
287 change_hash: &Hash,
288 change: &Change,
289 options: &InsertOptions,
290 already_in_graph: bool,
291) -> InsertResult<InsertOutcome> {
292 let mut workspace = Workspace::new();
293 let mut conflict_tracker = ConflictTracker::new();
294 let mut stats = InsertStats::new();
295
296 // Get the current view
297 let mut view = txn
298 .open_or_create_view(view_name)
299 .map_err(|e| InsertError::Database(e.to_string()))?;
300
301 #[cfg(feature = "prototype-context-completion")]
302 if change
303 .hunks()
304 .iter()
305 .any(|op| matches!(op, GraphOp::PrototypeContext { .. }))
306 && (options.prototype_context.is_none() || !view.kind.is_draft())
307 {
308 return Err(InsertError::InvalidChange {
309 message: "experimental context carriers require atomic draft sandbox composition"
310 .into(),
311 });
312 }
313
314 // Validate we can apply (unless caller explicitly skipped validation,
315 // e.g. rebuild_change_graph re-applying an existing change with new hunks).
316 let verified_frontier = if options.skip_validation {
317 // Rebuild paths may skip duplicate/dependency checks, but a causal
318 // frontier is never accepted without complete local closure proof.
319 verify_causal_frontier(txn, change)?
320 } else {
321 validate_can_apply_with_frontier(txn, &view, change_id, change_hash, change)?
322 };
323
324 // Only apply hunks if the change isn't already in the graph.
325 // All edges go to the global GRAPH + INODE_GRAPH tables.
326 let should_apply_hunks = !already_in_graph;
327
328 log::debug!(
329 "write_change_to_graph: change_id={:?} hash={} should_apply_hunks={} view_kind={:?}",
330 change_id,
331 change_hash.to_base32(),
332 should_apply_hunks,
333 view.kind
334 );
335
336 if should_apply_hunks {
337 apply_change_hunks_locked(
338 txn,
339 &mut workspace,
340 &mut conflict_tracker,

Callers 2

write_change_to_graphFunction · 0.85

Calls 14

verify_causal_frontierFunction · 0.85
compute_new_stateFunction · 0.85
open_or_create_viewMethod · 0.80
is_noneMethod · 0.80
put_changeMethod · 0.80
update_viewMethod · 0.80
total_conflict_countMethod · 0.80
iterMethod · 0.45
hunksMethod · 0.45
is_draftMethod · 0.45

Tested by

no test coverage detected