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
This commit is contained in:
Joey Hess 2022-05-05 15:22:11 -04:00
parent 3d8af64527
commit d1cce869ed
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 47 additions and 7 deletions

View file

@ -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 <id@joeyh.name> 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,

View file

@ -1,6 +1,6 @@
{- data size display and parsing
-
- Copyright 2011 Joey Hess <id@joeyh.name>
- Copyright 2011-2022 Joey Hess <id@joeyh.name>
-
- 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]

View file

@ -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]]