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

Method fetch_manifest_chain

atomic-cli/src/commands/clone/command.rs:471–511  ·  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

469 /// that loops, means the remote's view metadata is corrupted and is a
470 /// hard error.
471 fn fetch_manifest_chain(&self, pack: &SyncPack) -> CliResult<Option<Vec<ViewManifest>>> {
472 let Some(leaf) = self.view_manifest_from_pack(pack, &self.view)? else {
473 return Ok(None);
474 };
475
476 let mut visited: HashSet<String> = HashSet::new();
477 visited.insert(leaf.name.clone());
478 let mut next_parent = leaf.parent.clone();
479 let mut chain = vec![leaf];
480
481 while let Some(parent) = next_parent {
482 if !visited.insert(parent.clone()) {
483 return Err(CliError::RemoteError {
484 message: format!(
485 "View parent chain loops at '{}' — the remote's view metadata is corrupted",
486 parent
487 ),
488 url: Some(self.url.clone()),
489 });
490 }
491 let child_name = chain
492 .last()
493 .map(|m| m.name.clone())
494 .unwrap_or_else(|| self.view.clone());
495 let manifest = self
496 .view_manifest_from_pack(pack, &parent)?
497 .ok_or_else(|| CliError::RemoteError {
498 message: format!(
499 "View '{}' declares parent '{}', but the remote has no such view",
500 child_name, parent
501 ),
502 url: Some(self.url.clone()),
503 })?;
504 next_parent = manifest.parent.clone();
505 chain.push(manifest);
506 }
507
508 // Collected leaf→root; parents must be applied first.
509 chain.reverse();
510 Ok(Some(chain))
511 }
512
513 /// Download every change in `missing` and save it to the change store.
514 ///

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