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

Method fetch_manifest_chain

atomic-cli/src/commands/clone/command.rs:574–614  ·  view source on GitHub ↗

Fetch the requested view's manifest and walk its parent chain up to the root, returning the manifests in root→leaf apply order. Returns `Ok(None)` when the requested view does not exist on the remote. A declared parent that is missing remotely, or a parent chain that loops, means the remote's view metadata is corrupted and is a hard error.

(&self, pack: &SyncPack)

Source from the content-addressed store, hash-verified

572 /// that loops, means the remote's view metadata is corrupted and is a
573 /// hard error.
574 fn fetch_manifest_chain(&self, pack: &SyncPack) -> CliResult<Option<Vec<ViewManifest>>> {
575 let Some(leaf) = self.view_manifest_from_pack(pack, &self.view)? else {
576 return Ok(None);
577 };
578
579 let mut visited: HashSet<String> = HashSet::new();
580 visited.insert(leaf.name.clone());
581 let mut next_parent = leaf.parent.clone();
582 let mut chain = vec![leaf];
583
584 while let Some(parent) = next_parent {
585 if !visited.insert(parent.clone()) {
586 return Err(CliError::RemoteError {
587 message: format!(
588 "View parent chain loops at '{}' — the remote's view metadata is corrupted",
589 parent
590 ),
591 url: Some(self.url.clone()),
592 });
593 }
594 let child_name = chain
595 .last()
596 .map(|m| m.name.clone())
597 .unwrap_or_else(|| self.view.clone());
598 let manifest = self
599 .view_manifest_from_pack(pack, &parent)?
600 .ok_or_else(|| CliError::RemoteError {
601 message: format!(
602 "View '{}' declares parent '{}', but the remote has no such view",
603 child_name, parent
604 ),
605 url: Some(self.url.clone()),
606 })?;
607 next_parent = manifest.parent.clone();
608 chain.push(manifest);
609 }
610
611 // Collected leaf→root; parents must be applied first.
612 chain.reverse();
613 Ok(Some(chain))
614 }
615
616 /// Download every change in `missing` and save it to the change store.
617 ///

Callers 1

run_asyncMethod · 0.80

Calls 6

lastMethod · 0.80
insertMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
reverseMethod · 0.45

Tested by

no test coverage detected