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

Function legacy_content_file_diffs

atomic-cli/src/commands/diff/helpers.rs:1038–1121  ·  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

1036/// added (no before), deleted (no after), or modified (diffed with the
1037/// configured algorithm and context).
1038pub(crate) fn legacy_content_file_diffs(
1039 entries: &[(String, Vec<u8>, Vec<u8>)],
1040 algorithm: Algorithm,
1041 context_lines: usize,
1042) -> (Vec<FileDiff>, DiffStats) {
1043 let mut file_diffs = Vec::new();
1044 let mut stats = DiffStats::new();
1045
1046 for (file_path, before_content, after_content) in entries {
1047 // Determine the type of change based on before/after content
1048 let file_diff = match (before_content.is_empty(), after_content.is_empty()) {
1049 // File was added (no content before, has content after)
1050 (true, false) => {
1051 let mut diff = FileDiff::added(file_path);
1052 let lines: Vec<_> = after_content.split(|&b| b == b'\n').collect();
1053 let line_count = lines.len();
1054
1055 if !after_content.is_empty() {
1056 let mut graph_op = DiffHunk::new(0, 0, 1, line_count);
1057 for (i, line_bytes) in lines.iter().enumerate() {
1058 let line_content = String::from_utf8_lossy(line_bytes).into_owned();
1059 graph_op.add_line(HunkLine::added(line_content, i + 1));
1060 }
1061 diff.add_hunk(graph_op);
1062 }
1063
1064 diff.stats = FileDiffStats::added(file_path, line_count);
1065 diff
1066 }
1067
1068 // File was deleted (has content before, no content after)
1069 (false, true) => {
1070 let mut diff = FileDiff::deleted(file_path);
1071 let lines: Vec<_> = before_content.split(|&b| b == b'\n').collect();
1072 let line_count = lines.len();
1073
1074 if !before_content.is_empty() {
1075 let mut graph_op = DiffHunk::new(1, line_count, 0, 0);
1076 for (i, line_bytes) in lines.iter().enumerate() {
1077 let line_content = String::from_utf8_lossy(line_bytes).into_owned();
1078 graph_op.add_line(HunkLine::removed(line_content, i + 1));
1079 }
1080 diff.add_hunk(graph_op);
1081 }
1082
1083 diff.stats = FileDiffStats::deleted(file_path, line_count);
1084 diff
1085 }
1086
1087 // File was modified (has content both before and after)
1088 (false, false) => {
1089 let mut diff = FileDiff::modified(file_path);
1090
1091 // Compute diff between old (before) and new (after) content
1092 let diff_result = diff_text(before_content, after_content, algorithm);
1093
1094 if !diff_result.is_unchanged() {
1095 let old_lines: Vec<_> = before_content.split(|&b| b == b'\n').collect();

Callers 2

diff_changeFunction · 0.50

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