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

Function parse_advertisement

atomic-cli/src/commands/push/command.rs:54–82  ·  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

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

Callers 1

run_asyncMethod · 0.70

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