The paths `commit` changed relative to `parent`, or `None` when Git cannot say. Renames are reported as a delete plus an add, the way a turn sees them.
(repo_root: &Path, parent: &str, commit: &str)
| 966 | /// The paths `commit` changed relative to `parent`, or `None` when Git cannot |
| 967 | /// say. Renames are reported as a delete plus an add, the way a turn sees them. |
| 968 | fn commit_changed_paths(repo_root: &Path, parent: &str, commit: &str) -> Option<Vec<CommitPath>> { |
| 969 | let output = std::process::Command::new("git") |
| 970 | .args(["diff", "--raw", "--no-renames", "--no-abbrev", "-z"]) |
| 971 | .args([parent, commit]) |
| 972 | .current_dir(repo_root) |
| 973 | .output() |
| 974 | .ok()?; |
| 975 | if !output.status.success() { |
| 976 | return None; |
| 977 | } |
| 978 | // `-z` records: ":<old mode> <new mode> <old oid> <new oid> <status>\0<path>\0". |
| 979 | let stdout = String::from_utf8_lossy(&output.stdout).into_owned(); |
| 980 | let mut fields = stdout.split('\0').filter(|field| !field.is_empty()); |
| 981 | let mut paths = Vec::new(); |
| 982 | while let Some(meta) = fields.next() { |
| 983 | let mut meta = meta.strip_prefix(':')?.split(' '); |
| 984 | let (old_mode, new_mode) = (meta.next()?, meta.next()?); |
| 985 | paths.push(CommitPath { |
| 986 | path: fields.next()?.to_string(), |
| 987 | old_mode: old_mode.to_string(), |
| 988 | new_mode: new_mode.to_string(), |
| 989 | }); |
| 990 | } |
| 991 | Some(paths) |
| 992 | } |
| 993 | |
| 994 | /// The path where a commit puts a directory in place of a file, or a file |
| 995 | /// in place of a directory, if it does. |
no test coverage detected