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

Function normalize_tracked_path

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

1321/// Normalize a tracked path from the TREE table to a relative PathBuf
1322/// with forward slashes, handling absolute paths and platform differences.
1323fn normalize_tracked_path(path: &str, repo_root: &Path) -> PathBuf {
1324 let path_buf = PathBuf::from(path);
1325
1326 let stripped = if path_buf.is_absolute() {
1327 if let Ok(rel) = path_buf.strip_prefix(repo_root) {
1328 rel.to_path_buf()
1329 } else if let Ok(canonical_root) = repo_root.canonicalize() {
1330 if let Ok(rel) = path_buf.strip_prefix(&canonical_root) {
1331 rel.to_path_buf()
1332 } else {
1333 path_buf
1334 }
1335 } else {
1336 path_buf
1337 }
1338 } else {
1339 path_buf
1340 };
1341
1342 // Normalize to forward slashes for cross-platform consistency
1343 if cfg!(windows) || stripped.to_string_lossy().contains('\\') {
1344 PathBuf::from(stripped.to_string_lossy().replace('\\', "/"))
1345 } else {
1346 stripped
1347 }
1348}
1349
1350// Decode only at the filesystem boundary; callers retain stored keys for
1351// graph lookup and status entries. Reject decoded traversal/absolute paths.

Callers 1

status_innerMethod · 0.85

Calls 3

canonicalizeMethod · 0.80
containsMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected