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,
)
| 338 | /// |
| 339 | /// A [`PushTransferResult`] describing the transfer, or an error. |
| 340 | pub async fn upload_change_smart( |
| 341 | remote: &atomic_remote::HttpRemote, |
| 342 | repo: &Repository, |
| 343 | hash: &Hash, |
| 344 | stack: &str, |
| 345 | ) -> CliResult<PushTransferResult> { |
| 346 | let change_data = load_change_data(repo, hash)?; |
| 347 | let data_len = change_data.len(); |
| 348 | let hash_str = hash.to_base32(); |
| 349 | |
| 350 | if data_len < DELTA_TRANSFER_THRESHOLD { |
| 351 | // FAST PATH: small change — send directly, no negotiation. |
| 352 | // This covers 99% of source code changes. |
| 353 | remote |
| 354 | .upload_change(&hash_str, stack, change_data) |
| 355 | .await |
| 356 | .map_err(|e| convert_remote_error(e, &remote.url().to_string()))?; |
| 357 | |
| 358 | Ok(PushTransferResult::direct(data_len as u64)) |
| 359 | } else { |
| 360 | // LARGE PATH: try delta transfer — negotiate chunks first. |
| 361 | // |
| 362 | // 1. Ask server for chunk manifest support |
| 363 | // 2. If supported: send our manifest, get back "need" list, send only missing chunks |
| 364 | // 3. If not supported: fall back to direct send |
| 365 | let manifest_result = remote.get_chunk_manifest(&hash_str).await; |
| 366 | |
| 367 | match manifest_result { |
| 368 | Ok(Some(_server_manifest)) => { |
| 369 | // Server supports manifests and returned one for a prior version |
| 370 | // of this content. But wait — we're pushing a NEW change, not |
| 371 | // updating an existing one. The manifest endpoint returns chunks |
| 372 | // for an existing change hash on the server. |
| 373 | // |
| 374 | // For delta to work, we'd need to: |
| 375 | // 1. Push our manifest (our chunk hashes) to the server |
| 376 | // 2. Server checks which of our chunks it already has in CONTENT_CHUNKS |
| 377 | // 3. Server tells us which chunks to send |
| 378 | // |
| 379 | // The current ?manifest endpoint returns the SERVER's manifest for |
| 380 | // a hash, not a negotiation. For now, fall back to direct send. |
| 381 | // The delta protocol needs a dedicated negotiation endpoint. |
| 382 | // |
| 383 | // TODO: Implement POST ?negotiate_chunks with our manifest body |
| 384 | // Server responds with { "need": [indices] } |
| 385 | remote |
| 386 | .upload_change(&hash_str, stack, change_data) |
| 387 | .await |
| 388 | .map_err(|e| convert_remote_error(e, &remote.url().to_string()))?; |
| 389 | |
| 390 | Ok(PushTransferResult::direct(data_len as u64)) |
| 391 | } |
| 392 | Ok(None) | Err(_) => { |
| 393 | // Server doesn't support manifests or error — direct send. |
| 394 | remote |
| 395 | .upload_change(&hash_str, stack, change_data) |
| 396 | .await |
| 397 | .map_err(|e| convert_remote_error(e, &remote.url().to_string()))?; |
nothing calls this directly
no test coverage detected