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
Junio C Hamano <gitster@pobox.com>
Date
Aug 14, 2008, 23:04 UTC
Message-ID
<7viqu3ci5k.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080814223429.GC10544@machine.or.cz>
Petr Baudis <pasky@suse.cz> writes:
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.

I pretty much agree with everything you said in this thread. In addition, I wonder if we would want to be able to say:

	960 bps
        0.9 KiB/s
	2.3 MiB/s

IOW, I do not think it is a good idea to have the list of "prefixes" in this function and force callers to _append_ unit. You might be better off by making the interface to the function to pass something like this:

	struct human_unit {
		char *unitname;
                unsigned long valuescale;
	} bps_to_human[] = {
        	{ "bps", 1 },
                { "KiB/s", 1024 },
                { "MiB/s", 1024 * 1024 },
                { NULL, 0 },
	};

and perhaps give canned set of unit list for sizes and throughputs as convenience.

By doing so, you could even do this:
	struct human_unit bits_to_human[] = {
        	{ "bits", 1 },
                { "bytes", 8 },
                { "Kbytes", 8 * 1024 },
                { "Mbytes", 8 * 1024 * 1024 },
                { NULL, 0 },
	};

I also am not particularly happy about using "double" in this API. Most of the callers that gather stats in the rest of the codebase count in (long) integers as far as I can tell, and it may be conceptually cleaner to keep the use of double as an internal implementation issue of this particular function.

Previous: Petr BaudisNext: Petr Baudis
Message 9 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.