Byte snapshot of the working tree (excluding .git/.atomic), order- independent: (relative path, bytes) pairs hashed by serialization.
(root: &Path)
| 473 | /// Byte snapshot of the working tree (excluding .git/.atomic), order- |
| 474 | /// independent: (relative path, bytes) pairs hashed by serialization. |
| 475 | fn worktree_bytes(root: &Path) -> u64 { |
| 476 | let mut snapshot: Vec<(String, Vec<u8>)> = Vec::new(); |
| 477 | let mut stack = vec![root.to_path_buf()]; |
| 478 | while let Some(directory) = stack.pop() { |
| 479 | for entry in fs::read_dir(&directory).expect("read dir").flatten() { |
| 480 | let path = entry.path(); |
| 481 | let name = path.file_name().and_then(|name| name.to_str()); |
| 482 | if name == Some(".git") || name == Some(".atomic") { |
| 483 | continue; |
| 484 | } |
| 485 | if path.is_dir() { |
| 486 | stack.push(path); |
| 487 | } else if let Ok(bytes) = fs::read(&path) { |
| 488 | snapshot.push(( |
| 489 | path.strip_prefix(root) |
| 490 | .expect("relative path") |
| 491 | .display() |
| 492 | .to_string(), |
| 493 | bytes, |
| 494 | )); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | snapshot.sort(); |
| 499 | let mut hasher = std::collections::hash_map::DefaultHasher::new(); |
| 500 | use std::hash::Hasher; |
| 501 | for (path, bytes) in snapshot { |
| 502 | hasher.write(path.as_bytes()); |
| 503 | hasher.write(&bytes); |
| 504 | } |
| 505 | hasher.finish() |
| 506 | } |
| 507 | |
| 508 | /// Replace base32-looking runs of >= 32 chars with `<state>` (mirrors the |
| 509 | /// CB-13D harness normalization: per-repository change identities are not |