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

Function change_file_diffs_with

atomic-repository/src/diff_engine.rs:1638–1818  ·  view source on GitHub ↗

The resolver-parameterized core of [`change_file_diffs`]: `before` supplies a file's pre-change content for context padding (a `None` answer pads nothing — zero-context hunks, still at true offsets).

(
    change: &Change,
    config: &DiffOutputConfig,
    before: F,
)

Source from the content-addressed store, hash-verified

1636/// supplies a file's pre-change content for context padding (a `None`
1637/// answer pads nothing — zero-context hunks, still at true offsets).
1638pub fn change_file_diffs_with<F>(
1639 change: &Change,
1640 config: &DiffOutputConfig,
1641 before: F,
1642) -> Result<(Vec<FileDiff>, DiffStats), crate::error::RepositoryError>
1643where
1644 F: Fn(&str) -> Option<Vec<u8>>,
1645{
1646 // Git-imported changes carry Git's captured +/- lines in unhashed metadata.
1647 if let Some((file_diffs, stats)) = build_git_import_file_diffs(change) {
1648 return Ok((file_diffs, stats));
1649 }
1650
1651 let file_ops = change.file_ops();
1652
1653 let mut file_diffs = Vec::new();
1654 let mut stats = DiffStats::new();
1655
1656 for ops in file_ops {
1657 let file_path = ops.path();
1658
1659 let trunk_op = ops.trunk_op();
1660 let line_ops = ops.line_ops();
1661 if matches!(trunk_op, Some(TrunkOp::ProjectedSpanEdit { .. })) {
1662 return Err(crate::error::RepositoryError::InvalidOperation {
1663 message: "projected span edit requires a span-aware semantic diff".into(),
1664 });
1665 }
1666
1667 // Determine file change status from trunk operation
1668 let change_status = match trunk_op {
1669 Some(TrunkOp::Create { .. }) => FileChangeStatus::Added,
1670 Some(TrunkOp::Delete { .. }) => FileChangeStatus::Deleted,
1671 Some(TrunkOp::Move { .. }) => FileChangeStatus::Renamed,
1672 Some(TrunkOp::Undelete { .. })
1673 | Some(TrunkOp::SetMode { .. })
1674 | Some(TrunkOp::SetKind { .. })
1675 | Some(TrunkOp::ProjectedSpanEdit { .. }) => FileChangeStatus::Modified,
1676 None => FileChangeStatus::Modified,
1677 };
1678
1679 let mut file_diff = match change_status {
1680 FileChangeStatus::Added => FileDiff::added(file_path),
1681 FileChangeStatus::Deleted => FileDiff::deleted(file_path),
1682 FileChangeStatus::Renamed => FileDiff::modified(file_path),
1683 _ => FileDiff::modified(file_path),
1684 };
1685
1686 // Whole-file rewrites preserve graph/CRDT identities by deleting and
1687 // reinserting every line. Display their actual text delta instead of
1688 // exposing empty tombstones and unchanged reinserted lines. This also
1689 // needs the baseline for --stat and -U0, not just for context padding.
1690 if let Some((before_content, after_content)) =
1691 whole_file_replacement_text(ops, &change.contents, || before(file_path))
1692 {
1693 let result = diff_text(&before_content, &after_content, Algorithm::Myers);
1694 let old_lines: Vec<_> = before_content.split(|&b| b == b'\n').collect();
1695 let new_lines: Vec<_> = after_content.split(|&b| b == b'\n').collect();

Callers 1

change_file_diffsFunction · 0.70

Calls 15

addedFunction · 0.85
deletedFunction · 0.85
modifiedFunction · 0.85
diff_textFunction · 0.85
repair_diff_linesFunction · 0.85
removedFunction · 0.85
hunks_from_changed_linesFunction · 0.85
build_hunks_from_diffFunction · 0.70
is_git_import_changeFunction · 0.70

Tested by

no test coverage detected