aboutsummaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-02-05 15:42:01 -0800
committerJunio C Hamano <gitster@pobox.com>2026-02-05 15:42:01 -0800
commit1f17604ce4e35e8a94e73c5c11e5882812663c2f (patch)
tree4c8e30e9f56fae3acd3131bda4947ce3ee4e37a6 /diff.c
parentd83491aebacf6ff645ccac2b821e3771356af69f (diff)
parent04f5d95ef7715e952c93f078e2973c44bb6f3396 (diff)
downloadgit-1f17604ce4e35e8a94e73c5c11e5882812663c2f.tar.xz
Merge branch 'lp/diff-stat-utf8-display-width-fix'
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
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/diff.c b/diff.c
index a68ddd2168..452fc69775 100644
--- a/diff.c
+++ b/diff.c
@@ -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;