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....@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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to