fa62c98910
This eliminates the distinction between decodeBS and decodeBS', encodeBS and encodeBS', etc. The old implementation truncated at NUL, and the primed versions had to do extra work to avoid that problem. The new implementation does not truncate at NUL, and is also a lot faster. (Benchmarked at 2x faster for decodeBS and 3x for encodeBS; more for the primed versions.) Note that filepath-bytestring 1.4.2.1.8 contains the same optimisation, and upgrading to it will speed up to/fromRawFilePath. AFAIK, nothing relied on the old behavior of truncating at NUL. Some code used the faster versions in places where I was sure there would not be a NUL. So this change is unlikely to break anything. Also, moved s2w8 and w82s out of the module, as they do not involve filesystem encoding really. Sponsored-by: Shae Erisson on Patreon
50 lines
1.3 KiB
Haskell
50 lines
1.3 KiB
Haskell
{- git config types
|
|
-
|
|
- Copyright 2012, 2017 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Git.ConfigTypes where
|
|
|
|
import Data.Char
|
|
import qualified Data.ByteString.Char8 as S8
|
|
|
|
import Common
|
|
import Git
|
|
import Git.Types
|
|
import qualified Git.Config
|
|
|
|
data SharedRepository = UnShared | GroupShared | AllShared | UmaskShared Int
|
|
deriving (Eq)
|
|
|
|
getSharedRepository :: Repo -> SharedRepository
|
|
getSharedRepository r =
|
|
case Git.Config.getMaybe "core.sharedrepository" r of
|
|
Just (ConfigValue v) -> case S8.map toLower v of
|
|
"1" -> GroupShared
|
|
"2" -> AllShared
|
|
"group" -> GroupShared
|
|
"true" -> GroupShared
|
|
"all" -> AllShared
|
|
"world" -> AllShared
|
|
"everybody" -> AllShared
|
|
_ -> maybe UnShared UmaskShared (readish (decodeBS v))
|
|
Just NoConfigValue -> UnShared
|
|
Nothing -> UnShared
|
|
|
|
data DenyCurrentBranch = UpdateInstead | RefusePush | WarnPush | IgnorePush
|
|
deriving (Eq)
|
|
|
|
getDenyCurrentBranch :: Repo -> DenyCurrentBranch
|
|
getDenyCurrentBranch r =
|
|
case Git.Config.getMaybe "receive.denycurrentbranch" r of
|
|
Just (ConfigValue v) -> case S8.map toLower v of
|
|
"updateinstead" -> UpdateInstead
|
|
"warn" -> WarnPush
|
|
"ignore" -> IgnorePush
|
|
_ -> RefusePush
|
|
Just NoConfigValue -> RefusePush
|
|
Nothing -> RefusePush
|