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

Function normalize_tracked_path

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

553/// Normalize a tracked path from the TREE table to a relative PathBuf
554/// with forward slashes, handling absolute paths and platform differences.
555fn normalize_tracked_path(path: &str, repo_root: &Path) -> PathBuf {
556 let path_buf = PathBuf::from(path);
557
558 let stripped = if path_buf.is_absolute() {
559 if let Ok(rel) = path_buf.strip_prefix(repo_root) {
560 rel.to_path_buf()
561 } else if let Ok(canonical_root) = repo_root.canonicalize() {
562 if let Ok(rel) = path_buf.strip_prefix(&canonical_root) {
563 rel.to_path_buf()
564 } else {
565 path_buf
566 }
567 } else {
568 path_buf
569 }
570 } else {
571 path_buf
572 };
573
574 // Normalize to forward slashes for cross-platform consistency
575 if cfg!(windows) || stripped.to_string_lossy().contains('\\') {
576 PathBuf::from(stripped.to_string_lossy().replace('\\', "/"))
577 } else {
578 stripped
579 }
580}

Callers 1

statusMethod · 0.85

Calls 2

containsMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected