(
repo: &Repository,
view: &str,
)
| 319 | } |
| 320 | |
| 321 | fn observe_atomic_on_handle( |
| 322 | repo: &Repository, |
| 323 | view: &str, |
| 324 | ) -> Result<CheckpointAtomicState, CheckpointError> { |
| 325 | let state = repo |
| 326 | .get_view_info(view) |
| 327 | .map_err(|error| CheckpointError::Atomic(error.to_string()))? |
| 328 | .state |
| 329 | .to_string(); |
| 330 | let mut paths: Vec<_> = repo |
| 331 | .visible_file_paths(view) |
| 332 | .map_err(|error| CheckpointError::Atomic(error.to_string()))? |
| 333 | .into_iter() |
| 334 | .collect(); |
| 335 | paths.sort(); |
| 336 | |
| 337 | // RFC §8.3 (CB-8B): a conflicted view's materialized state IS the |
| 338 | // marker projection. The checkpoint's atomic-visible manifest must |
| 339 | // describe exactly the bytes on disk and in the conflict snapshot's Git |
| 340 | // tree, so the workspace classifies as aligned instead of inventing |
| 341 | // "pending edits" for the lossy marker representation. |
| 342 | let conflict_markers = repo |
| 343 | .capture_view_conflict_set_with_markers(view) |
| 344 | .map_err(|error| CheckpointError::Atomic(error.to_string()))? |
| 345 | .map(|(object, markers)| (object.hash().ok(), markers)); |
| 346 | |
| 347 | // Paths with marker bytes never consult the graph. Every other path is |
| 348 | // streamed from one read (one projection, one span context) in the same |
| 349 | // sorted order, and hashed as it arrives so only one file is held at a |
| 350 | // time; marker paths are hashed from their marker bytes in between. |
| 351 | let marker_bytes = |path: &str| -> Option<&[u8]> { |
| 352 | conflict_markers |
| 353 | .as_ref() |
| 354 | .and_then(|(_, markers)| markers.get(path)) |
| 355 | .map(Vec::as_slice) |
| 356 | }; |
| 357 | let graph_paths: Vec<String> = paths |
| 358 | .iter() |
| 359 | .filter(|path| marker_bytes(path).is_none()) |
| 360 | .cloned() |
| 361 | .collect(); |
| 362 | let mut hasher = blake3::Hasher::new(); |
| 363 | hasher.update(ATOMIC_MANIFEST_DOMAIN); |
| 364 | let hash_entry = |hasher: &mut blake3::Hasher, path: &str, content: &[u8]| { |
| 365 | hasher.update(&(path.len() as u64).to_le_bytes()); |
| 366 | hasher.update(path.as_bytes()); |
| 367 | hasher.update(&(content.len() as u64).to_le_bytes()); |
| 368 | hasher.update(content); |
| 369 | }; |
| 370 | let mut next = 0usize; |
| 371 | let mut missing: Option<String> = None; |
| 372 | let streamed = repo.for_each_file_content_on_view(&graph_paths, view, |path, bytes| { |
| 373 | while paths.get(next).is_some_and(|pending| pending != path) { |
| 374 | let pending = &paths[next]; |
| 375 | match marker_bytes(pending) { |
| 376 | Some(marker) => hash_entry(&mut hasher, pending, marker), |
| 377 | None => { |
| 378 | missing = Some(pending.clone()); |
no test coverage detected