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 <geofft@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Geoffrey Thomas committed
Jan 30, 2009 at 04:41 UTC
ffaf9cc0ff0692a0b60cdf1b62e8375706b7865d
1 file changed
+7
-5
builtin-blame.c
+7
-5
@@ -19,6 +19,7 @@
19
#include "string-list.h"
20
#include "mailmap.h"
21
#include "parse-options.h"
22
+#include "utf8.h"
23
24
static char blame_usage[] = "git blame [options] [rev-opts] [rev] [--] file";
25
@@ -1618,13 +1619,14 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1619
printf(" %*d", max_orig_digits,
1620
ent->s_lno + 1 + cnt);
1621
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, "",
1626
format_time(ci.author_time,
1627
ci.author_tz,
1628
show_raw_time));
1629
+ }
1630
printf(" %*d) ",
1631
max_digits, ent->lno + 1 + cnt);
1632
}
@@ -1755,7 +1757,7 @@ static void find_alignment(struct scoreboard *sb, int *option)
1757
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
1758
suspect->commit->object.flags |= METAINFO_SHOWN;
1759
get_commit_info(suspect->commit, &ci, 1);
1758
- num = strlen(ci.author);
1760
+ num = utf8_strwidth(ci.author);
1761
if (longest_author < num)
1762
longest_author = num;
1763
}