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

Re: [PATCH v2] remote: align --verbose output with spaces

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 18, 2024, 15:39 UTC
Message-ID
<xmqqy10dt2zb.fsf@gitster.g>
In-Reply-To
<1812389a7b6fe18d.7946240d95ed36ca.1b2132d5c888cc21@host>
"Wang Bing-hua" <louiswpf@gmail.com> writes:
Show 15 quoted lines
>> 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.
Previous: Wang Bing-huaNext: Wang Bing-hua
Message 11 of 12 in “remote: align --verbose output with spaces”
  1. remote: align --verbose output with spacesWang Bing-hua via GitGitGadget, Dec 17, 2024
  2. shejialuoDec 17, 2024
  3. Wang Bing-huaDec 17, 2024
  4. Junio C HamanoDec 17, 2024
  5. Wang Bing-huaDec 18, 2024
  6. shejialuoDec 18, 2024
  7. Wang Bing-huaDec 18, 2024
  8. remote: align --verbose output with spacesWang Bing-hua via GitGitGadget, Dec 17, 2024
  9. Junio C HamanoDec 17, 2024
  10. Wang Bing-huaDec 18, 2024
  11. Junio C HamanoDec 18, 2024
  12. Wang Bing-huaDec 19, 2024

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.