Create one view locally and populate it from its remote changelist. Returns the number of changes inserted into the view.
(
&self,
repo: &mut Repository,
remote: &HttpRemote,
view_name: &str,
stats: &mut CloneStats,
)
| 362 | /// |
| 363 | /// Returns the number of changes inserted into the view. |
| 364 | async fn clone_one_view( |
| 365 | &self, |
| 366 | repo: &mut Repository, |
| 367 | remote: &HttpRemote, |
| 368 | view_name: &str, |
| 369 | stats: &mut CloneStats, |
| 370 | ) -> CliResult<usize> { |
| 371 | if !repo.view_exists(view_name).map_err(CliError::Repository)? { |
| 372 | repo.create_shared_view(view_name) |
| 373 | .map_err(CliError::Repository)?; |
| 374 | } |
| 375 | |
| 376 | let entries = remote |
| 377 | .get_changelist(view_name, 0) |
| 378 | .await |
| 379 | .map_err(|e| convert_remote_error(e, &self.url))?; |
| 380 | |
| 381 | let mut applied = 0usize; |
| 382 | for entry in &entries { |
| 383 | let Some(hash) = atomic_core::types::Hash::from_base32(entry.hash.as_bytes()) else { |
| 384 | continue; |
| 385 | }; |
| 386 | |
| 387 | // Reuse content already present locally; fetch only what's missing. |
| 388 | if !repo.has_change(&hash) { |
| 389 | let data = remote |
| 390 | .download_change(&entry.hash) |
| 391 | .await |
| 392 | .map_err(|e| convert_remote_error(e, &self.url))?; |
| 393 | let len = data.len() as u64; |
| 394 | save_downloaded_change(&*repo, &hash, data).map_err(|e| { |
| 395 | CliError::Internal(anyhow::anyhow!("save change {}: {}", entry.hash, e)) |
| 396 | })?; |
| 397 | stats.record_change_downloaded(len); |
| 398 | } |
| 399 | |
| 400 | // Insert the change (and its dependency closure) into this view. |
| 401 | // Changes arrive in dependency order, so deps are already present. |
| 402 | let opts = atomic_repository::InsertOptions::default() |
| 403 | .apply_deps(true) |
| 404 | .view(view_name); |
| 405 | match repo.insert_change_rec(&hash, opts) { |
| 406 | Ok(_) => applied += 1, |
| 407 | Err(e) => { |
| 408 | let msg = e.to_string(); |
| 409 | if msg.contains("already applied") || msg.contains("AlreadyApplied") { |
| 410 | applied += 1; |
| 411 | } else { |
| 412 | return Err(CliError::Internal(anyhow::anyhow!( |
| 413 | "insert {} into '{}': {}", |
| 414 | entry.hash, |
| 415 | view_name, |
| 416 | e |
| 417 | ))); |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
no test coverage detected