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

Function legacy_content_file_diffs

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

Build the legacy (no-file_ops) change's file diffs from per-file before/after content — the computation `atomic diff -c` runs for legacy changes, factored out so the local body (graph-read content) and the routed hook (wire-carried content) run the SAME code: added (no before), deleted (no after), or modified (diffed with the configured algorithm and context).

(
    entries: &[(String, Vec<u8>, Vec<u8>)],
    algorithm: Algorithm,
    context_lines: usize,
)

Source from the content-addressed store, hash-verified

1487/// added (no before), deleted (no after), or modified (diffed with the
1488/// configured algorithm and context).
1489pub fn legacy_content_file_diffs(
1490 entries: &[(String, Vec<u8>, Vec<u8>)],
1491 algorithm: Algorithm,
1492 context_lines: usize,
1493) -> (Vec<FileDiff>, DiffStats) {
1494 let mut file_diffs = Vec::new();
1495 let mut stats = DiffStats::new();
1496
1497 for (file_path, before_content, after_content) in entries {
1498 // Determine the type of change based on before/after content
1499 let file_diff = match (before_content.is_empty(), after_content.is_empty()) {
1500 // File was added (no content before, has content after)
1501 (true, false) => {
1502 let mut diff = FileDiff::added(file_path);
1503 let lines: Vec<_> = after_content.split(|&b| b == b'\n').collect();
1504 let line_count = lines.len();
1505
1506 if !after_content.is_empty() {
1507 let mut graph_op = DiffHunk::new(0, 0, 1, line_count);
1508 for (i, line_bytes) in lines.iter().enumerate() {
1509 let line_content = String::from_utf8_lossy(line_bytes).into_owned();
1510 graph_op.add_line(HunkLine::added(line_content, i + 1));
1511 }
1512 diff.add_hunk(graph_op);
1513 }
1514
1515 diff.stats = FileDiffStats::added(file_path, line_count);
1516 diff
1517 }
1518
1519 // File was deleted (has content before, no content after)
1520 (false, true) => {
1521 let mut diff = FileDiff::deleted(file_path);
1522 let lines: Vec<_> = before_content.split(|&b| b == b'\n').collect();
1523 let line_count = lines.len();
1524
1525 if !before_content.is_empty() {
1526 let mut graph_op = DiffHunk::new(1, line_count, 0, 0);
1527 for (i, line_bytes) in lines.iter().enumerate() {
1528 let line_content = String::from_utf8_lossy(line_bytes).into_owned();
1529 graph_op.add_line(HunkLine::removed(line_content, i + 1));
1530 }
1531 diff.add_hunk(graph_op);
1532 }
1533
1534 diff.stats = FileDiffStats::deleted(file_path, line_count);
1535 diff
1536 }
1537
1538 // File was modified (has content both before and after)
1539 (false, false) => {
1540 let mut diff = FileDiff::modified(file_path);
1541
1542 // Compute diff between old (before) and new (after) content
1543 let diff_result = diff_text(before_content, after_content, algorithm);
1544
1545 if !diff_result.is_unchanged() {
1546 let old_lines: Vec<_> = before_content.split(|&b| b == b'\n').collect();

Callers

nothing calls this directly

Calls 15

addedFunction · 0.85
deletedFunction · 0.85
removedFunction · 0.85
modifiedFunction · 0.85
diff_textFunction · 0.85
build_hunks_from_diffFunction · 0.70
is_emptyMethod · 0.45
collectMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
add_lineMethod · 0.45
add_hunkMethod · 0.45

Tested by

no test coverage detected