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)
| 671 | /// Normalize a tracked path from the TREE table to a relative PathBuf |
| 672 | /// with forward slashes, handling absolute paths and platform differences. |
| 673 | fn 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 | } |