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

Method print_unified

atomic-cli/src/commands/diff/format.rs:11–364  ·  view source on GitHub ↗

Print the diff in unified format.

(
        &self,
        file_diffs: &[FileDiff],
        config: &DiffOutputConfig,
    )

Source from the content-addressed store, hash-verified

9impl Diff {
10 /// Print the diff in unified format.
11 pub(super) fn print_unified(
12 &self,
13 file_diffs: &[FileDiff],
14 config: &DiffOutputConfig,
15 ) -> CliResult<()> {
16 for file_diff in file_diffs {
17 // Print file header
18 let old_path = if config.show_path_prefix {
19 format!("a/{}", file_diff.old_path)
20 } else {
21 file_diff.old_path.clone()
22 };
23 let new_path = if config.show_path_prefix {
24 format!("b/{}", file_diff.new_path)
25 } else {
26 file_diff.new_path.clone()
27 };
28
29 // Format line stats (e.g., "+2 -1") with colors
30 let line_stats = if file_diff.stats.insertions > 0 || file_diff.stats.deletions > 0 {
31 let ins = if file_diff.stats.insertions > 0 {
32 format!("+{}", file_diff.stats.insertions)
33 } else {
34 String::new()
35 };
36 let del = if file_diff.stats.deletions > 0 {
37 format!("-{}", file_diff.stats.deletions)
38 } else {
39 String::new()
40 };
41 (ins, del)
42 } else {
43 (String::new(), String::new())
44 };
45
46 if config.color {
47 // Build colored line stats
48 let colored_stats = if !line_stats.0.is_empty() || !line_stats.1.is_empty() {
49 let ins_colored = if !line_stats.0.is_empty() {
50 added(&line_stats.0).to_string()
51 } else {
52 String::new()
53 };
54 let del_colored = if !line_stats.1.is_empty() {
55 deleted(&line_stats.1).to_string()
56 } else {
57 String::new()
58 };
59 if !ins_colored.is_empty() && !del_colored.is_empty() {
60 format!(" ({} {})", ins_colored, del_colored)
61 } else if !ins_colored.is_empty() {
62 format!(" ({})", ins_colored)
63 } else {
64 format!(" ({})", del_colored)
65 }
66 } else {
67 String::new()
68 };

Callers 4

runMethod · 0.80

Calls 15

addedFunction · 0.85
deletedFunction · 0.85
semantic_diffFunction · 0.85
compute_inline_diffFunction · 0.85
print_word_diff_lineFunction · 0.85
old_hunksMethod · 0.80
new_hunksMethod · 0.80
skipMethod · 0.80
cloneMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected