(
repo: &Repository,
before: &Tree,
after: &Tree,
stage: bool,
)
| 438 | } |
| 439 | |
| 440 | fn write_tree( |
| 441 | repo: &Repository, |
| 442 | before: &Tree, |
| 443 | after: &Tree, |
| 444 | stage: bool, |
| 445 | ) -> Result<(), RepositoryError> { |
| 446 | let wc = repo.require_working_copy_id()?; |
| 447 | let mut removed: Vec<_> = before.values().collect(); |
| 448 | removed.sort_by_key(|file| std::cmp::Reverse(file.path.len())); |
| 449 | for file in removed { |
| 450 | let path = file_path(repo.root(), &file.path)?; |
| 451 | if fs::symlink_metadata(&path).is_ok() { |
| 452 | if file.kind == ViewEntryKind::Directory { |
| 453 | fs::remove_dir(path)?; |
| 454 | } else { |
| 455 | fs::remove_file(path)?; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | for file in after.values() { |
| 460 | let path = file_path(repo.root(), &file.path)?; |
| 461 | fs::create_dir_all(path.parent().unwrap())?; |
| 462 | if file.kind == ViewEntryKind::Directory { |
| 463 | fs::create_dir_all(&path)?; |
| 464 | } else if file.kind == ViewEntryKind::Symlink { |
| 465 | #[cfg(unix)] |
| 466 | { |
| 467 | use std::os::unix::ffi::OsStringExt; |
| 468 | std::os::unix::fs::symlink( |
| 469 | std::ffi::OsString::from_vec(file.bytes.clone()), |
| 470 | &path, |
| 471 | )?; |
| 472 | } |
| 473 | #[cfg(not(unix))] |
| 474 | { |
| 475 | return Err(invalid("symlink revision is unsupported on this platform")); |
| 476 | } |
| 477 | } else { |
| 478 | fs::write(&path, &file.bytes)?; |
| 479 | #[cfg(unix)] |
| 480 | { |
| 481 | use std::os::unix::fs::PermissionsExt; |
| 482 | fs::set_permissions(&path, fs::Permissions::from_mode(file.mode.into()))?; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | // Attribute files must all exist before converting canonical bytes back |
| 487 | // to recorder input, including nested .gitattributes and Git driver policy. |
| 488 | let filter = GitAttributesFilter::for_repository(repo.root()); |
| 489 | for file in after |
| 490 | .values() |
| 491 | .filter(|file| file.kind == ViewEntryKind::File) |
| 492 | { |
| 493 | let bytes = filter |
| 494 | .smudge(Path::new(&file.path), &file.bytes) |
| 495 | .map_err(|e| invalid(e.to_string()))? |
| 496 | .bytes; |
| 497 | fs::write(file_path(repo.root(), &file.path)?, bytes)?; |
no test coverage detected