all commands building except for assistant

also, changed ConfigValue to a newtype, and moved it into Git.Config.
This commit is contained in:
Joey Hess 2019-12-05 14:36:43 -04:00
parent 718fa83da6
commit c20f4704a7
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
40 changed files with 187 additions and 174 deletions

View file

@ -6,8 +6,8 @@
-}
module Logs.Config (
ConfigKey,
ConfigValue,
ConfigKey(..),
ConfigValue(..),
setGlobalConfig,
unsetGlobalConfig,
getGlobalConfig,
@ -18,7 +18,7 @@ import Annex.Common
import Logs
import Logs.MapLog
import qualified Annex.Branch
import Git.Types (ConfigKey(..))
import Git.Types (ConfigKey(..), ConfigValue(..))
import qualified Data.Map as M
import qualified Data.ByteString as S
@ -26,8 +26,6 @@ import qualified Data.ByteString.Lazy as L
import qualified Data.Attoparsec.ByteString.Lazy as A
import Data.ByteString.Builder
type ConfigValue = S.ByteString
setGlobalConfig :: ConfigKey -> ConfigValue -> Annex ()
setGlobalConfig name new = do
curr <- getGlobalConfig name
@ -44,7 +42,8 @@ unsetGlobalConfig :: ConfigKey -> Annex ()
unsetGlobalConfig name = do
curr <- getGlobalConfig name
when (curr /= Nothing) $
setGlobalConfig' name mempty -- set to empty string to unset
-- set to empty string to unset
setGlobalConfig' name (ConfigValue mempty)
-- Reads the global config log every time.
getGlobalConfig :: ConfigKey -> Annex (Maybe ConfigValue)
@ -53,15 +52,17 @@ getGlobalConfig name = M.lookup name <$> loadGlobalConfig
buildGlobalConfig :: MapLog ConfigKey ConfigValue -> Builder
buildGlobalConfig = buildMapLog configkeybuilder valuebuilder
where
configkeybuilder (ConfigKey f) = byteString f
valuebuilder = byteString
configkeybuilder (ConfigKey k) = byteString k
valuebuilder (ConfigValue v) = byteString v
parseGlobalConfig :: L.ByteString -> MapLog ConfigKey ConfigValue
parseGlobalConfig = parseMapLog configkeyparser valueparser
where
configkeyparser = ConfigKey <$> A.takeByteString
valueparser = A.takeByteString
valueparser = ConfigValue <$> A.takeByteString
loadGlobalConfig :: Annex (M.Map ConfigKey ConfigValue)
loadGlobalConfig = M.filter (not . S.null) . simpleMap . parseGlobalConfig
loadGlobalConfig = M.filter (\(ConfigValue v) -> not (S.null v))
. simpleMap
. parseGlobalConfig
<$> Annex.Branch.get configLog