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

Re: [PATCH v4] rev-list: support human-readable output for `--disk-usage`

From
Jeff King <peff@peff.net>
Date
Aug 10, 2022, 21:20 UTC
Message-ID
<YvQhHOkjZatIqlFr@coredump.intra.peff.net>
In-Reply-To
<xmqqlerwm28n.fsf@gitster.g>
On Wed, Aug 10, 2022 at 10:34:32AM -0700, Junio C Hamano wrote:
Show 25 quoted lines
> > +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. ;)

Show 14 quoted lines
> > @@ -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
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 17 in “rev-list: support `--human-readable` option when applied `disk-usage`”
  1. rev-list: support `--human-readable` option when applied `disk-usage`Li Linchao via GitGitGadget, Aug 5, 2022
  2. Ævar Arnfjörð BjarmasonAug 5, 2022
  3. lilinchao@oschina.cnAug 5, 2022
  4. rev-list: support human-readable output for `--disk-usage`Li Linchao via GitGitGadget, Aug 8, 2022
  5. lilinchao@oschina.cnAug 8, 2022
  6. Jeff KingAug 9, 2022
  7. lilinchao@oschina.cnAug 9, 2022
  8. rev-list: support human-readable output for `--disk-usage`Li Linchao via GitGitGadget, Aug 10, 2022
  9. Johannes SixtAug 10, 2022
  10. rev-list: support human-readable output for `--disk-usage`Li Linchao via GitGitGadget, Aug 10, 2022
  11. Junio C HamanoAug 10, 2022
  12. Jeff KingAug 10, 2022
  13. Junio C HamanoAug 10, 2022
  14. Junio C HamanoAug 11, 2022
  15. Jeff KingAug 11, 2022
  16. rev-list: support human-readable output for `--disk-usage`Li Linchao via GitGitGadget, Aug 11, 2022
  17. Junio C HamanoAug 11, 2022

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.