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

Function index_replayed_git_span

atomic-repository/src/repository/insert.rs:554–657  ·  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

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