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

Method fork_view

atomic-remote/src/http/upload.rs:266–317  ·  view source on GitHub ↗

Fork a view on the remote server. Creates a new view from an existing one. This is a lightweight server-side operation — no data is duplicated. The new view's changelog is copied from the source view in a single transaction. # Arguments `target_view` - The name of the new view to create. `source_view` - The name of the existing view to fork from. # Returns The number of changes adopted into t

(&self, target_view: &str, source_view: &str)

Source from the content-addressed store, hash-verified

264 ///
265 /// The number of changes adopted into the new view.
266 pub async fn fork_view(&self, target_view: &str, source_view: &str) -> RemoteResult<u64> {
267 let url = format!(
268 "{}?fork_from={}&view={}",
269 self.base_url, source_view, target_view
270 );
271 debug!("POST fork: {}", url);
272
273 let response = self
274 .client
275 .post(&url)
276 .send()
277 .await
278 .map_err(|e| RemoteError::connection_failed(&url, e))?;
279
280 crate::check_min_version_header(response.headers());
281 let status = response.status();
282
283 match status {
284 StatusCode::OK => {
285 let text = response
286 .text()
287 .await
288 .map_err(|e| RemoteError::connection_failed(&url, e))?;
289
290 // Parse the JSON response to extract the change count
291 let parsed: serde_json::Value = serde_json::from_str(&text)
292 .map_err(|e| RemoteError::protocol(format!("Invalid fork response: {}", e)))?;
293
294 let changes = parsed.get("changes").and_then(|v| v.as_u64()).unwrap_or(0);
295
296 debug!(
297 "Forked view '{}' from '{}' ({} changes)",
298 target_view, source_view, changes
299 );
300
301 Ok(changes)
302 }
303 StatusCode::BAD_REQUEST => {
304 let msg = response.text().await.unwrap_or_default();
305 Err(RemoteError::protocol(msg))
306 }
307 StatusCode::NOT_FOUND => Err(RemoteError::view_not_found(source_view)),
308 StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => {
309 let msg = response.text().await.unwrap_or_default();
310 Err(RemoteError::auth_failed(&url, msg))
311 }
312 _ => {
313 let msg = response.text().await.unwrap_or_default();
314 Err(RemoteError::http(status.as_u16(), msg))
315 }
316 }
317 }
318
319 /// Upload an attestation to the remote server.
320 ///

Callers

nothing calls this directly

Calls 6

check_min_version_headerFunction · 0.85
postMethod · 0.80
textMethod · 0.80
as_u64Method · 0.80
getMethod · 0.65
statusMethod · 0.45

Tested by

no test coverage detected