diff: leave NEEDWORK notes in show_stats() function
The previous step made an attempt to correctly compute display columns allocated and padded different parts of diffstat output. There are at least two known codepaths in the function that still mixes up display widths and byte length that need to be fixed. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 21, 2022 at 14:53 UTC
ce8529b2bbabcb5240bdcc73bccaafa1116c5d7a
1 file changed
+15
diff.c
+15
@@ -2675,6 +2675,11 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
2675
* making the line longer than the maximum width.
2676
*/
2677
2678
+ /*
2679
+ * NEEDSWORK: line_prefix is often used for "log --graph" output
2680
+ * and contains ANSI-colored string. utf8_strnwidth() should be
2681
+ * used to correctly count the display width instead of strlen().
2682
+ */
2683
if (options->stat_width == -1)
2684
width = term_columns() - strlen(line_prefix);
2685
else
@@ -2750,6 +2755,16 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
2755
char *slash;
2756
prefix = "...";
2757
len -= 3;
2758
+ /*
2759
+ * NEEDSWORK: (name_len - len) counts the display
2760
+ * width, which would be shorter than the byte
2761
+ * length of the corresponding substring.
2762
+ * Advancing "name" by that number of bytes does
2763
+ * *NOT* skip over that many columns, so it is
2764
+ * very likely that chomping the pathname at the
2765
+ * slash we will find starting from "name" will
2766
+ * leave the resulting string still too long.
2767
+ */
2768
name += name_len - len;
2769
slash = strchr(name, '/');
2770
if (slash)