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

Method resolve_view_claim

atomic-cli/src/commands/git/parallel.rs:4710–4751  ·  view source on GitHub ↗

The view a commit's Atomic claim is verified against, and the state it names when the view holds that state. The view is the commit's own `Atomic-View` header when that view exists (a record projection reached through a Git branch that has no Atomic view yet), else the branch's view. Every claimed root must be a member of that view; the named `Atomic-State` binds the roots and is kept only when e

(
        &self,
        source: &Repository,
        branch_name: &str,
        parsed: &ParsedCommit,
        claimed_roots: &[ContentHash],
    )

Source from the content-addressed store, hash-verified

4708 /// a member of that view; the named `Atomic-State` binds the roots and
4709 /// is kept only when every root is a member at that state.
4710 fn resolve_view_claim(
4711 &self,
4712 source: &Repository,
4713 branch_name: &str,
4714 parsed: &ParsedCommit,
4715 claimed_roots: &[ContentHash],
4716 ) -> CliResult<ViewClaim> {
4717 let message = parsed.full_message();
4718 let view = match parse_header_trailer(&message, "Atomic-View") {
4719 Some(named) if view_exists(source, &named)? => named,
4720 _ => branch_name.to_string(),
4721 };
4722 if !view_exists(source, &view)? {
4723 return Err(git_error(format!(
4724 "commit {} claims Atomic changes on view '{view}', which does not exist",
4725 parsed.git_sha
4726 )));
4727 }
4728 let claimed_state = parse_header_trailer(&message, "Atomic-State")
4729 .and_then(|encoded| Merkle::from_base32(encoded.as_bytes()));
4730 let history = source
4731 .effective_history(Some(&view))
4732 .map_err(|error| CliError::Internal(error.into()))?;
4733 let mut members = HashSet::with_capacity(history.len());
4734 let mut state = None;
4735 for entry in &history {
4736 members.insert(entry.hash);
4737 if state.is_none()
4738 && claimed_state == Some(entry.state)
4739 && claimed_roots.iter().all(|root| members.contains(root))
4740 {
4741 state = Some(entry.state);
4742 }
4743 }
4744 if !claimed_roots.iter().all(|root| members.contains(root)) {
4745 return Err(git_error(format!(
4746 "commit {} claims Atomic changes that are not members of view '{view}'",
4747 parsed.git_sha
4748 )));
4749 }
4750 Ok(ViewClaim { view, state })
4751 }
4752
4753 /// A tip that moved backwards onto an already-interpreted commit (`git
4754 /// reset --hard HEAD~1`, a rebase dropping the newest commit, a

Callers 1

Calls 12

parse_header_trailerFunction · 0.85
view_existsFunction · 0.85
full_messageMethod · 0.80
effective_historyMethod · 0.80
is_noneMethod · 0.80
git_errorFunction · 0.70
as_bytesMethod · 0.45
lenMethod · 0.45
insertMethod · 0.45
allMethod · 0.45
iterMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected