MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / parse_diff_files_via_git_cli

Function parse_diff_files_via_git_cli

atomic-cli/src/commands/git/parallel.rs:4036–4146  ·  view source on GitHub ↗
(
    git_repo: &GitRepository,
    commit_oid: Oid,
    parent_oid: Oid,
    tree: &Tree<'_>,
    parent_tree: &Tree<'_>,
)

Source from the content-addressed store, hash-verified

4034}
4035
4036fn parse_diff_files_via_git_cli(
4037 git_repo: &GitRepository,
4038 commit_oid: Oid,
4039 parent_oid: Oid,
4040 tree: &Tree<'_>,
4041 parent_tree: &Tree<'_>,
4042) -> CliResult<Vec<ParsedFile>> {
4043 let repo_root = git_repo.path().parent().ok_or_else(|| CliError::GitError {
4044 message: "Failed to locate git repository root".to_string(),
4045 })?;
4046
4047 let output = Command::new("git")
4048 .arg("-C")
4049 .arg(repo_root)
4050 .arg("diff-tree")
4051 .arg("-r")
4052 .arg("--name-status")
4053 .arg("-M")
4054 .arg(parent_oid.to_string())
4055 .arg(commit_oid.to_string())
4056 .output()
4057 .map_err(|e| CliError::GitError {
4058 message: format!("Failed to run git diff-tree fallback: {}", e),
4059 })?;
4060
4061 if !output.status.success() {
4062 return Err(CliError::GitError {
4063 message: format!(
4064 "git diff-tree fallback failed: {}",
4065 String::from_utf8_lossy(&output.stderr).trim()
4066 ),
4067 });
4068 }
4069
4070 let mut files = Vec::new();
4071 for line in String::from_utf8_lossy(&output.stdout).lines() {
4072 if line.is_empty() {
4073 continue;
4074 }
4075 let mut parts = line.split('\t');
4076 let status = parts.next().unwrap_or_default();
4077 let Some(kind) = status.chars().next() else {
4078 continue;
4079 };
4080
4081 match kind {
4082 'A' => {
4083 let Some(path) = parts.next() else { continue };
4084 files.push(ParsedFile {
4085 path: path.to_string(),
4086 operation: FileOperation::Added,
4087 new_content: get_file_content(git_repo, tree, path).ok(),
4088 old_content: None,
4089 diff_lines: None,
4090 old_path: None,
4091 });
4092 }
4093 'M' => {

Callers 1

parse_commitFunction · 0.85

Calls 8

get_file_contentFunction · 0.85
parentMethod · 0.80
successMethod · 0.80
pathMethod · 0.45
linesMethod · 0.45
is_emptyMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected