diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-03-09 14:36:55 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-09 14:36:55 -0700 |
| commit | e757df82af5e9283fec2ff54d1e0eec2662c623c (patch) | |
| tree | cd5826bb03074d2e2af42116301aa4384bf01b21 /diff.c | |
| parent | 3fe08b8fd1f7731edabeab8138547ec88d6407de (diff) | |
| parent | 064b869efc50be2557015665bc3dc8ac9008a6e4 (diff) | |
| download | git-e757df82af5e9283fec2ff54d1e0eec2662c623c.tar.xz | |
Merge branch 'lp/diff-stat-utf8-display-width-fix'
"git log --graph --stat" did not count the display width of colored
graph part of its own output correctly, which has been corrected.
* lp/diff-stat-utf8-display-width-fix:
t4052: test for diffstat width when prefix contains ANSI escape codes
diff: handle ANSI escape codes in prefix when calculating diffstat width
Diffstat (limited to 'diff.c')
| -rw-r--r-- | diff.c | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -2756,7 +2756,9 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) count = i; /* where we can stop scanning in data->files[] */ /* - * We have width = stat_width or term_columns() columns total. + * We have width = stat_width or term_columns() columns total minus the + * length of line_prefix skipping ANSI escape codes to get the display + * width (e.g., skip ANSI-colored strings in "log --graph --stat"). * We want a maximum of min(max_len, stat_name_width) for the name part. * We want a maximum of min(max_change, stat_graph_width) for the +- part. * We also need 1 for " " and 4 + decimal_width(max_change) @@ -2783,14 +2785,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) * separators and this message, this message will "overflow" * making the line longer than the maximum width. */ - - /* - * NEEDSWORK: line_prefix is often used for "log --graph" output - * and contains ANSI-colored string. utf8_strnwidth() should be - * used to correctly count the display width instead of strlen(). - */ if (options->stat_width == -1) - width = term_columns() - strlen(line_prefix); + width = term_columns() - utf8_strnwidth(line_prefix, strlen(line_prefix), 1); else width = options->stat_width ? options->stat_width : 80; number_width = decimal_width(max_change) > number_width ? |
