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

Re: [RFC Redux] strbuf: Add method to convert byte-size to human readable form

From
Marcus Griep <marcus@griep.us>
Date
Sep 19, 2008, 15:56 UTC
Message-ID
<48D3CBBA.8060507@griep.us>
In-Reply-To
<1221279997-9336-1-git-send-email-marcus@griep.us>

If there is no comment on this, Junio, would you be ok accepting this as a patch, even as a feature-branch on pu or next?

Marcus Griep wrote:
Show 38 quoted lines
> Takes a strbuf as its first argument and appends the human-readable
> form of 'value', the second argument, to that buffer.
> 
> e.g. strbuf_append_human_readable(sb, 1012, 0, 0, HR_SPACE)
> produces "0.9 Ki".
> 
> Documented in strbuf.h; units can be directly appended to the strbuf
> to produce "0.9 KiB/s", "0.9 KiB".
> 
> Supports SI magnitude prefixes as well as padding and spacing of
> the units portion of the output.
> 
> Also, add in test cases to ensure it produces the expected output
> and to demonstrate what different arguments do.
> 
> Signed-off-by: Marcus Griep <marcus@griep.us>
> ---
> 
>  This is a redux of a prior patch as part of a series on count-objects
>  but is now split off and submitted on its own as an RFC for a library
>  function to be added to strbuf.  If accepted, I'd like to standardize
>  upon this method for user visible byte-sizes, thoroughput, large object
>  counts, etc.
> 
>  Provides similar functionality similar to the '-h' size output of du
>  in the default case.
> 
>  Based on master, but also applies cleanly to next.
> 
>  .gitignore                |    1 +
>  Makefile                  |    2 +-
>  strbuf.c                  |   92 +++++++++++++++++++++++++++++++++++++++++++++
>  strbuf.h                  |   30 +++++++++++++++
>  t/t0031-human-readable.sh |   49 ++++++++++++++++++++++++
>  test-human-read.c         |   23 +++++++++++
>  6 files changed, 196 insertions(+), 1 deletions(-)
>  create mode 100755 t/t0031-human-readable.sh
>  create mode 100644 test-human-read.c
-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´
Previous: Marcus GriepNext: Junio C Hamano
Message 2 of 6 in “[RFC Redux] strbuf: Add method to convert byte-size to human readable form”
  1. Marcus GriepSep 13, 2008
  2. Marcus GriepSep 19, 2008
  3. Junio C HamanoSep 19, 2008
  4. Daniel BarkalowSep 19, 2008
  5. Junio C HamanoSep 19, 2008
  6. Junio C HamanoSep 19, 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.