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)
| 170 | /// Returns `CliError::ChangeNotFound` if the change doesn't exist, |
| 171 | /// or `CliError::Internal` if serialization fails. |
| 172 | pub 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 |
no test coverage detected