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". Note that git treats "core.bare =" the same as "core.bare = false", so the code had to become more complicated in order to treat the absense of a value differently than an empty value. Ugh.
This commit is contained in:
parent
ca9c6c5f60
commit
9cb69dbb76
8 changed files with 35 additions and 7 deletions
22
Git/Types.hs
22
Git/Types.hs
|
@ -1,12 +1,11 @@
|
|||
{- git data types
|
||||
-
|
||||
- Copyright 2010-2019 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
||||
|
||||
module Git.Types where
|
||||
|
||||
|
@ -18,6 +17,8 @@ import qualified Data.ByteString as S
|
|||
import System.Posix.Types
|
||||
import Utility.SafeCommand
|
||||
import Utility.FileSystemEncoding
|
||||
import qualified Data.Semigroup as Sem
|
||||
import Prelude
|
||||
|
||||
{- Support repositories on local disk, and repositories accessed via an URL.
|
||||
-
|
||||
|
@ -54,8 +55,20 @@ data Repo = Repo
|
|||
newtype ConfigKey = ConfigKey S.ByteString
|
||||
deriving (Ord, Eq)
|
||||
|
||||
newtype ConfigValue = ConfigValue S.ByteString
|
||||
deriving (Ord, Eq, Semigroup, Monoid)
|
||||
data ConfigValue
|
||||
= ConfigValue S.ByteString
|
||||
| NoConfigValue
|
||||
-- ^ git treats a setting with no value as different than a setting
|
||||
-- with an empty value
|
||||
deriving (Ord, Eq)
|
||||
|
||||
instance Sem.Semigroup ConfigValue where
|
||||
ConfigValue a <> ConfigValue b = ConfigValue (a <> b)
|
||||
a <> NoConfigValue = a
|
||||
NoConfigValue <> b = b
|
||||
|
||||
instance Monoid ConfigValue where
|
||||
mempty = ConfigValue mempty
|
||||
|
||||
instance Default ConfigValue where
|
||||
def = ConfigValue mempty
|
||||
|
@ -68,6 +81,7 @@ instance Show ConfigKey where
|
|||
|
||||
fromConfigValue :: ConfigValue -> String
|
||||
fromConfigValue (ConfigValue s) = decodeBS' s
|
||||
fromConfigValue NoConfigValue = mempty
|
||||
|
||||
instance Show ConfigValue where
|
||||
show = fromConfigValue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue