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

Function parse_diff_files

atomic-cli/src/commands/git/parallel.rs:8959–9176  ·  view source on GitHub ↗

Parse files from a git diff. For each changed file we capture: - The operation type (Added / Modified / Deleted / Renamed / Copied) - The new file content (for adds/modifies) - The old file content (for modifies/deletes) - The exact diff lines that git computed, so Phase 2 can build BranchOps directly from git's diff rather than re-diffing.

(
    git_repo: &GitRepository,
    diff: &Diff,
    tree: &Tree,
    parent_tree: Option<&Tree>,
    capture_diff_lines: bool,
)

Source from the content-addressed store, hash-verified

8957/// - The exact diff lines that git computed, so Phase 2 can build
8958/// BranchOps directly from git's diff rather than re-diffing.
8959fn parse_diff_files(
8960 git_repo: &GitRepository,
8961 diff: &Diff,
8962 tree: &Tree,
8963 parent_tree: Option<&Tree>,
8964 capture_diff_lines: bool,
8965) -> CliResult<Vec<ParsedFile>> {
8966 use std::collections::HashMap;
8967
8968 // ── Step 1: collect per-file diff lines via diff.foreach ────────────
8969 //
8970 // git2::Diff::foreach gives us each DiffLine with its origin (`+`/`-`/` `),
8971 // raw bytes, and old/new line numbers — exactly what `git diff` outputs.
8972 // We key by file path so we can attach them to the ParsedFile below.
8973
8974 // Map from file path → accumulated diff lines for that file.
8975 let mut lines_by_path: HashMap<String, Vec<GitDiffLine>> = HashMap::new();
8976
8977 if capture_diff_lines {
8978 let _ = diff.foreach(
8979 &mut |_delta, _progress| true, // file_cb (no-op)
8980 None, // binary_cb
8981 None, // hunk_cb
8982 Some(&mut |delta, _hunk, line| {
8983 let origin = line.origin();
8984 // We only keep `+`, `-`, and context (` `) lines.
8985 if origin != '+' && origin != '-' && origin != ' ' {
8986 return true;
8987 }
8988 let line_path = delta
8989 .new_file()
8990 .path_bytes()
8991 .or_else(|| delta.old_file().path_bytes())
8992 .map(atomic_repository::escape_repo_path)
8993 .unwrap_or_default();
8994
8995 lines_by_path
8996 .entry(line_path)
8997 .or_default()
8998 .push(GitDiffLine {
8999 origin,
9000 content: line.content().to_vec(),
9001 old_lineno: line.old_lineno(),
9002 new_lineno: line.new_lineno(),
9003 });
9004 true
9005 }),
9006 );
9007 }
9008
9009 // ── Step 2: build ParsedFile entries from the delta list ─────────────
9010
9011 // CB-9C path fidelity (review R7): a Git delta path is carried as RAW
9012 // bytes and canonicalized through the reversible `%XX` escape when the
9013 // bytes are not a plain printable-UTF-8 path without `%`. The mapping is
9014 // injective, so the escaped String identity recovers the exact Git tree
9015 // bytes (fixture oracle) and normalization never becomes identity.
9016 // Refusing here (the historical behavior) lost the file from the imported

Callers 1

parse_commit_with_scopeFunction · 0.85

Calls 15

canonical_git_modeFunction · 0.85
operation_is_deleteFunction · 0.85
git_algorithm_for_shaFunction · 0.85
oid_bytes_as_hexFunction · 0.85
git_tree_entryFunction · 0.85
get_file_contentFunction · 0.85
normalize_typechangesFunction · 0.85
originMethod · 0.80
new_fileMethod · 0.80
git_errorFunction · 0.70
git_object_idFunction · 0.70

Tested by

no test coverage detected