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

Re: [PATCH v2 2/3] strbuf: Add method to convert byte-size to human readable form

From
Marcus Griep <marcus@griep.us>
Date
Aug 15, 2008, 00:46 UTC
Message-ID
<48A4D1DD.9060202@griep.us>
In-Reply-To
<20080814223429.GC10544@machine.or.cz>
Petr Baudis wrote:
> Frankly, I doubt this has too much value, and it complicates the code _a
> lot_. If you can't fit your stuff into pretty column, it's better to
> just print whatever you have to and disrupt the columns instead of
> _failing_, isn't it?

Generally, the only reason for such a failure would be requesting conflicting scale and maxlen values or requesting a maxlen which would be too small to reasonably display any value, hence an empty string and a number reporting how much more is necessary to get appropriate output.

In other words, a failure reports that you probably requested an irrational number for maxlen. It would probably be easier to understand if it were in terms of the numeric output rather than the entire string. If I change it that way, then there shouldn't be an "irrational" positive number to request, eliminating the need for these failures.

> Shouldn't pretty much all of this be documented in the code too?
Should I stuff this in comments in the header file, source file, or both?
Show 9 quoted lines
> My point still stands - in case of binary units, we should always
> consistently use the i suffix. So having an example in the commit
> message that advertises "bps" is simply wrong when it should read "iB/s"
> (like it does with the current progress.c code).
> 
> I may sound boring, but it seems to me that you're still ignoring my
> point quitly without proper counter-argumentation and I think it's an
> important want, and since it's so hard to keep things consistent across
> the wide Git codebase, we should do all we can to keep it.

From a consistency standpoint, I can certainly agree. It's not hard to implement. I wanted to avoid pigeon-holeing, but to keep our reporting consistent, using '*i' for all binaries works for me.

> Whitespace damage? Also at a lot of other places in your patch.

No damage. It was indicated to me that 80-ish was the preferred width, so I was trying to follow that. If that's not true in the C sources, I'll bundle things up a bit more.

Show 10 quoted lines
> Hmmm. We could have
> 
> +        char *hr_prefixes[] = {
> +		"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi", NULL
> +	};
> +        char *hr_si_prefixes[] = {
> +		"", "k", "M", "G", "T", "P", "E", "Z", "Y", NULL
> +	};
> 
> ;-)
Per previous, sounds good to me.

Overall, I was looking to create a generic function that could be used across Git without making assumptions of the consumer. Hence the maxlen, scale, SI, and space configurability.

Thanks for the input, and I'll work up another draft.
-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´
Previous: Marcus GriepNext: Shawn O. Pearce
Message 13 of 18 in “count-objects size and strbuf human-readable”
  1. 0/3 count-objects size and strbuf human-readableMarcus Griep, Aug 14, 2008
  2. 1/3 count-objects: Add total pack size to verbose outputMarcus Griep, Aug 14, 2008
  3. 2/3 strbuf: Add method to convert byte-size to human readable formMarcus Griep, Aug 14, 2008
  4. 3/3 count-objects: add human-readable size optionMarcus Griep, Aug 14, 2008
  5. Petr BaudisAug 14, 2008
  6. Marcus GriepAug 14, 2008
  7. Junio C HamanoAug 15, 2008
  8. Petr BaudisAug 14, 2008
  9. Junio C HamanoAug 14, 2008
  10. Petr BaudisAug 14, 2008
  11. Junio C HamanoAug 14, 2008
  12. Marcus GriepAug 15, 2008
  13. Marcus GriepAug 15, 2008
  14. Shawn O. PearceAug 15, 2008
  15. 1/3 count-objects: Add total pack size to verbose outputMarcus Griep, Aug 15, 2008
  16. 2/3 strbuf: Add method to convert byte-size to human readable formMarcus Griep, Aug 15, 2008
  17. 3/3 count-objects: add human-readable size optionMarcus Griep, Aug 15, 2008
  18. 1/3 count-objects: Add total pack size to verbose outputMarcus Griep, Aug 15, 2008

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.