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

Function load_change_data

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

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