git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Wang Bing-hua" <louiswpf@gmail.com>
Cc: "Wang Bing-hua via GitGitGadget" <gitgitgadget@gmail.com>,
	<git@vger.kernel.org>
Subject: Re: [PATCH v2] remote: align --verbose output with spaces
Date: Wed, 18 Dec 2024 07:39:20 -0800	[thread overview]
Message-ID: <xmqqy10dt2zb.fsf@gitster.g> (raw)
In-Reply-To: <1812389a7b6fe18d.7946240d95ed36ca.1b2132d5c888cc21@host> (Wang Bing-hua's message of "Wed, 18 Dec 2024 08:37:22 +0000")

"Wang Bing-hua" <louiswpf@gmail.com> writes:

>> Wouldn't it work to just do (totally untested code snippet below;
>> may have off-by-one around maxwidth)
>> 
>> 				printf("%.*s%s", maxwidth, item->string,
>> 					item->util ? "" : item->util);
>> 
>> without using any strbuf operation?
>
> I did try to use printf at first.
>
> 				printf("%-*s %s\n", maxwidth, item->string,
> 				       item->util ? (const char *)item->util :
> 						    "");
>
> But it broke when there are non-ASCII characters. For example:

Ah, of course, I should have double-checked, but it should be more
like

	printf("%.*s%s%s",
	       maxwidth + 1 - utf8_strwidth(item->string), "",
	       item->string,
	       item->util ? item->util : "");

meaning

 (1) the first output field must have maxwidth+1 - the display width
     the second output field takes.  The field's contents is empty, so
     we get enough SP padded to make the total of this first field
     and the second field to make maxwidth+1.

 (2) the second output field is item->string itself.

 (3) the third output field has item->util if exists.

> Thank you for reviewing. I'm also debating. It's great to align
> "remote -v" and make it behave similarly to "branch -v". But it might
> not be worth it to complicate the code and break machine readers.
> Do we continue working on this?

You already know from my initial reaction what my answer would be,
but I am inclined to hear from others before we make a decision.

THanks.

  reply	other threads:[~2024-12-18 15:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-17 12:39 [PATCH] remote: align --verbose output with spaces Wang Bing-hua via GitGitGadget
2024-12-17 13:23 ` shejialuo
2024-12-17 15:24   ` Wang Bing-hua
2024-12-17 20:21   ` Junio C Hamano
2024-12-18  5:49     ` Wang Bing-hua
2024-12-18 13:52     ` shejialuo
2024-12-18 14:09       ` Wang Bing-hua
2024-12-17 17:18 ` [PATCH v2] " Wang Bing-hua via GitGitGadget
2024-12-17 20:47   ` Junio C Hamano
2024-12-18  8:37     ` Wang Bing-hua
2024-12-18 15:39       ` Junio C Hamano [this message]
2024-12-19  2:14         ` Wang Bing-hua

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqy10dt2zb.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=louiswpf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).