git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC PATCH 0/2] diff: handle ANSI chars in prefix when calculating diffstat width

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 24, 2026, 05:17 UTC
Message-ID
<xmqqwm02k9e0.fsf@gitster.g>
In-Reply-To
<cover.1771894207.git.lorenzo.pegorari2002@gmail.com>
LorenzoPegorari <lorenzo.pegorari2002@gmail.com> writes:
Show 12 quoted lines
> This patch aims to fix a bug where the calculation of the diffstat width
> incorrectly uses the strlen() of line_prefix instead of its actual
> display width.
>
> This patch addresses the NEEDSWORK item added by ce8529b2 (diff: leave
> NEEDWORK notes in show_stats() function, 2022-10-21).
>
> Also, this bug was reported and suggested to me by Junio C Hamano here:
> https://lore.kernel.org/git/xmqqikd3ermt.fsf@gitster.g/
>
> Junio, do you wish to be included in this patch by a Reported-by and/or
> Suggested-by tag?

Neither. I didn't report or suggest anything recently. I merely pointed at one out of the two NEEDSWORK comments that was written long time ago when you addressed the other one.

>   diff: handle ANSI chars in prefix when calculating diffstat width
>   t4074: add test for diffstat width when prefix contains ANSI chars

"ANSI chars" is a phrase that was hard to understand, as the theme of this was paged out of my working memory a long time ago ;-). I think the issue is that strings with ANSI color escape sequences are used in "log --graph" and other output, and in order to measure how many display columns these strings occupy, we must not be using strlen() but utr8_strnwidth() that knows how to count UTF-8 chars (whose display widths do not match the number of bytes) as well as that these color escape sequences do not occupy any display width?

Anyway, thanks for working on these patches.
Previous: Lorenzo PegorariNext: LorenzoPegorari
Message 6 of 14 in “diff: handle ANSI chars in prefix when calculating diffstat width”
  1. 0/2 diff: handle ANSI chars in prefix when calculating diffstat widthLorenzoPegorari, Feb 24, 2026
  2. 1/2 diff: handle ANSI chars in prefix when calculating diffstat widthLorenzoPegorari, Feb 24, 2026
  3. 2/2 t4074: add test for diffstat width when prefix contains ANSI charsLorenzoPegorari, Feb 24, 2026
  4. Junio C HamanoFeb 24, 2026
  5. Lorenzo PegorariFeb 25, 2026
  6. Junio C HamanoFeb 24, 2026
  7. 0/2 diff: handle UTF-8 chars in prefix when calculating diffstat widthLorenzoPegorari, Feb 27, 2026
  8. 1/2 diff: handle UTF-8 chars in prefix when calculating diffstat widthLorenzoPegorari, Feb 27, 2026
  9. 2/2 t4052: add test for diffstat width when prefix contains UTF-8 charsLorenzoPegorari, Feb 27, 2026
  10. Junio C HamanoFeb 27, 2026
  11. Junio C HamanoFeb 27, 2026
  12. 0/2 diff: handle ANSI escape codes in prefix when calculating diffstat widthLorenzoPegorari, Feb 27, 2026
  13. 1/2 diff: handle ANSI escape codes in prefix when calculating diffstat widthLorenzoPegorari, Feb 27, 2026
  14. 2/2 t4052: test for diffstat width when prefix contains ANSI escape codesLorenzoPegorari, Feb 27, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.