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

[GSoC PATCH v2 0/2] diff: improve scaling of filenames in diffstat to handle UTF-8 chars

From
LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
Date
Jan 16, 2026, 00:04 UTC
Message-ID
<cover.1768520441.git.lorenzo.pegorari2002@gmail.com>
In-Reply-To
<aWgYRkv-YsuekdR_@lorenzo-VM>

Added a test (as Junio Hamano suggested) to check how the generated diffstat handles UTF-8 characters when given various `name-width`s.

This allowed me to notice a bug where, if the given `name-width` was 2 or less, the `len` variable would become negative, entering an infinite loop. So I also fixed this bug.

LorenzoPegorari (2):
  diff: improve scaling of filenames in diffstat to handle UTF-8 chars
  t4073: add test for diffstat paths length when containing UTF-8 chars
 diff.c                          | 17 ++++-----
 t/meson.build                   |  1 +
 t/t4073-diff-stat-name-width.sh | 61 +++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 11 deletions(-)
 create mode 100755 t/t4073-diff-stat-name-width.sh
Range-diff against v1:
1:  63e73122d1 ! 1:  abeb8d3439 diff: improve scaling of filenames in diffstat to handle UTF-8 chars
    @@ Commit message
         characters to drop from the filename, rather than their display width, using
         the `utf8_width()` function.
     
    +    Force `len` to not be less than 0 (this happens if the given `name-width` is
    +    2 or less), otherwise an infinite loop is entered.
    +
         Signed-off-by: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
     
      ## diff.c ##
    @@ diff.c: static void show_stats(struct diffstat_t *data, struct diff_options *opt
     -			 * leave the resulting string still too long.
     -			 */
     -			name += name_len - len;
    ++			if (len < 0)
    ++				len = 0;
     +
     +			while (name_len > len)
     +				name_len -= utf8_width((const char**)&name, NULL);
-:  ---------- > 2:  ee088ea6ef t4073: add test for diffstat paths length when containing UTF-8 chars
-- 
2.43.0
Previous: Lorenzo PegorariNext: LorenzoPegorari
Message 4 of 7 in “diff: improve scaling of filenames in diffstat to handle UTF-8 chars”
  1. 1/1 diff: improve scaling of filenames in diffstat to handle UTF-8 charsLorenzoPegorari, Jan 14, 2026
  2. Junio C HamanoJan 14, 2026
  3. Lorenzo PegorariJan 16, 2026
  4. 0/2 diff: improve scaling of filenames in diffstat to handle UTF-8 charsLorenzoPegorari, Jan 16, 2026
  5. 1/2 diff: improve scaling of filenames in diffstat to handle UTF-8 charsLorenzoPegorari, Jan 16, 2026
  6. 2/2 t4073: add test for diffstat paths length when containing UTF-8 charsLorenzoPegorari, Jan 16, 2026
  7. Junio C HamanoJan 17, 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.