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

Function normalize_tracked_path

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

671/// Normalize a tracked path from the TREE table to a relative PathBuf
672/// with forward slashes, handling absolute paths and platform differences.
673fn normalize_tracked_path(path: &str, repo_root: &Path) -> PathBuf {
674 let path_buf = PathBuf::from(path);
675
676 let stripped = if path_buf.is_absolute() {
677 if let Ok(rel) = path_buf.strip_prefix(repo_root) {
678 rel.to_path_buf()
679 } else if let Ok(canonical_root) = repo_root.canonicalize() {
680 if let Ok(rel) = path_buf.strip_prefix(&canonical_root) {
681 rel.to_path_buf()
682 } else {
683 path_buf
684 }
685 } else {
686 path_buf
687 }
688 } else {
689 path_buf
690 };
691
692 // Normalize to forward slashes for cross-platform consistency
693 if cfg!(windows) || stripped.to_string_lossy().contains('\\') {
694 PathBuf::from(stripped.to_string_lossy().replace('\\', "/"))
695 } else {
696 stripped
697 }
698}

Callers 1

statusMethod · 0.85

Calls 2

containsMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected