Skip to content

diff: improve scaling of filenames in diffstat to handle UTF-8 chars

LorenzoPegorari git 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 1 replyIn review
  2. v11 patch 2 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2diff: improve scaling of filenames in diffstat to handle UTF-8 charsdiff.c+6 -110 replies
2/2t4073: add test for diffstat paths length when containing UTF-8 charst/meson.build t/t4073-diff-stat-name-width.sh+62 -01 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

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

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

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 <[email protected]>
     
      ## 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

Signature · 1 line
2.43.0