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

Method checked_git_sha

atomic-repository/src/repository/resurrection.rs:617–646  ·  view source on GitHub ↗

The checked `GIT_SHA_INDEX` row for one SHA. A row is usable only when the mapped change is registered, loadable, decodes to exactly its claimed identity, and its unhashed provenance names this SHA. Anything else is a stale/missing/ambiguous/malicious entry and reports `None` — the same treatment as a cold cache.

(&self, sha: &str)

Source from the content-addressed store, hash-verified

615 /// names this SHA. Anything else is a stale/missing/ambiguous/malicious
616 /// entry and reports `None` — the same treatment as a cold cache.
617 pub fn checked_git_sha(&self, sha: &str) -> Result<Option<Hash>, RepositoryError> {
618 use atomic_core::pristine::{GitShaIndexTxnT, GraphTxnT};
619 let txn = self.pristine.read_txn().map_err(pristine_map)?;
620 let Some(change_id) = txn.get_by_git_sha(sha).map_err(pristine_map)? else {
621 return Ok(None);
622 };
623 let Some(hash) = txn.get_external(change_id).map_err(pristine_map)? else {
624 return Ok(None);
625 };
626 drop(txn);
627 if !self.has_change(&hash) {
628 return Ok(None);
629 }
630 let Ok(change) = self.load_change(&hash) else {
631 return Ok(None);
632 };
633 let names_sha = change
634 .unhashed
635 .as_ref()
636 .and_then(|unhashed| unhashed.get("git"))
637 .and_then(|git| git.get("sha"))
638 .and_then(|value| value.as_str())
639 .map(|claimed| claimed == sha)
640 .unwrap_or(false);
641 if names_sha {
642 Ok(Some(hash))
643 } else {
644 Ok(None)
645 }
646 }
647
648 /// The raw `GIT_SHA_INDEX` row for one SHA: the mapped change must be
649 /// registered, loadable, and decode to exactly its claimed identity.

Calls 8

read_txnMethod · 0.80
as_refMethod · 0.80
getMethod · 0.65
get_by_git_shaMethod · 0.45
get_externalMethod · 0.45
has_changeMethod · 0.45
load_changeMethod · 0.45
as_strMethod · 0.45