(
change: Change,
origin: GitSynthesisOrigin,
metadata: Vec<u8>,
mut unhashed: serde_json::Value,
span_mode: bool,
)
| 353 | } |
| 354 | |
| 355 | fn prepare( |
| 356 | change: Change, |
| 357 | origin: GitSynthesisOrigin, |
| 358 | metadata: Vec<u8>, |
| 359 | mut unhashed: serde_json::Value, |
| 360 | span_mode: bool, |
| 361 | ) -> Result<Self, RepositoryError> { |
| 362 | if change.hashed.span.is_some() != span_mode { |
| 363 | return Err(invalid("stream change format does not match producer mode")); |
| 364 | } |
| 365 | if span_mode { |
| 366 | let patch = change.hashed.span.as_ref().expect("span mode checked"); |
| 367 | if !patch.prior_metadata.is_empty() || !change.hashed.metadata.is_empty() { |
| 368 | return Err(invalid( |
| 369 | "span compiler must not prepopulate foreign metadata", |
| 370 | )); |
| 371 | } |
| 372 | } else if change.hashed.metadata.starts_with(b"ATSP") { |
| 373 | return Err(invalid( |
| 374 | "opaque span-prefixed metadata is not accepted by the graph stream", |
| 375 | )); |
| 376 | } |
| 377 | if !change.file_ops().is_empty() { |
| 378 | return Err(invalid("direct graph stream does not import native CRDT identities; eager semantics are unsupported")); |
| 379 | } |
| 380 | let sha = git_oid_hex(&origin.commit); |
| 381 | let git = unhashed |
| 382 | .get_mut("git") |
| 383 | .and_then(serde_json::Value::as_object_mut) |
| 384 | .ok_or_else(|| invalid("prepared stream metadata needs the standard Git namespace"))?; |
| 385 | if git |
| 386 | .get("sha") |
| 387 | .and_then(serde_json::Value::as_str) |
| 388 | .is_some_and(|value| value != sha) |
| 389 | { |
| 390 | return Err(invalid( |
| 391 | "stream metadata SHA differs from its hashed Git origin", |
| 392 | )); |
| 393 | } |
| 394 | git.insert("sha".into(), serde_json::Value::String(sha.clone())); |
| 395 | let parent = origin.parents.first().map(git_oid_hex); |
| 396 | let deleted = change |
| 397 | .hunks() |
| 398 | .iter() |
| 399 | .filter_map(|op| match op { |
| 400 | GraphOp::FileDel { path, .. } => Some(path.clone()), |
| 401 | _ => None, |
| 402 | }) |
| 403 | .collect(); |
| 404 | let (change, bytes, hash) = finalize_classified_change( |
| 405 | change, |
| 406 | &SynthesisClassification::Synthesized(origin), |
| 407 | metadata, |
| 408 | unhashed, |
| 409 | )?; |
| 410 | Ok(Self { |
| 411 | change, |
| 412 | bytes, |
no test coverage detected