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

Function load_change_data

atomic-cli/src/commands/push/helpers.rs:361–393  ·  view source on GitHub ↗

Load and serialize change data from the repository. Loads the change from the repository and serializes it to bytes suitable for uploading to a remote. # Errors Returns `CliError::ChangeNotFound` if the change doesn't exist, or `CliError::Internal` if serialization fails.

(repo: &Repository, hash: &Hash)

Source from the content-addressed store, hash-verified

359/// Returns `CliError::ChangeNotFound` if the change doesn't exist,
360/// or `CliError::Internal` if serialization fails.
361pub fn load_change_data(repo: &Repository, hash: &Hash) -> CliResult<Bytes> {
362 // Read the raw V3 change file from disk instead of deserializing and
363 // re-serializing. This is faster, uses less memory, and — critically —
364 // preserves the exact bytes that produced the content hash. Re-serializing
365 // can produce different bytes (field ordering, padding) which would break
366 // hash verification on the server.
367 let change_path = repo.change_store().change_path(hash);
368 if change_path.exists() {
369 let data = std::fs::read(&change_path).map_err(|e| {
370 CliError::Internal(anyhow::anyhow!(
371 "Failed to read change file {:?}: {}",
372 change_path,
373 e
374 ))
375 })?;
376 return Ok(Bytes::from(data));
377 }
378
379 // Fallback: deserialize + re-serialize (legacy path for changes
380 // whose on-disk file was cleaned up or doesn't exist).
381 let change = repo
382 .load_change(hash)
383 .map_err(|_| CliError::ChangeNotFound {
384 hash: hash.to_base32(),
385 })?;
386
387 let mut buffer = Vec::new();
388 change
389 .serialize(&mut buffer)
390 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to serialize change: {}", e)))?;
391
392 Ok(Bytes::from(buffer))
393}
394
395/// Load the message from a change, returning None if it fails.
396pub fn load_change_message(repo: &Repository, hash: &Hash) -> Option<String> {

Callers 1

run_asyncMethod · 0.85

Calls 6

change_pathMethod · 0.45
change_storeMethod · 0.45
existsMethod · 0.45
load_changeMethod · 0.45
to_base32Method · 0.45
serializeMethod · 0.45

Tested by

no test coverage detected