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

Function normalize_tracked_path

atomic-repository/src/repository/status.rs:722–747  ·  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

720/// Normalize a tracked path from the TREE table to a relative PathBuf
721/// with forward slashes, handling absolute paths and platform differences.
722fn normalize_tracked_path(path: &str, repo_root: &Path) -> PathBuf {
723 let path_buf = PathBuf::from(path);
724
725 let stripped = if path_buf.is_absolute() {
726 if let Ok(rel) = path_buf.strip_prefix(repo_root) {
727 rel.to_path_buf()
728 } else if let Ok(canonical_root) = repo_root.canonicalize() {
729 if let Ok(rel) = path_buf.strip_prefix(&canonical_root) {
730 rel.to_path_buf()
731 } else {
732 path_buf
733 }
734 } else {
735 path_buf
736 }
737 } else {
738 path_buf
739 };
740
741 // Normalize to forward slashes for cross-platform consistency
742 if cfg!(windows) || stripped.to_string_lossy().contains('\\') {
743 PathBuf::from(stripped.to_string_lossy().replace('\\', "/"))
744 } else {
745 stripped
746 }
747}

Callers 1

status_innerMethod · 0.85

Calls 2

containsMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected