MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / build_switch_projection

Function build_switch_projection

atomic-cli/src/commands/git/shadow.rs:1467–1639  ·  view source on GitHub ↗

(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

Source from the content-addressed store, hash-verified

1465#[allow(clippy::too_many_arguments)]
1466#[allow(clippy::type_complexity)] // (tip, optional parent tree) projection pair
1467fn 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 ))

Callers 1

Calls 15

to_core_oidFunction · 0.85
projection_authorFunction · 0.85
build_projected_commitFunction · 0.85
projection_message_forFunction · 0.85
local_utc_offset_minutesFunction · 0.85
git_tree_oidMethod · 0.80
signatureMethod · 0.80
as_refMethod · 0.80
view_set_idMethod · 0.80
emailMethod · 0.80
git_errorFunction · 0.70
viewMethod · 0.45

Tested by

no test coverage detected