Collect HEAD tree blob entries recursively into `path -> (bytes, mode)`.
(
repository: &git2::Repository,
tree: &git2::Tree<'_>,
#[allow(clippy::ptr_arg)] // recursive tree walker shares the Vec
prefix: &mut Vec<u8>,
output: &mut std::collections::BTree
| 447 | |
| 448 | /// Collect HEAD tree blob entries recursively into `path -> (bytes, mode)`. |
| 449 | fn collect_baseline_blobs( |
| 450 | repository: &git2::Repository, |
| 451 | tree: &git2::Tree<'_>, |
| 452 | #[allow(clippy::ptr_arg)] // recursive tree walker shares the Vec |
| 453 | prefix: &mut Vec<u8>, |
| 454 | output: &mut std::collections::BTreeMap<String, (Vec<u8>, u32)>, |
| 455 | ) -> CliResult<()> { |
| 456 | for entry in tree.iter() { |
| 457 | let mut path = prefix.clone(); |
| 458 | if !path.is_empty() { |
| 459 | path.push(b'/'); |
| 460 | } |
| 461 | path.extend_from_slice(entry.name_bytes()); |
| 462 | if entry.kind() == Some(git2::ObjectType::Tree) { |
| 463 | let child = repository |
| 464 | .find_tree(entry.id()) |
| 465 | .map_err(|error| CliError::GitError { |
| 466 | message: format!("cannot read subtree {}: {error}", entry.id()), |
| 467 | })?; |
| 468 | collect_baseline_blobs(repository, &child, &mut path, output)?; |
| 469 | } else { |
| 470 | let content = if entry.kind() == Some(git2::ObjectType::Blob) { |
| 471 | repository |
| 472 | .find_blob(entry.id()) |
| 473 | .map(|blob| blob.content().to_vec()) |
| 474 | .unwrap_or_default() |
| 475 | } else { |
| 476 | Vec::new() |
| 477 | }; |
| 478 | output.insert( |
| 479 | String::from_utf8_lossy(&path).into_owned(), |
| 480 | (content, entry.filemode() as u32), |
| 481 | ); |
| 482 | } |
| 483 | } |
| 484 | Ok(()) |
| 485 | } |
| 486 | |
| 487 | /// Build one file diff between two layer byte-sets. |
| 488 | fn build_layer_file_diff( |