(tip, optional parent tree) projection pair
(
repo: &Repository,
repo_root: &Path,
git_repo: &GitRepository,
target_ref: &str,
default_parent: Option<&str>,
view: &str,
state: &str,
tree_oid: git2::Oid,
publi
| 1465 | #[allow(clippy::too_many_arguments)] |
| 1466 | #[allow(clippy::type_complexity)] // (tip, optional parent tree) projection pair |
| 1467 | fn build_switch_projection( |
| 1468 | repo: &Repository, |
| 1469 | repo_root: &Path, |
| 1470 | git_repo: &GitRepository, |
| 1471 | target_ref: &str, |
| 1472 | default_parent: Option<&str>, |
| 1473 | view: &str, |
| 1474 | state: &str, |
| 1475 | tree_oid: git2::Oid, |
| 1476 | publication: &VerifiedPublication, |
| 1477 | record_metadata: Option<&RecordProjectionMetadata>, |
| 1478 | conflict_set_hash: Option<atomic_core::Hash>, |
| 1479 | ) -> CliResult<( |
| 1480 | atomic_core::operation::GitObjectId, |
| 1481 | Option<(atomic_core::operation::GitObjectId, Vec<u8>)>, |
| 1482 | )> { |
| 1483 | if publication.view() != view || publication.git_tree_oid()? != tree_oid { |
| 1484 | return Err(git_error( |
| 1485 | "shadow projection does not match verified publication", |
| 1486 | )); |
| 1487 | } |
| 1488 | // One parent by default: the previous projected state on the mapped ref |
| 1489 | // (RFC §8.2). An advanced ephemeral view defaults to its adopted commit. |
| 1490 | // A second parent is only produced by an explicit whole-view merge |
| 1491 | // publication, which the switch path never performs. |
| 1492 | let parent_oid = match git_repo.find_reference(target_ref) { |
| 1493 | Ok(reference) => { |
| 1494 | let commit = reference.peel_to_commit().map_err(|error| { |
| 1495 | git_error(format!( |
| 1496 | "cannot read target projection ref '{target_ref}': {error}" |
| 1497 | )) |
| 1498 | })?; |
| 1499 | if commit.tree_id() == tree_oid { |
| 1500 | // The mapped ref already tips at the projection: the commit |
| 1501 | // object is durable and no ref movement is journaled. |
| 1502 | return Ok((to_core_oid(commit.id())?, None)); |
| 1503 | } |
| 1504 | commit.id() |
| 1505 | } |
| 1506 | Err(error) if error.code() == git2::ErrorCode::NotFound => { |
| 1507 | if let Some(original) = default_parent { |
| 1508 | git_repo |
| 1509 | .revparse_single(original) |
| 1510 | .and_then(|object| object.peel_to_commit()) |
| 1511 | .map_err(|error| { |
| 1512 | git_error(format!( |
| 1513 | "ephemeral default parent {original} is unreadable: {error}" |
| 1514 | )) |
| 1515 | })? |
| 1516 | .id() |
| 1517 | } else { |
| 1518 | git_repo |
| 1519 | .head() |
| 1520 | .and_then(|head| head.peel_to_commit()) |
| 1521 | .map_err(|error| { |
| 1522 | git_error(format!( |
| 1523 | "cannot create shadow projection for '{view}' without a current Git HEAD commit: {error}" |
| 1524 | )) |
no test coverage detected