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

Function parse_advertisement

atomic-cli/src/commands/push/command.rs:52–80  ·  view source on GitHub ↗

Parse a ref-advertisement [`SyncPack`] (from `sync_pull` with `refs_only`) into per-view snapshot keys and manifests. This replaces the legacy per-view `get_view_ref` + `get_object("views", …)` round-trips: push negotiation now reads the remote's view state from a single `/code` advertisement, uniform across local (`FsStore`) and geo (`S3Store`).

(adv: &SyncPack, url: &str)

Source from the content-addressed store, hash-verified

50/// round-trips: push negotiation now reads the remote's view state from a single
51/// `/code` advertisement, uniform across local (`FsStore`) and geo (`S3Store`).
52fn parse_advertisement(adv: &SyncPack, url: &str) -> CliResult<RemoteAdvertisement> {
53 let mut snapshots: HashMap<String, ViewSnapshot> = HashMap::new();
54 for obj in &adv.objects {
55 if obj.family == ObjectFamily::View {
56 if let Some(s) = ViewSnapshot::from_bytes(&obj.bytes) {
57 snapshots.insert(obj.key.clone(), s);
58 }
59 }
60 }
61 let mut ref_targets = HashMap::new();
62 let mut manifests = HashMap::new();
63 for r in &adv.refs {
64 ref_targets.insert(r.name.clone(), r.new_target.clone());
65 match snapshots.get(&r.new_target) {
66 Some(s) => {
67 let manifest = parse_remote_manifest(&r.name, &s.to_manifest_text(&r.name), url)?;
68 manifests.insert(r.name.clone(), manifest);
69 }
70 None => {
71 // Ref points at a snapshot the advertisement did not carry;
72 // treat the view as absent (a re-push heals it).
73 }
74 }
75 }
76 Ok(RemoteAdvertisement {
77 ref_targets,
78 manifests,
79 })
80}
81
82/// Mint the content-addressed `ViewSnapshot` for a view from its local manifest
83/// and the remote's current snapshot key (`prev`, for the CAS-on-`prev` chain).

Callers 1

run_asyncMethod · 0.85

Calls 5

to_manifest_textMethod · 0.80
parse_remote_manifestFunction · 0.70
getMethod · 0.65
insertMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected