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)
| 1321 | /// Normalize a tracked path from the TREE table to a relative PathBuf |
| 1322 | /// with forward slashes, handling absolute paths and platform differences. |
| 1323 | fn 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. |
no test coverage detected