1443
{
1444
int i, len, add, del, adds = 0, dels = 0;
1445
uintmax_t max_change = 0, max_len = 0;
1446
- int total_files = data->nr;
1447
- int width, name_width, graph_width, number_width = 4, count;
1446
+ int total_files = data->nr, count;
1447
+ int width, name_width, graph_width, number_width = 0, bin_width = 0;
1448
const char *reset, *add_c, *del_c;
1449
const char *line_prefix = "";
1450
int extra_shown = 0;
1480
if (max_len < len)
1481
max_len = len;
1482
1483
- if (file->is_binary || file->is_unmerged)
1483
+ if (file->is_unmerged) {
1484
+ /* "Unmerged" is 8 characters */
1485
+ bin_width = bin_width < 8 ? 8 : bin_width;
1486
continue;
1487
+ }
1488
+ if (file->is_binary) {
1489
+ /* "Bin XXX -> YYY bytes" */
1490
+ int w = 14 + decimal_width(file->added)
1491
+ + decimal_width(file->deleted);
1492
+ bin_width = bin_width < w ? w : bin_width;
1493
+ /* Display change counts aligned with "Bin" */
1494
+ number_width = 3;
1495
+ continue;
1496
+ }
1497
+
1498
if (max_change < change)
1499
max_change = change;
1500
}
1519
* stat_name_width fixes the maximum width of the filename,
1520
* and is also used to divide available columns if there
1521
* aren't enough.
1522
+ *
1523
+ * Binary files are displayed with "Bin XXX -> YYY bytes"
1524
+ * instead of the change count and graph. This part is treated
1525
+ * similarly to the graph part, except that it is not
1526
+ * "scaled". If total width is too small to accomodate the
1527
+ * guaranteed minimum width of the filename part and the
1528
+ * separators and this message, this message will "overflow"
1529
+ * making the line longer than the maximum width.
1530
*/
1531
1532
if (options->stat_width == -1)
1533
width = term_columns();
1534
else
1535
width = options->stat_width ? options->stat_width : 80;
1536
+ number_width = decimal_width(max_change) > number_width ?
1537
+ decimal_width(max_change) : number_width;
1538
1539
if (options->stat_graph_width == -1)
1540
options->stat_graph_width = diff_stat_graph_width;
1548
1549
/*
1550
* First assign sizes that are wanted, ignoring available width.
1551
+ * strlen("Bin XXX -> YYY bytes") == bin_width, and the part
1552
+ * starting from "XXX" should fit in graph_width.
1553
*/
1529
- graph_width = (options->stat_graph_width &&
1530
- options->stat_graph_width < max_change) ?
1531
- options->stat_graph_width : max_change;
1554
+ graph_width = max_change + 4 > bin_width ? max_change : bin_width - 4;
1555
+ if (options->stat_graph_width &&
1556
+ options->stat_graph_width < graph_width)
1557
+ graph_width = options->stat_graph_width;
1558
+
1559
name_width = (options->stat_name_width > 0 &&
1560
options->stat_name_width < max_len) ?
1561
options->stat_name_width : max_len;
1610
if (data->files[i]->is_binary) {
1611
fprintf(options->file, "%s", line_prefix);
1612
show_name(options->file, prefix, name, len);
1586
- fprintf(options->file, " Bin ");
1613
+ fprintf(options->file, " %*s ", number_width, "Bin");
1614
fprintf(options->file, "%s%"PRIuMAX"%s",
1615
del_c, deleted, reset);
1616
fprintf(options->file, " -> ");
1623
else if (data->files[i]->is_unmerged) {
1624
fprintf(options->file, "%s", line_prefix);
1625
show_name(options->file, prefix, name, len);
1599
- fprintf(options->file, " Unmerged\n");
1626
+ fprintf(options->file, " Unmerged\n");
1627
continue;
1628
}
1629
1652
}
1653
fprintf(options->file, "%s", line_prefix);
1654
show_name(options->file, prefix, name, len);
1628
- fprintf(options->file, "%5"PRIuMAX"%s", added + deleted,
1629
- added + deleted ? " " : "");
1655
+ fprintf(options->file, " %*"PRIuMAX"%s",
1656
+ number_width, added + deleted,
1657
+ added + deleted ? " " : "");
1658
show_graph(options->file, '+', add, add_c, reset);
1659
show_graph(options->file, '-', del, del_c, reset);
1660
fprintf(options->file, "\n");