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

Method print_stat

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

Print the diff in stat format.

(&self, stats: &DiffStats, config: &DiffOutputConfig)

Source from the content-addressed store, hash-verified

371
372 /// Print the diff in stat format.
373 pub(crate) fn print_stat(&self, stats: &DiffStats, config: &DiffOutputConfig) -> CliResult<()> {
374 if !stats.has_changes() {
375 return Ok(());
376 }
377
378 let max_path_len = stats.max_path_length();
379 let max_changes = stats.max_change_count();
380 let graph_width = cmp::min(config.stat_width, max_changes);
381
382 for file_stats in stats.iter() {
383 let path = &file_stats.path;
384 let padding = max_path_len - path.len();
385 let total = file_stats.total_changes();
386
387 // Calculate graph
388 let graph = if total > 0 && graph_width > 0 {
389 let scale = if max_changes > graph_width {
390 graph_width as f64 / max_changes as f64
391 } else {
392 1.0
393 };
394 let plus_count = ((file_stats.insertions as f64 * scale).round() as usize)
395 .max(if file_stats.insertions > 0 { 1 } else { 0 });
396 let minus_count = ((file_stats.deletions as f64 * scale).round() as usize)
397 .max(if file_stats.deletions > 0 { 1 } else { 0 });
398 format!("{}{}", "+".repeat(plus_count), "-".repeat(minus_count))
399 } else {
400 String::new()
401 };
402
403 if config.color {
404 let plus_part = "+".repeat(file_stats.insertions.min(graph_width));
405 let minus_part = "-".repeat(file_stats.deletions.min(graph_width));
406 println!(
407 " {} {} | {} {}{}",
408 style_path(path),
409 " ".repeat(padding),
410 total,
411 added(&plus_part),
412 deleted(&minus_part)
413 );
414 } else {
415 println!(" {} {} | {} {}", path, " ".repeat(padding), total, graph);
416 }
417 }
418
419 // Print summary
420 let files_text = if stats.file_count() == 1 {
421 "file"
422 } else {
423 "files"
424 };
425 let ins_text = if stats.total_insertions() == 1 {
426 "insertion"
427 } else {
428 "insertions"
429 };
430 let del_text = if stats.total_deletions() == 1 {

Callers 1

renderMethod · 0.80

Calls 9

has_changesMethod · 0.45
max_path_lengthMethod · 0.45
max_change_countMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
total_changesMethod · 0.45
file_countMethod · 0.45
total_insertionsMethod · 0.45
total_deletionsMethod · 0.45

Tested by

no test coverage detected