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

Function normalize_tracked_path

atomic-repository/src/repository/status.rs:586–611  ·  view source on GitHub ↗

Normalize a tracked path from the TREE table to a relative PathBuf with forward slashes, handling absolute paths and platform differences.

(path: &str, repo_root: &Path)

Source from the content-addressed store, hash-verified

584/// Normalize a tracked path from the TREE table to a relative PathBuf
585/// with forward slashes, handling absolute paths and platform differences.
586fn normalize_tracked_path(path: &str, repo_root: &Path) -> PathBuf {
587 let path_buf = PathBuf::from(path);
588
589 let stripped = if path_buf.is_absolute() {
590 if let Ok(rel) = path_buf.strip_prefix(repo_root) {
591 rel.to_path_buf()
592 } else if let Ok(canonical_root) = repo_root.canonicalize() {
593 if let Ok(rel) = path_buf.strip_prefix(&canonical_root) {
594 rel.to_path_buf()
595 } else {
596 path_buf
597 }
598 } else {
599 path_buf
600 }
601 } else {
602 path_buf
603 };
604
605 // Normalize to forward slashes for cross-platform consistency
606 if cfg!(windows) || stripped.to_string_lossy().contains('\\') {
607 PathBuf::from(stripped.to_string_lossy().replace('\\', "/"))
608 } else {
609 stripped
610 }
611}

Callers 1

statusMethod · 0.85

Calls 2

containsMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected