Skip to content

Commit ffaf9cc

Browse files
geofftgitster
authored andcommitted
builtin-blame.c: Use utf8_strwidth for author's names
git blame misaligns output if a author's name has a differing display width and strlen; for instance, an accented Latin letter that takes two bytes to encode will cause the rest of the line to be shifted to the left by one. To fix this, use utf8_strwidth instead of strlen (and compute the padding ourselves, since printf doesn't know about UTF-8). Signed-off-by: Geoffrey Thomas <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a9391e commit ffaf9cc

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

builtin-blame.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "string-list.h"
2020
#include "mailmap.h"
2121
#include "parse-options.h"
22+
#include "utf8.h"
2223

2324
static char blame_usage[] = "git blame [options] [rev-opts] [rev] [--] file";
2425

@@ -1618,13 +1619,14 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
16181619
printf(" %*d", max_orig_digits,
16191620
ent->s_lno + 1 + cnt);
16201621

1621-
if (!(opt & OUTPUT_NO_AUTHOR))
1622-
printf(" (%-*.*s %10s",
1623-
longest_author, longest_author,
1624-
ci.author,
1622+
if (!(opt & OUTPUT_NO_AUTHOR)) {
1623+
int pad = longest_author - utf8_strwidth(ci.author);
1624+
printf(" (%s%*s %10s",
1625+
ci.author, pad, "",
16251626
format_time(ci.author_time,
16261627
ci.author_tz,
16271628
show_raw_time));
1629+
}
16281630
printf(" %*d) ",
16291631
max_digits, ent->lno + 1 + cnt);
16301632
}
@@ -1755,7 +1757,7 @@ static void find_alignment(struct scoreboard *sb, int *option)
17551757
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
17561758
suspect->commit->object.flags |= METAINFO_SHOWN;
17571759
get_commit_info(suspect->commit, &ci, 1);
1758-
num = strlen(ci.author);
1760+
num = utf8_strwidth(ci.author);
17591761
if (longest_author < num)
17601762
longest_author = num;
17611763
}

0 commit comments

Comments
 (0)