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

Function load_change_data

atomic-cli/src/commands/push/helpers.rs:307–339  ·  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

305/// Returns `CliError::ChangeNotFound` if the change doesn't exist,
306/// or `CliError::Internal` if serialization fails.
307pub fn load_change_data(repo: &Repository, hash: &Hash) -> CliResult<Bytes> {
308 // Read the raw V3 change file from disk instead of deserializing and
309 // re-serializing. This is faster, uses less memory, and — critically —
310 // preserves the exact bytes that produced the content hash. Re-serializing
311 // can produce different bytes (field ordering, padding) which would break
312 // hash verification on the server.
313 let change_path = repo.change_store().change_path(hash);
314 if change_path.exists() {
315 let data = std::fs::read(&change_path).map_err(|e| {
316 CliError::Internal(anyhow::anyhow!(
317 "Failed to read change file {:?}: {}",
318 change_path,
319 e
320 ))
321 })?;
322 return Ok(Bytes::from(data));
323 }
324
325 // Fallback: deserialize + re-serialize (legacy path for changes
326 // whose on-disk file was cleaned up or doesn't exist).
327 let change = repo
328 .load_change(hash)
329 .map_err(|_| CliError::ChangeNotFound {
330 hash: hash.to_base32(),
331 })?;
332
333 let mut buffer = Vec::new();
334 change
335 .serialize(&mut buffer)
336 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to serialize change: {}", e)))?;
337
338 Ok(Bytes::from(buffer))
339}
340
341/// Load the message from a change, returning None if it fails.
342pub 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