(
txn: &mut WriteTxn<'_>,
view_name: &str,
change_id: NodeId,
change_hash: &Hash,
change: &Change,
options: &InsertOptions,
already_in_graph: bool,
)
| 278 | |
| 279 | #[allow(clippy::too_many_arguments)] |
| 280 | fn 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 |
no test coverage detected