Merge branch 'lp/diff-stat-utf8-display-width-fix' into next

The computation of column width made by "git diff --stat" was
confused when pathnames contain non-ASCII characters.

* lp/diff-stat-utf8-display-width-fix:
  t4073: add test for diffstat paths length when containing UTF-8 chars
  diff: improve scaling of filenames in diffstat to handle UTF-8 chars
This commit is contained in:
Junio C Hamano
2026-01-23 13:35:36 -08:00
3 changed files with 68 additions and 11 deletions

17
diff.c
View File

@@ -2859,17 +2859,12 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
char *slash;
prefix = "...";
len -= 3;
/*
* NEEDSWORK: (name_len - len) counts the display
* width, which would be shorter than the byte
* length of the corresponding substring.
* Advancing "name" by that number of bytes does
* *NOT* skip over that many columns, so it is
* very likely that chomping the pathname at the
* slash we will find starting from "name" will
* 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);
slash = strchr(name, '/');
if (slash)
name = slash;