]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jh/p4-human-unit-numbers'
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Jan 2022 19:52:49 +0000 (11:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Jan 2022 19:52:49 +0000 (11:52 -0800)
The way "git p4" shows file sizes in its output has been updated to
use human-readable units.

* jh/p4-human-unit-numbers:
  git-p4: show progress as an integer
  git-p4: print size values in appropriate units

1  2 
git-p4.py

diff --cc git-p4.py
index 986595bef0c92f714c3b553d6b5b520c9cc387fe,a625077b83462885e75e84e37e44c72f21f90f32..1b5694500a942316aabc2eddd6b54afe556fff23
+++ b/git-p4.py
@@@ -56,9 -56,18 +56,21 @@@ defaultBlockSize = 1<<2
  
  p4_access_checked = False
  
 +re_ko_keywords = re.compile(br'\$(Id|Header)(:[^$\n]+)?\$')
 +re_k_keywords = re.compile(br'\$(Id|Header|Author|Date|DateTime|Change|File|Revision)(:[^$\n]+)?\$')
 +
+ def format_size_human_readable(num):
+     """ Returns a number of units (typically bytes) formatted as a human-readable
+         string.
+     """
+     if num < 1024:
+         return '{:d} B'.format(num)
+     for unit in ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
+         num /= 1024.0
+         if num < 1024.0:
+             return "{:3.1f} {}B".format(num, unit)
+     return "{:.1f} YiB".format(num)
  def p4_build_cmd(cmd):
      """Build a suitable p4 command line.