git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] builtin-blame.c: Use utf8_strwidth for author's names

From
Geoffrey Thomas <geofft@mit.edu>
Date
Jan 30, 2009, 09:41 UTC
Message-ID
<1233308489-2656-2-git-send-email-geofft@mit.edu>
In-Reply-To
<1233308489-2656-1-git-send-email-geofft@mit.edu>
From: Geoffrey Thomas <geofft@mit.edu>
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>
---
 builtin-blame.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/builtin-blame.c b/builtin-blame.c
index aae14ef..2941fc0 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -19,6 +19,7 @@
 #include "string-list.h"
 #include "mailmap.h"
 #include "parse-options.h"
+#include "utf8.h"
 
 static char blame_usage[] = "git blame [options] [rev-opts] [rev] [--] file";
 
@@ -1619,9 +1620,9 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
 				       ent->s_lno + 1 + cnt);
 
 			if (!(opt & OUTPUT_NO_AUTHOR))
-				printf(" (%-*.*s %10s",
-				       longest_author, longest_author,
+				printf(" (%s%*s %10s",
 				       ci.author,
+				       longest_author - utf8_strwidth(ci.author), "",
 				       format_time(ci.author_time,
 						   ci.author_tz,
 						   show_raw_time));
@@ -1755,7 +1756,7 @@ static void find_alignment(struct scoreboard *sb, int *option)
 		if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
 			suspect->commit->object.flags |= METAINFO_SHOWN;
 			get_commit_info(suspect->commit, &ci, 1);
-			num = strlen(ci.author);
+			num = utf8_strwidth(ci.author);
 			if (longest_author < num)
 				longest_author = num;
 		}
-- 
1.5.6.5
Previous: Geoffrey ThomasNext: Johannes Schindelin
Message 2 of 13 in “utf8: add utf8_strwidth()”
  1. utf8: add utf8_strwidth()Geoffrey Thomas, Jan 30, 2009
  2. builtin-blame.c: Use utf8_strwidth for author's namesGeoffrey Thomas, Jan 30, 2009
  3. Johannes SchindelinJan 30, 2009
  4. Geoffrey ThomasJan 30, 2009
  5. Jeff KingJan 31, 2009
  6. Johannes SchindelinFeb 1, 2009
  7. Junio C HamanoFeb 2, 2009
  8. Johannes SchindelinFeb 2, 2009
  9. Junio C HamanoFeb 3, 2009
  10. Jeff KingFeb 2, 2009
  11. Jeff KingJan 31, 2009
  12. Geoffrey ThomasJan 31, 2009
  13. Jeff KingJan 31, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.