Re: [PATCH] remote: align columns on -v

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 07, 2023 at 03:52:38PM -0800, Kir Kolyshkin wrote:
> Currently, git remote -v produces a misaligned output when a remote name
> is more than 8 characters long (i.e. longer than a tab step). Here's how
> it looks like:
>
> giuseppe	https://github.com/giuseppe/runc (fetch)
> giuseppe	https://github.com/giuseppe/runc (push)
> kir	git@xxxxxxxxxx:kolyshkin/runc.git (fetch)
> kir	git@xxxxxxxxxx:kolyshkin/runc.git (push)
> lifubang	https://github.com/lifubang/runc (fetch)
> lifubang	https://github.com/lifubang/runc (push)
> marquiz	https://github.com/marquiz/runc (fetch)
> marquiz	https://github.com/marquiz/runc (push)
>
> Let's find the maximum width and use it for alignment.
>
> While at it, let's keep the \t in case some tools depend on it
> for parsing (there will still be trailing spaces in the remote name).
>
> With this change, the output is like this now:
>
> giuseppe 	https://github.com/giuseppe/runc (fetch)
> giuseppe 	https://github.com/giuseppe/runc (push)
> kir      	git@xxxxxxxxxx:kolyshkin/runc.git (fetch)
> kir      	git@xxxxxxxxxx:kolyshkin/runc.git (push)
> lifubang 	https://github.com/lifubang/runc (fetch)
> lifubang 	https://github.com/lifubang/runc (push)
> marquiz  	https://github.com/marquiz/runc (fetch)
> marquiz  	https://github.com/marquiz/runc (push)
>

Thanks for working on that  - I had the same wish as well.
However, I am tempted to comment on some details here.
Especially, what happens if a remote is named with a non-ASCII
character (unicode code point would be a better term) ?
To determine the width on screen for aligment, strlen()
does the wrong thing here.
This has been done at other place (being UTF-8 aware),
you may want to have a look at this change:

  commit 12fc4ad89e23af642a8614371ff80bc67cb3315d
  Author: Torsten Bögershausen <tboegi@xxxxxx>
  Date:   Wed Sep 14 17:13:33 2022 +0200

      diff.c: use utf8_strwidth() to count display width



> Reported-by: Roman Dodin <dodin.roman@xxxxxxxxx>
> Signed-off-by: Kir Kolyshkin <kolyshkin@xxxxxxxxx>
> ---
>  builtin/remote.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/remote.c b/builtin/remote.c
> index 729f6f3643..116417574d 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -1245,13 +1245,21 @@ static int show_all(void)
>  	result = for_each_remote(get_one_entry, &list);
>
>  	if (!result) {
> -		int i;
> +		int i, width = 7;
> +
> +		if (verbose) {
> +			for (i = 0; i < list.nr; i++) {
> +				int len = strlen((list.items + i)->string);
> +				if (len > width)
> +					width = len;
> +			}
> +		}
>
>  		string_list_sort(&list);
>  		for (i = 0; i < list.nr; i++) {
>  			struct string_list_item *item = list.items + i;
>  			if (verbose)
> -				printf("%s\t%s\n", item->string,
> +				printf("%-*s\t%s\n", width, item->string,
>  					item->util ? (const char *)item->util : "");
>  			else {
>  				if (i && !strcmp((item - 1)->string, item->string))
> --
> 2.39.0
>




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux