]> dgit.raspbian.org Git - git-annex.git/commitdiff
support parsing numeric git configs as bool
authorJoey Hess <joeyh@joeyh.name>
Mon, 16 Nov 2020 14:09:25 +0000 (10:09 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 16 Nov 2020 14:09:25 +0000 (10:09 -0400)
I'm not sure if git documents it aside from 0 and 1, but any integer
can be interpreted as a bool by it. Doing the same in git-annex is good
for consistency. Also, I am planning a config that starts out as a
numeric range, but will later transition to a simple bool (hopefully),
which this interpretation supports well.

Git/Config.hs

index df16196ec0905940b61a7359c2a765bdfe8e9e17..ed4e661bb7862411f907cd7c39d7fd39e6833952 100644 (file)
@@ -186,6 +186,10 @@ isTrueFalse' (ConfigValue s)
        | s' == "0" = Just False
        | s' == "" = Just False
 
+       -- Git treats any number other than 0 as true,
+       -- including negative numbers.
+       | S8.all (\c -> isDigit c || c == '-') s' = Just True
+
        | otherwise = Nothing
   where
        s' = S8.map toLower s