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

Function load_change_data

atomic-cli/src/commands/push/helpers.rs:172–204  ·  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. # Arguments `repo` - The repository to load from `hash` - The hash of the change to load # Returns The serialized change data as bytes. # Errors Returns `CliError::ChangeNotFound` if the change doesn't exist, or `CliError::Internal` if seria

(repo: &Repository, hash: &Hash)

Source from the content-addressed store, hash-verified

170/// Returns `CliError::ChangeNotFound` if the change doesn't exist,
171/// or `CliError::Internal` if serialization fails.
172pub fn load_change_data(repo: &Repository, hash: &Hash) -> CliResult<Bytes> {
173 // Read the raw V3 change file from disk instead of deserializing and
174 // re-serializing. This is faster, uses less memory, and — critically —
175 // preserves the exact bytes that produced the content hash. Re-serializing
176 // can produce different bytes (field ordering, padding) which would break
177 // hash verification on the server.
178 let change_path = repo.change_store().change_path(hash);
179 if change_path.exists() {
180 let data = std::fs::read(&change_path).map_err(|e| {
181 CliError::Internal(anyhow::anyhow!(
182 "Failed to read change file {:?}: {}",
183 change_path,
184 e
185 ))
186 })?;
187 return Ok(Bytes::from(data));
188 }
189
190 // Fallback: deserialize + re-serialize (legacy path for changes
191 // whose on-disk file was cleaned up or doesn't exist).
192 let change = repo
193 .load_change(hash)
194 .map_err(|_| CliError::ChangeNotFound {
195 hash: hash.to_base32(),
196 })?;
197
198 let mut buffer = Vec::new();
199 change
200 .serialize(&mut buffer)
201 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to serialize change: {}", e)))?;
202
203 Ok(Bytes::from(buffer))
204}
205
206// Delta Transfer Protocol
207

Callers 1

upload_change_smartFunction · 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