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:280–367  ·  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

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

Callers 2

write_change_to_graphFunction · 0.85

Calls 10

verify_causal_frontierFunction · 0.85
compute_new_stateFunction · 0.85
open_or_create_viewMethod · 0.80
put_changeMethod · 0.80
update_viewMethod · 0.80
total_conflict_countMethod · 0.80
has_conflictsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected