public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Toon Claes <toon@iotcl.com>, Justin Tobler <jltobler@gmail.com>,
	Niels Glodny <n.glodny@campus.lmu.de>,
	Patrick Steinhardt <ps@pks.im>
Subject: [GSoC PATCH v2 0/2] diff: improve scaling of filenames in diffstat to handle UTF-8 chars
Date: Fri, 16 Jan 2026 01:04:22 +0100	[thread overview]
Message-ID: <cover.1768520441.git.lorenzo.pegorari2002@gmail.com> (raw)
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


  parent reply	other threads:[~2026-01-16  0:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-14 22:27 [GSoC PATCH 1/1] diff: improve scaling of filenames in diffstat to handle UTF-8 chars LorenzoPegorari
2026-01-14 22:50 ` Junio C Hamano
2026-01-16  0:00   ` Lorenzo Pegorari
2026-01-16  0:04 ` LorenzoPegorari [this message]
2026-01-16  0:05   ` [GSoC PATCH v2 1/2] " LorenzoPegorari
2026-01-16  0:05   ` [GSoC PATCH v2 2/2] t4073: add test for diffstat paths length when containing " LorenzoPegorari
2026-01-17 17:52     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1768520441.git.lorenzo.pegorari2002@gmail.com \
    --to=lorenzo.pegorari2002@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jltobler@gmail.com \
    --cc=n.glodny@campus.lmu.de \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    --cc=toon@iotcl.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox