From: Junio C Hamano Date: Mon, 10 Jan 2022 19:52:49 +0000 (-0800) Subject: Merge branch 'jh/p4-human-unit-numbers' X-Git-Tag: v2.35.0-rc0~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66f6c18e5b8706f07a9a8cbd06942d4c7835f7d7;p=thirdparty%2Fgit.git Merge branch 'jh/p4-human-unit-numbers' 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 --- 66f6c18e5b8706f07a9a8cbd06942d4c7835f7d7 diff --cc git-p4.py index 986595bef0,a625077b83..1b5694500a --- a/git-p4.py +++ 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.