MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / worktree_bytes

Function worktree_bytes

atomic-cli/tests/it/import_budget_100k_bench.rs:475–506  ·  view source on GitHub ↗

Byte snapshot of the working tree (excluding .git/.atomic), order- independent: (relative path, bytes) pairs hashed by serialization.

(root: &Path)

Source from the content-addressed store, hash-verified

473/// Byte snapshot of the working tree (excluding .git/.atomic), order-
474/// independent: (relative path, bytes) pairs hashed by serialization.
475fn 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

Callers

nothing calls this directly

Calls 10

is_dirMethod · 0.80
displayMethod · 0.80
sortMethod · 0.80
readFunction · 0.70
pathMethod · 0.45
file_nameMethod · 0.45
pushMethod · 0.45
writeMethod · 0.45
as_bytesMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected