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

Function format_stat_graph

atomic-cli/src/commands/diff/output.rs:34–56  ·  view source on GitHub ↗

Build hunks from a diff result with context lines. This function groups diff operations into hunks with the specified number of context lines around changes. # Arguments `diff_result` - The raw diff result `old_lines` - Lines from the old content `new_lines` - Lines from the new content `context` - Number of context lines to include # Returns A vector of `DiffHunk`s representing the changes w

(insertions: usize, deletions: usize, max_width: usize)

Source from the content-addressed store, hash-verified

32///
33/// A string containing `+` and `-` characters representing the change ratio.
34pub(crate) fn format_stat_graph(insertions: usize, deletions: usize, max_width: usize) -> String {
35 let total = insertions + deletions;
36 if total == 0 {
37 return String::new();
38 }
39
40 let width = total.min(max_width);
41 let ins_width = if total <= max_width {
42 insertions
43 } else {
44 (insertions as f64 / total as f64 * max_width as f64).round() as usize
45 };
46 let del_width = width.saturating_sub(ins_width);
47
48 let mut result = String::with_capacity(width);
49 for _ in 0..ins_width {
50 result.push('+');
51 }
52 for _ in 0..del_width {
53 result.push('-');
54 }
55 result
56}
57
58pub(crate) fn build_hunks_from_diff(
59 diff_result: &DiffResult,

Calls 1

pushMethod · 0.45