]> Kevux Git Server - rit/commit
git-p4: print size values in appropriate units
authorJoel Holdsworth <jholdsworth@nvidia.com>
Sun, 19 Dec 2021 15:40:27 +0000 (15:40 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Dec 2021 20:55:09 +0000 (12:55 -0800)
commitae9b9509a76e49cbf4fb254b2b75d566be6434a8
treeb79a318190e3cf0372e100c135b207105c95b048
parente9d7761bb94f20acc98824275e317fa82436c25d
git-p4: print size values in appropriate units

The git-p4 script reports file sizes in various log messages.
Previously, in each case the script would print them as the number of
bytes divided by 1048576 i.e. the size in mebibytes, rounded down to an
integer.  This resulted in small files being described as having a size
of "0 MB".

This patch replaces the existing behaviour with a new helper function:
format_size_human_readable, which takes a number of bytes (or any other
quantity), and computes the appropriate prefix to use: none, Ki, Mi, Gi,
Ti, Pi, Ei, Zi, Yi.

For example, a size of 123456 will now be printed as "120.6 KiB" greatly
improving the readability of the log output.

Large valued prefixes such as pebi, exbi, zebi and yobi are included for
completeness, though they not expected to appear in any real-world
Perforce repository!

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-p4.py