mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
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>
This commit is contained in:
parent
8a9391e944
commit
ffaf9cc0ff
|
@ -19,6 +19,7 @@
|
||||||
#include "string-list.h"
|
#include "string-list.h"
|
||||||
#include "mailmap.h"
|
#include "mailmap.h"
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
|
#include "utf8.h"
|
||||||
|
|
||||||
static char blame_usage[] = "git blame [options] [rev-opts] [rev] [--] file";
|
static char blame_usage[] = "git blame [options] [rev-opts] [rev] [--] file";
|
||||||
|
|
||||||
|
@ -1618,13 +1619,14 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
|
||||||
printf(" %*d", max_orig_digits,
|
printf(" %*d", max_orig_digits,
|
||||||
ent->s_lno + 1 + cnt);
|
ent->s_lno + 1 + cnt);
|
||||||
|
|
||||||
if (!(opt & OUTPUT_NO_AUTHOR))
|
if (!(opt & OUTPUT_NO_AUTHOR)) {
|
||||||
printf(" (%-*.*s %10s",
|
int pad = longest_author - utf8_strwidth(ci.author);
|
||||||
longest_author, longest_author,
|
printf(" (%s%*s %10s",
|
||||||
ci.author,
|
ci.author, pad, "",
|
||||||
format_time(ci.author_time,
|
format_time(ci.author_time,
|
||||||
ci.author_tz,
|
ci.author_tz,
|
||||||
show_raw_time));
|
show_raw_time));
|
||||||
|
}
|
||||||
printf(" %*d) ",
|
printf(" %*d) ",
|
||||||
max_digits, ent->lno + 1 + cnt);
|
max_digits, ent->lno + 1 + cnt);
|
||||||
}
|
}
|
||||||
|
@ -1755,7 +1757,7 @@ static void find_alignment(struct scoreboard *sb, int *option)
|
||||||
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
|
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
|
||||||
suspect->commit->object.flags |= METAINFO_SHOWN;
|
suspect->commit->object.flags |= METAINFO_SHOWN;
|
||||||
get_commit_info(suspect->commit, &ci, 1);
|
get_commit_info(suspect->commit, &ci, 1);
|
||||||
num = strlen(ci.author);
|
num = utf8_strwidth(ci.author);
|
||||||
if (longest_author < num)
|
if (longest_author < num)
|
||||||
longest_author = num;
|
longest_author = num;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue