Upload a single change using the threshold-gated delta transfer protocol. - Changes smaller than [`DELTA_TRANSFER_THRESHOLD`]: sent directly (fast path) - Changes larger: manifest exchange → send only missing chunks (delta path) # Arguments `remote` - The HTTP remote to push to. `repo` - The local repository. `hash` - The change hash. `stack` - The target stack name on the remote. # Returns A
(
remote: &atomic_remote::HttpRemote,
repo: &Repository,
hash: &Hash,
stack: &str,
)
| 284 | /// |
| 285 | /// A [`PushTransferResult`] describing the transfer, or an error. |
| 286 | pub async fn upload_change_smart( |
| 287 | remote: &atomic_remote::HttpRemote, |
| 288 | repo: &Repository, |
| 289 | hash: &Hash, |
| 290 | stack: &str, |
| 291 | ) -> CliResult<PushTransferResult> { |
| 292 | let change_data = load_change_data(repo, hash)?; |
| 293 | let data_len = change_data.len(); |
| 294 | let hash_str = hash.to_base32(); |
| 295 | |
| 296 | if data_len < DELTA_TRANSFER_THRESHOLD { |
| 297 | // FAST PATH: small change — send directly, no negotiation. |
| 298 | // This covers 99% of source code changes. |
| 299 | remote |
| 300 | .upload_change(&hash_str, stack, change_data) |
| 301 | .await |
| 302 | .map_err(|e| convert_remote_error(e, &remote.url().to_string()))?; |
| 303 | |
| 304 | Ok(PushTransferResult::direct(data_len as u64)) |
| 305 | } else { |
| 306 | // LARGE PATH: try delta transfer — negotiate chunks first. |
| 307 | // |
| 308 | // 1. Ask server for chunk manifest support |
| 309 | // 2. If supported: send our manifest, get back "need" list, send only missing chunks |
| 310 | // 3. If not supported: fall back to direct send |
| 311 | let manifest_result = remote.get_chunk_manifest(&hash_str).await; |
| 312 | |
| 313 | match manifest_result { |
| 314 | Ok(Some(_server_manifest)) => { |
| 315 | // Server supports manifests and returned one for a prior version |
| 316 | // of this content. But wait — we're pushing a NEW change, not |
| 317 | // updating an existing one. The manifest endpoint returns chunks |
| 318 | // for an existing change hash on the server. |
| 319 | // |
| 320 | // For delta to work, we'd need to: |
| 321 | // 1. Push our manifest (our chunk hashes) to the server |
| 322 | // 2. Server checks which of our chunks it already has in CONTENT_CHUNKS |
| 323 | // 3. Server tells us which chunks to send |
| 324 | // |
| 325 | // The current ?manifest endpoint returns the SERVER's manifest for |
| 326 | // a hash, not a negotiation. For now, fall back to direct send. |
| 327 | // The delta protocol needs a dedicated negotiation endpoint. |
| 328 | // |
| 329 | // TODO: Implement POST ?negotiate_chunks with our manifest body |
| 330 | // Server responds with { "need": [indices] } |
| 331 | remote |
| 332 | .upload_change(&hash_str, stack, change_data) |
| 333 | .await |
| 334 | .map_err(|e| convert_remote_error(e, &remote.url().to_string()))?; |
| 335 | |
| 336 | Ok(PushTransferResult::direct(data_len as u64)) |
| 337 | } |
| 338 | Ok(None) | Err(_) => { |
| 339 | // Server doesn't support manifests or error — direct send. |
| 340 | remote |
| 341 | .upload_change(&hash_str, stack, change_data) |
| 342 | .await |
| 343 | .map_err(|e| convert_remote_error(e, &remote.url().to_string()))?; |
nothing calls this directly
no test coverage detected