| 9336 | } |
| 9337 | |
| 9338 | fn parse_diff_files_via_git_cli( |
| 9339 | git_repo: &GitRepository, |
| 9340 | commit_oid: Oid, |
| 9341 | parent_oid: Oid, |
| 9342 | tree: &Tree<'_>, |
| 9343 | parent_tree: &Tree<'_>, |
| 9344 | ) -> CliResult<Vec<ParsedFile>> { |
| 9345 | let output = Command::new("git") |
| 9346 | // The caller may run alongside another thread that changes or removes |
| 9347 | // the process cwd. Git resolves cwd even with --git-dir; anchor the |
| 9348 | // child to this live repository instead of inheriting that global state. |
| 9349 | .current_dir(git_repo.path()) |
| 9350 | .arg("--git-dir") |
| 9351 | .arg(git_repo.path()) |
| 9352 | .arg("diff-tree") |
| 9353 | .arg("-r") |
| 9354 | .arg("--name-status") |
| 9355 | .arg("-z") |
| 9356 | .arg("-M") |
| 9357 | .arg(parent_oid.to_string()) |
| 9358 | .arg(commit_oid.to_string()) |
| 9359 | .output() |
| 9360 | .map_err(|e| CliError::GitError { |
| 9361 | message: format!("Failed to run git diff-tree fallback: {}", e), |
| 9362 | })?; |
| 9363 | |
| 9364 | if !output.status.success() { |
| 9365 | return Err(CliError::GitError { |
| 9366 | message: format!( |
| 9367 | "git diff-tree fallback failed: {}", |
| 9368 | String::from_utf8_lossy(&output.stderr).trim() |
| 9369 | ), |
| 9370 | }); |
| 9371 | } |
| 9372 | |
| 9373 | let mut files = Vec::new(); |
| 9374 | // NUL framing preserves tabs, newlines, non-UTF-8 bytes, and literal '%'. |
| 9375 | // Never parse Git's display quoting as a repository path. |
| 9376 | let mut fields = output.stdout.split(|byte| *byte == 0); |
| 9377 | while let Some(status) = fields.next() { |
| 9378 | if status.is_empty() { |
| 9379 | break; |
| 9380 | } |
| 9381 | let kind = status[0]; |
| 9382 | let source = fields |
| 9383 | .next() |
| 9384 | .filter(|path| !path.is_empty()) |
| 9385 | .ok_or_else(|| git_error("missing path in git diff-tree output"))?; |
| 9386 | let old_path = |
| 9387 | matches!(kind, b'R' | b'C').then(|| atomic_repository::escape_repo_path(source)); |
| 9388 | let raw_path = if old_path.is_some() { |
| 9389 | fields |
| 9390 | .next() |
| 9391 | .filter(|path| !path.is_empty()) |
| 9392 | .ok_or_else(|| git_error("missing destination in git diff-tree output"))? |
| 9393 | } else { |
| 9394 | source |
| 9395 | }; |