From: Joey Hess Date: Thu, 5 May 2022 19:22:11 +0000 (-0400) Subject: implement dataUnits finally X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~72^2~281 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d1cce869ede0cb9e5a01e83ce2dbbbd740182817;p=git-annex.git implement dataUnits finally Added support for "megabit" and related bandwidth units in annex.stalldetection and everywhere else that git-annex parses data units. Note that the short form is "Mbit" not "Mb" because that differs from "MB" only in case, and git-annex parses units case-insensitively. It would be horrible if two different versions of git-annex parsed the same value differently, so I don't think "Mb" can be supported. See comment for bonus sad story from my childhood. Sponsored-by: Nicholas Golder-Manning --- diff --git a/CHANGELOG b/CHANGELOG index b391c69860..506f3cd0e7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,13 @@ +git-annex (10.20220505) UNRELEASED; urgency=medium + + * Added support for "megabit" and related bandwidth units + in annex.stalldetection and everywhere else that git-annex parses + data units. Note that the short form is "Mbit" not "Mb" because + that differs from "MB" only in case, and git-annex parses units + case-insensitively. + + -- Joey Hess Thu, 05 May 2022 15:08:07 -0400 + git-annex (10.20220504) upstream; urgency=medium * Ignore annex.numcopies set to 0 in gitattributes or git config, diff --git a/Utility/DataUnits.hs b/Utility/DataUnits.hs index a6c9ffcf19..7fe4a0a4ae 100644 --- a/Utility/DataUnits.hs +++ b/Utility/DataUnits.hs @@ -1,6 +1,6 @@ {- data size display and parsing - - - Copyright 2011 Joey Hess + - Copyright 2011-2022 Joey Hess - - License: BSD-2-clause - @@ -22,13 +22,19 @@ - - So, a committee was formed. And it arrived at a committee-like decision, - which satisfied noone, confused everyone, and made the world an uglier - - place. As with all committees, this was meh. + - place. As with all committees, this was meh. Or in this case, "mib". - - And the drive manufacturers happily continued selling drives that are - increasingly smaller than you'd expect, if you don't count on your - fingers. But that are increasingly too big for anyone to much notice. - This caused me to need git-annex. - + - Meanwhile, over in telecommunications land, they were using entirely + - different units that differ only in capitalization sometimes. + - (At one point this convinced me that it was a good idea to buy an ISDN + - line because 128 kb/s sounded really fast! But it was really only 128 + - kbit/s...) + - - Thus, I use units here that I loathe. Because if I didn't, people would - be confused that their drives seem the wrong size, and other people would - complain at me for not being standards compliant. And we call this @@ -62,7 +68,7 @@ data Unit = Unit ByteSize Abbrev Name deriving (Ord, Show, Eq) dataUnits :: [Unit] -dataUnits = storageUnits ++ memoryUnits +dataUnits = storageUnits ++ memoryUnits ++ bandwidthUnits {- Storage units are (stupidly) powers of ten. -} storageUnits :: [Unit] @@ -75,7 +81,7 @@ storageUnits = , Unit (p 3) "GB" "gigabyte" , Unit (p 2) "MB" "megabyte" , Unit (p 1) "kB" "kilobyte" -- weird capitalization thanks to committe - , Unit (p 0) "B" "byte" + , Unit 1 "B" "byte" ] where p :: Integer -> Integer @@ -92,15 +98,33 @@ memoryUnits = , Unit (p 3) "GiB" "gibibyte" , Unit (p 2) "MiB" "mebibyte" , Unit (p 1) "KiB" "kibibyte" - , Unit (p 0) "B" "byte" + , Unit 1 "B" "byte" ] where p :: Integer -> Integer p n = 2^(n*10) -{- Bandwidth units are only measured in bits if you're some crazy telco. -} +{- Bandwidth units are (stupidly) measured in bits, not bytes, and are + - (also stupidly) powers of ten. + - + - While it's fairly common for "Mb", "Gb" etc to be used, that differs + - from "MB", "GB", etc only in case, and readSize is case-insensitive. + - So "Mbit", "Gbit" etc are used instead to avoid parsing ambiguity. + -} bandwidthUnits :: [Unit] -bandwidthUnits = error "stop trying to rip people off" +bandwidthUnits = + [ Unit (p 8) "Ybit" "yottabit" + , Unit (p 7) "Zbit" "zettabit" + , Unit (p 6) "Ebit" "exabit" + , Unit (p 5) "Pbit" "petabit" + , Unit (p 4) "Tbit" "terabit" + , Unit (p 3) "Gbit" "gigabit" + , Unit (p 2) "Mbit" "megabit" + , Unit (p 1) "kbit" "kilobit" -- weird capitalization thanks to committe + ] + where + p :: Integer -> Integer + p n = (1000^n) `div` 8 {- Do you yearn for the days when men were men and megabytes were megabytes? -} oldSchoolUnits :: [Unit] diff --git a/doc/todo/Mbps.mdwn b/doc/todo/Mbps.mdwn index 8710bdd7c2..a411df7310 100644 --- a/doc/todo/Mbps.mdwn +++ b/doc/todo/Mbps.mdwn @@ -9,3 +9,9 @@ and match up with the other bandwidth displays. This might make sense as a per-remote configurable value. Allowing using MiB/s for a hard drive and Mbps for a network remote. --[[Joey]] + +> I've implemented bandwidthUnits now, but it's not used for display yet. +> It is possible to specify such units in eg annex.stalldetection now. +> Note that it uses Mbit, not Mb because that is just confusingly close to +> "MB" and git-annex parses data units case insensitively. So the actual +> display will end up being "Mbit/s" rather than Mbps probably. --[[Joey]]