From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 81D951F54E for ; Wed, 10 Aug 2022 21:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232695AbiHJVUd (ORCPT ); Wed, 10 Aug 2022 17:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbiHJVUb (ORCPT ); Wed, 10 Aug 2022 17:20:31 -0400 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C19BC3 for ; Wed, 10 Aug 2022 14:20:30 -0700 (PDT) Received: (qmail 6915 invoked by uid 109); 10 Aug 2022 21:20:29 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 10 Aug 2022 21:20:29 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 15703 invoked by uid 111); 10 Aug 2022 21:20:29 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 10 Aug 2022 17:20:29 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 10 Aug 2022 17:20:28 -0400 From: Jeff King To: Junio C Hamano Cc: Li Linchao via GitGitGadget , git@vger.kernel.org, =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Johannes Sixt , Li Linchao Subject: Re: [PATCH v4] rev-list: support human-readable output for `--disk-usage` Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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