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

Re: [PATCH] blame: add correct paddings in time_buf for align

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 18, 2014, 17:08 UTC
Message-ID
<xmqqd2ged0qg.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CACsJy8BTBwqFZUU3i3cuv40B6AHw5SRY9DZN2PoKL4XzgEL2eA@mail.gmail.com>
Duy Nguyen <pclouds@gmail.com> writes:
Show 31 quoted lines
> On Fri, Apr 18, 2014 at 3:44 PM, Jiang Xin <worldhello.net@gmail.com> wrote:
>> 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)
>
>
> The numbers 21..26 still do not look aligned, both in gmail raw
> message view and gmane.

Interesting. In my GNUS/Emacs on a fixed-column terminal where an CJK occupies two display columns, they do look aligned, but in my Chrome showing news.gmane.org/gmane.comp.version-control.git/, they do look jagged. When these lines shown in the browser get copied and pasted to gedit, they still look jagged, but after saving it to a file and catting it to the same fixed-column terminal, they are perfectly aligned.

Font issues, I guess?
Show 9 quoted lines
>> +               /*
>> +                * 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;
>
> And you may want to turn time_buf[128] to strbuf as well while you're at it.
Good eyes.
Previous: Duy NguyenNext: Duy Nguyen
Message 3 of 20 in “blame: add correct paddings in time_buf for align”
  1. blame: add correct paddings in time_buf for alignJiang Xin, Apr 18, 2014
  2. Duy NguyenApr 18, 2014
  3. Junio C HamanoApr 18, 2014
  4. Duy NguyenApr 19, 2014
  5. 0/2 peroper align of datetime filed of git-blameJiang Xin, Apr 20, 2014
  6. 1/2 bugfix: fix broken time_buf paddings for git-blameJiang Xin, Apr 20, 2014
  7. Eric SunshineApr 20, 2014
  8. 2/2 blame: use different blame_date_width for different localeJiang Xin, Apr 20, 2014
  9. Junio C HamanoApr 20, 2014
  10. 0/2 peroper align of datetime filed of git-blameJiang Xin, Apr 21, 2014
  11. 1/2 bugfix: fix broken time_buf paddings for git-blameJiang Xin, Apr 21, 2014
  12. 2/2 blame: use a helper to get suitable blame_date_widthJiang Xin, Apr 21, 2014
  13. Junio C HamanoApr 21, 2014
  14. Junio C HamanoApr 21, 2014
  15. Jiang XinApr 22, 2014
  16. 0/2 peroper align of datetime filed of git-blameJiang Xin, Apr 22, 2014
  17. 1/2 bugfix: fix broken time_buf paddings for git-blameJiang Xin, Apr 22, 2014
  18. 2/2 blame: dynamic blame_date_width for different localesJiang Xin, Apr 22, 2014
  19. David KastrupApr 22, 2014
  20. Jiang XinApr 22, 2014

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.