Subject: Re: [PATCH 2] count-objects: add human-readable size option

From: Marcus Griep <[email-masked]>
Date: Thu, 14 Aug 2008 10:26:07 -0400

Junio C Hamano wrote:
>     extern int human_readable(struct strbuf *,
>     			      double value, int precision,
>                               const char **unit);
> 
>     static const char **size_unit = {
>     	"byte", "KB", "MB", "GB", NULL,
>     };
>     static const char **throughput_unit = {
>     	"bps", "Kbps", "Mbps", "Gbps", NULL,
>     };
> 
>     human_readble(&sb, (double) bytes_transferred, 0, size_unit);
>     human_readble(&sb, (double) throughput, 2, throughput_unit);

Here's what I'm looking at as a new signature:

extern int strbuf_add_human_readable(struct strbuf *,
				double value, int maxlen,
				int scale, const char *suffix,
				int flags);

where 'maxlen' specifies the longest string that should be returned.
That will make it easier for any pretty-ish formatting like ls and
du use. A value of 0 is unlimited length.

'scale' is used to specify a boundary, above which value should be
reduced, and below which it should be reported. Commonly this is
1000.  If 0, then it will find a scale that best fits into 'maxlen'.
If both 'maxlen' and 'scale' are 0, then it will use the default
of 1000.

'suffix' is appended onto every formatted string.  This would often be
"", "B", "bps".

'flags' would provide the ability to switch between a binary (1024)
and an si (1000) period.  Also, adding a space between number and
unit.

On success, would return 0.  If maxlen is specified and there is not
enough space given the scale or an inordinately large value, return
-n, where n is the amount of additional length that would have been
needed.

Does this sound appropriate?

-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´