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

Function build_switch_projection

atomic-cli/src/commands/git/shadow.rs:1655–1827  ·  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

1653#[allow(clippy::too_many_arguments)]
1654#[allow(clippy::type_complexity)] // (tip, optional parent tree) projection pair
1655fn build_switch_projection(
1656 repo: &Repository,
1657 repo_root: &Path,
1658 git_repo: &GitRepository,
1659 target_ref: &str,
1660 default_parent: Option<&str>,
1661 view: &str,
1662 state: &str,
1663 tree_oid: git2::Oid,
1664 publication: &VerifiedPublication,
1665 record_metadata: Option<&RecordProjectionMetadata>,
1666 conflict_set_hash: Option<atomic_core::Hash>,
1667) -> CliResult<(
1668 atomic_core::operation::GitObjectId,
1669 Option<(atomic_core::operation::GitObjectId, Vec<u8>)>,
1670)> {
1671 if publication.view() != view || publication.git_tree_oid()? != tree_oid {
1672 return Err(git_error(
1673 "shadow projection does not match verified publication",
1674 ));
1675 }
1676 // One parent by default: the previous projected state on the mapped ref
1677 // (RFC §8.2). An advanced ephemeral view defaults to its adopted commit.
1678 // A second parent is only produced by an explicit whole-view merge
1679 // publication, which the switch path never performs.
1680 let parent_oid = match git_repo.find_reference(target_ref) {
1681 Ok(reference) => {
1682 let commit = reference.peel_to_commit().map_err(|error| {
1683 git_error(format!(
1684 "cannot read target projection ref '{target_ref}': {error}"
1685 ))
1686 })?;
1687 if commit.tree_id() == tree_oid {
1688 // The mapped ref already tips at the projection: the commit
1689 // object is durable and no ref movement is journaled.
1690 return Ok((to_core_oid(commit.id())?, None));
1691 }
1692 commit.id()
1693 }
1694 Err(error) if error.code() == git2::ErrorCode::NotFound => {
1695 if let Some(original) = default_parent {
1696 git_repo
1697 .revparse_single(original)
1698 .and_then(|object| object.peel_to_commit())
1699 .map_err(|error| {
1700 git_error(format!(
1701 "ephemeral default parent {original} is unreadable: {error}"
1702 ))
1703 })?
1704 .id()
1705 } else {
1706 git_repo
1707 .head()
1708 .and_then(|head| head.peel_to_commit())
1709 .map_err(|error| {
1710 git_error(format!(
1711 "cannot create shadow projection for '{view}' without a current Git HEAD commit: {error}"
1712 ))

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