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

Method apply_view_manifest

atomic-repository/src/repository/views.rs:889–1056  ·  view source on GitHub ↗

Declaratively apply a [`ViewManifest`]: create the view with its declared identity if absent, then fast-forward its change log to match the manifest. # Semantics Everything is validated **before** any write: 1. The manifest's declared state must equal the fold of its log. 2. Every referenced change file must be present in the local store. 3. Every dependency of every change must appear earlier

(
        &mut self,
        manifest: &ViewManifest,
    )

Source from the content-addressed store, hash-verified

887 /// resumes where it stopped. After replay the view's merkle state is
888 /// verified against the declared state.
889 pub fn apply_view_manifest(
890 &mut self,
891 manifest: &ViewManifest,
892 ) -> Result<ManifestApplyOutcome, RepositoryError> {
893 // 1. Structural integrity: declared state == fold of the log.
894 manifest.verify()?;
895
896 // 2. Presence: every change file must exist locally.
897 let missing: Vec<&Hash> = manifest
898 .changes
899 .iter()
900 .filter(|h| !self.has_change(h))
901 .collect();
902 if let Some(first) = missing.first() {
903 return Err(RepositoryError::ManifestMissingChanges {
904 view: manifest.name.clone(),
905 count: missing.len(),
906 first: first.to_base32(),
907 });
908 }
909
910 // 3. Dependency closure: deps must be earlier in the log or already
911 // applied locally. Read from the change files (self-contained DAG).
912 {
913 let txn = self
914 .pristine
915 .read_txn()
916 .map_err(|e| RepositoryError::Database(e.to_string()))?;
917 let mut seen: HashSet<Hash> = HashSet::with_capacity(manifest.changes.len());
918 for hash in &manifest.changes {
919 let change = self.load_change(hash)?;
920 for dep in change.dependencies() {
921 if seen.contains(dep) {
922 continue;
923 }
924 let applied = txn
925 .get_internal(dep)
926 .map_err(|e| RepositoryError::Database(e.to_string()))?
927 .is_some();
928 if !applied {
929 return Err(RepositoryError::ManifestDependencyMissing {
930 view: manifest.name.clone(),
931 change: hash.to_base32(),
932 dependency: dep.to_base32(),
933 });
934 }
935 }
936 seen.insert(*hash);
937 }
938 }
939
940 // 4. Identity + prefix rule against the existing view (if any).
941 let prefix_len = {
942 let txn = self
943 .pristine
944 .read_txn()
945 .map_err(|e| RepositoryError::Database(e.to_string()))?;
946 match txn

Calls 15

read_txnMethod · 0.80
view_existsMethod · 0.80
get_view_infoMethod · 0.80
getMethod · 0.65
verifyMethod · 0.45
iterMethod · 0.45
has_changeMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
to_base32Method · 0.45
load_changeMethod · 0.45