git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Li Linchao via GitGitGadget" <gitgitgadget@gmail.com>,
	git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Johannes Sixt" <j6t@kdbg.org>,
	"Li Linchao" <lilinchao@oschina.cn>
Subject: Re: [PATCH v4] rev-list: support human-readable output for `--disk-usage`
Date: Wed, 10 Aug 2022 17:20:28 -0400	[thread overview]
Message-ID: <YvQhHOkjZatIqlFr@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqlerwm28n.fsf@gitster.g>

On Wed, Aug 10, 2022 at 10:34:32AM -0700, Junio C Hamano wrote:

> > +static void print_disk_usage(off_t size)
> > +{
> > +	struct strbuf sb = STRBUF_INIT;
> > +	if (human_readable)
> > +		strbuf_humanise_bytes(&sb, size);
> > +	else
> > +		strbuf_addf(&sb, "%"PRIuMAX, (uintmax_t)size);
> > +	puts(sb.buf);
> > +	strbuf_release(&sb);
> > +}
> 
> Hmph, I am not sure if we want to make it a helper like this.  The
> normal case does not need to prepare the string into a strbuf but
> just can send the output to the standard output stream.
> 
> It is probably easy to fix, like so:
> 
> 	if (!human_readable) {
> 		printf("%" PRIuMAX "\n", disk_usage);
> 	} else {
> 		strbuf sb = STRBUF_INIT;
> 		strbuf_humanise_bytes(&sb, disk_usage);
> 		puts(sb.buf);
> 		strbuf_release(&sb);
> 	}

It was my suggestion to turn it into a helper, because the same code
needs to be present in two distant spots (the bitmap and non-bitmap
cases).

I don't care much between "printf directly vs strbuf" for the non-human
case, but it was an earlier review suggestion to connect them. I do
think the result is a little easier to follow, but mostly I want to make
it clear that the author is getting stuck between warring review
comments here. ;)

> > @@ -481,8 +495,8 @@ static int try_bitmap_disk_usage(struct rev_info *revs,
> >  	if (!bitmap_git)
> >  		return -1;
> >  
> > -	printf("%"PRIuMAX"\n",
> > -	       (uintmax_t)get_disk_usage_from_bitmap(bitmap_git, revs));
> > +	size_from_bitmap = get_disk_usage_from_bitmap(bitmap_git, revs);
> > +	print_disk_usage(size_from_bitmap);
> 
> It makes sense to make the function declare how it gets disk usage
> in its name, but once we call the function to get what we want,
> there is no need to keep saying we got it from bitmap.  If we ever
> gained another function that obtains the disk usage from other
> means, then this part of the code would become

Keep in mind that we are in try_bitmap_disk_usage() here. :) There is
indeed similar code to use other means, but it's far away, and this code
will always use bitmaps.

That said, I'd have just written:

  print_disk_usage(get_disk_usage_from_bitmap(bitmap_git, revs));

since the variable is not otherwise used. But arguably that's harder to
read.

-Peff

  reply	other threads:[~2022-08-10 21:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05  7:54 [PATCH] rev-list: support `--human-readable` option when applied `disk-usage` Li Linchao via GitGitGadget
2022-08-05 10:03 ` Ævar Arnfjörð Bjarmason
2022-08-05 11:01   ` lilinchao
2022-08-08  8:35 ` [PATCH v2] rev-list: support human-readable output for `--disk-usage` Li Linchao via GitGitGadget
2022-08-08  9:37   ` lilinchao
2022-08-09 13:22   ` Jeff King
2022-08-09 16:46     ` lilinchao
2022-08-10  6:01   ` [PATCH v3] " Li Linchao via GitGitGadget
2022-08-10  7:18     ` Johannes Sixt
2022-08-10 11:14     ` [PATCH v4] " Li Linchao via GitGitGadget
2022-08-10 17:34       ` Junio C Hamano
2022-08-10 21:20         ` Jeff King [this message]
2022-08-10 21:25           ` Junio C Hamano
2022-08-11  5:20           ` Junio C Hamano
2022-08-11  8:38             ` Jeff King
2022-08-11  4:47       ` [PATCH v5] " Li Linchao via GitGitGadget
2022-08-11 20:49         ` Junio C Hamano

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=YvQhHOkjZatIqlFr@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=lilinchao@oschina.cn \
    /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).