]> dgit.raspbian.org Git - git-annex.git/commitdiff
When parsing git configs, support all the documented ways to write true and false...
authorJoey Hess <joeyh@joeyh.name>
Mon, 13 Apr 2020 17:45:40 +0000 (13:45 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 13 Apr 2020 18:05:30 +0000 (14:05 -0400)
This change does impact git-annex config
eg "git annex config --set annex.addunlocked on"
will store "on" and new git-annex will understand that value, while
old git-annex will error:
git-annex: bad annex.addunlocked configuration in git annex config:
Parse failure: near "on"
That seems acceptable.

Not special remote configs that are only documented as =true or =false
however. Having git-annex support other values for those would break
backwards compatability when used with old versions of git-annex. And
older versions ignore invalid special remote configs.. That would not
be a good combination.

Annex/SpecialRemote.hs
Annex/SpecialRemote/Config.hs
CHANGELOG
Git/Config.hs

index 4e55c399b6f000fc272773a789b3057b0b4cccff..165f2f8ea1f45ad873c57c673e2ea8da20374ef6 100644 (file)
@@ -22,7 +22,6 @@ import Config
 import Remote.List
 import Logs.Remote
 import Logs.Trust
-import qualified Git.Config
 import qualified Types.Remote as Remote
 import Git.Types (RemoteName)
 
@@ -99,7 +98,7 @@ autoEnable = do
                        _ -> return ()
   where
        configured rc = fromMaybe False $
-               Git.Config.isTrueFalse . fromProposedAccepted
+               trueFalseParser' . fromProposedAccepted
                        =<< M.lookup autoEnableField rc
        canenable u = (/= DeadTrusted) <$> lookupTrust u
        getenabledremotes = M.fromList
index 5e0e85f2f4f8dd381d415dbf17295ea2200115d8..df5eb11054a8123c3f7398b32d68cd3dd5afe9e4 100644 (file)
@@ -17,7 +17,6 @@ import Types.UUID
 import Types.ProposedAccepted
 import Types.RemoteConfig
 import Types.GitConfig
-import qualified Git.Config
 
 import qualified Data.Map as M
 import qualified Data.Set as S
@@ -242,9 +241,17 @@ yesNoParser f v fd = genParser yesno f v fd
        yesno _ = Nothing
 
 trueFalseParser :: RemoteConfigField -> Bool -> FieldDesc -> RemoteConfigFieldParser
-trueFalseParser f v fd = genParser Git.Config.isTrueFalse f v fd
+trueFalseParser f v fd = genParser trueFalseParser' f v fd
        (Just (ValueDesc "true or false"))
 
+-- Not using Git.Config.isTrueFalse because git supports
+-- a lot of other values for true and false in its configs,
+-- and this is not a git config and we want to avoid that mess.
+trueFalseParser' :: String -> Maybe Bool
+trueFalseParser' "true" = Just True
+trueFalseParser' "false" = Just False
+trueFalseParser' _ = Nothing
+
 genParser
        :: Typeable t
        => (String -> Maybe t)
index 603ff20f7d463efc918c1f87bc81590fef03c50c..8b0d372eb00e2ff4484f462fd2f94e3e9d53d55a 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,8 @@ git-annex (8.20200331) UNRELEASED; urgency=medium
   * Fix a potential failure to parse git config.
   * Support boolean git configs that are represented by the name of the
     setting with no value, eg "core.bare" is the same as "core.bare = true".
+  * When parsing git configs, support all the documented ways to write
+    true and false, including "yes", "on", "1", etc.
 
  -- Joey Hess <id@joeyh.name>  Mon, 30 Mar 2020 15:58:34 -0400
 
index 54370865a0fe45403af6ca93974e4bc635b5a269..f50d5eb534f1a9807df6884ad4b010fcde1e9870 100644 (file)
@@ -166,8 +166,17 @@ isTrueFalse = isTrueFalse' . ConfigValue . encodeBS'
 
 isTrueFalse' :: ConfigValue -> Maybe Bool
 isTrueFalse' (ConfigValue s)
+       | s' == "yes" = Just True
+       | s' == "on" = Just True
        | s' == "true" = Just True
+       | s' == "1" = Just True
+
+       | s' == "no" = Just False
+       | s' == "off" = Just False
        | s' == "false" = Just False
+       | s' == "0" = Just False
+       | s' == "" = Just False
+
        | otherwise = Nothing
   where
        s' = S8.map toLower s