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

Function index_replayed_git_span

atomic-repository/src/repository/insert.rs:562–665  ·  view source on GitHub ↗
(
    txn: &mut atomic_core::pristine::WriteTxn<'_>,
    change_id: NodeId,
    hash: Hash,
    change: &Change,
    allow_create: bool,
)

Source from the content-addressed store, hash-verified

560}
561
562fn index_replayed_git_span(
563 txn: &mut atomic_core::pristine::WriteTxn<'_>,
564 change_id: NodeId,
565 hash: Hash,
566 change: &Change,
567 allow_create: bool,
568) -> Result<(), RepositoryError> {
569 use atomic_core::pristine::{
570 EffectiveProjectionClosure, GitCommitClosureMutTxnT, GitCommitClosureTxnT,
571 GitShaIndexMutTxnT, GitShaIndexTxnT, ViewMembershipSet,
572 };
573 let atomic_core::change::ChangeOrigin::GitSynthesized {
574 commit, parents, ..
575 } = change.origin()
576 else {
577 return Err(RepositoryError::Apply(
578 "replayed Git span has no Git origin".into(),
579 ));
580 };
581 let sha = super::synthesis::git_oid_hex(commit);
582 match txn.get_by_git_sha(&sha)? {
583 Some(existing) if existing != change_id => {
584 return Err(RepositoryError::Apply(format!(
585 "Git commit {sha} already has a different repository identity"
586 )))
587 }
588 None if !allow_create => {
589 return Err(RepositoryError::Apply(format!(
590 "Git commit {sha} identity is missing"
591 )))
592 }
593 _ => {}
594 }
595 let mut closure = if let Some(parent) = parents.first() {
596 let parent_sha = super::synthesis::git_oid_hex(parent);
597 let parent_id = txn.get_by_git_sha(&parent_sha)?.ok_or_else(|| {
598 RepositoryError::Apply(format!("Git parent {parent_sha} is not indexed"))
599 })?;
600 let dependency_ids = change
601 .dependencies()
602 .iter()
603 .map(|dependency| {
604 txn.get_internal(dependency)?
605 .ok_or_else(|| RepositoryError::Apply("Git replay dependency missing".into()))
606 })
607 .collect::<Result<Vec<_>, RepositoryError>>()?;
608 let visible = EffectiveProjectionClosure::try_from_membership(
609 txn,
610 &ViewMembershipSet::from_ordered(dependency_ids),
611 )?;
612 if !visible.contains(parent_id) {
613 return Err(RepositoryError::Apply(
614 "Git first parent is outside the change dependency closure".into(),
615 ));
616 }
617 let parent_hash = txn
618 .get_external(parent_id)?
619 .ok_or_else(|| RepositoryError::Apply("Git parent hash missing".into()))?;

Callers 2

Calls 13

originMethod · 0.80
sortMethod · 0.80
put_git_shaMethod · 0.80
git_oid_hexFunction · 0.70
get_by_git_shaMethod · 0.45
iterMethod · 0.45
dependenciesMethod · 0.45
get_internalMethod · 0.45
containsMethod · 0.45
get_externalMethod · 0.45

Tested by

no test coverage detected