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