git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blame: add correct paddings in time_buf for align
@ 2014-04-18  8:44 Jiang Xin
  2014-04-18 14:42 ` Duy Nguyen
  0 siblings, 1 reply; 20+ messages in thread
From: Jiang Xin @ 2014-04-18  8:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Brian Gesiak, Git List, Jiang Xin

When show blame information with relative time, the UTF-8 characters in
`time_str` will break the alignment of columns after the date field.
This is because the `time_buf` padding with spaces should have a
constant display width, not a fixed strlen size.  So we should call
utf8_strwidth() instead of strlen() for calibration.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
---

Before applying this patch:

        5817da01 builtin-blame.c   (Pierre Habouzit             6 年前                         21) #include "parse-options.h"
        ffaf9cc0 builtin-blame.c   (Geoffrey Thomas             5 年前                         22) #include "utf8.h"
        3b8a12e8 builtin/blame.c   (Axel Bonnet                 3 年 10 个月之前            23) #include "userdiff.h"
        25ed3412 builtin/blame.c   (Bo Yang                     1 年 1 个月之前             24) #include "line-range.h"
        58dbfa2e builtin/blame.c   (Eric Sunshine               9 个月之前                   25) #include "line-log.h"
        cee7f245 builtin-pickaxe.c (Junio C Hamano              8 年前                         26) 

After applying this patch:

        5817da01 builtin-blame.c   (Pierre Habouzit             6 年前                           21) #include "parse-options.h"
        ffaf9cc0 builtin-blame.c   (Geoffrey Thomas             5 年前                           22) #include "utf8.h"
        3b8a12e8 builtin/blame.c   (Axel Bonnet                 3 年 10 个月之前                 23) #include "userdiff.h"
        25ed3412 builtin/blame.c   (Bo Yang                     1 年 1 个月之前                  24) #include "line-range.h"
        58dbfa2e builtin/blame.c   (Eric Sunshine               9 个月之前                       25) #include "line-log.h"
        cee7f245 builtin-pickaxe.c (Junio C Hamano              8 年前                           26) 

 builtin/blame.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 88cb799..c8f6647 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1564,12 +1564,19 @@ static const char *format_time(unsigned long time, const char *tz_str,
 	else {
 		const char *time_str;
 		int time_len;
+		int time_col;
 		int tz;
 		tz = atoi(tz_str);
 		time_str = show_date(time, tz, blame_date_mode);
 		time_len = strlen(time_str);
 		memcpy(time_buf, time_str, time_len);
-		memset(time_buf + time_len, ' ', blame_date_width - time_len);
+		/*
+		 * Add space paddings to time_buf to display a fixed width
+		 * string, and use time_col for display width calibration.
+		 */
+		time_col = utf8_strwidth(time_str);
+		memset(time_buf + time_len, ' ', blame_date_width - time_col);
+		*(time_buf + time_len + blame_date_width - time_col) = 0;
 	}
 	return time_buf;
 }
-- 
1.9.2.474.g17b2a16

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2014-04-22 14:39 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-18  8:44 [PATCH] blame: add correct paddings in time_buf for align Jiang Xin
2014-04-18 14:42 ` Duy Nguyen
2014-04-18 17:08   ` Junio C Hamano
2014-04-19  0:20     ` Duy Nguyen
2014-04-20 16:13   ` [PATCH v2 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-20 16:13   ` [PATCH v2 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-20 20:28     ` Eric Sunshine
2014-04-20 16:13   ` [PATCH v2 2/2] blame: use different blame_date_width for different locale Jiang Xin
2014-04-20 21:40     ` Junio C Hamano
2014-04-21  6:02       ` [PATCH v3 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-21  6:02       ` [PATCH v3 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-21  6:02       ` [PATCH v3 2/2] blame: use a helper to get suitable blame_date_width Jiang Xin
2014-04-21 17:20         ` Junio C Hamano
2014-04-21 19:19           ` Junio C Hamano
2014-04-22 12:25             ` Jiang Xin
2014-04-22 14:39             ` [PATCH v4 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-22 14:39             ` [PATCH v4 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-22 14:39             ` [PATCH v4 2/2] blame: dynamic blame_date_width for different locales Jiang Xin
2014-04-22 10:01       ` [PATCH v2 2/2] blame: use different blame_date_width for different locale David Kastrup
2014-04-22 12:16         ` Jiang Xin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).