include git-annex-shell back in

Also pushed ConfigKey down into the Git modules, which is the bulk of
the changes.
This commit is contained in:
Joey Hess 2019-12-02 10:57:09 -04:00
parent 65b88a0b99
commit f3047d7186
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
26 changed files with 101 additions and 82 deletions

View file

@ -22,15 +22,15 @@ import qualified Git.Construct
import Utility.UserInfo
{- Returns a single git config setting, or a default value if not set. -}
get :: S.ByteString -> S.ByteString -> Repo -> S.ByteString
get :: ConfigKey -> S.ByteString -> Repo -> S.ByteString
get key defaultValue repo = M.findWithDefault defaultValue key (config repo)
{- Returns a list with each line of a multiline config setting. -}
getList :: S.ByteString -> Repo -> [S.ByteString]
getList :: ConfigKey -> Repo -> [S.ByteString]
getList key repo = M.findWithDefault [] key (fullconfig repo)
{- Returns a single git config setting, if set. -}
getMaybe :: S.ByteString -> Repo -> Maybe S.ByteString
getMaybe :: ConfigKey -> Repo -> Maybe S.ByteString
getMaybe key repo = M.lookup key (config repo)
{- Runs git config and populates a repo with its config.
@ -100,7 +100,7 @@ store s repo = do
{- Stores a single config setting in a Repo, returning the new version of
- the Repo. Config settings can be updated incrementally. -}
store' :: S.ByteString -> S.ByteString -> Repo -> Repo
store' :: ConfigKey -> S.ByteString -> Repo -> Repo
store' k v repo = repo
{ config = M.singleton k v `M.union` config repo
, fullconfig = M.unionWith (++) (M.singleton k [v]) (fullconfig repo)
@ -137,7 +137,7 @@ updateLocation' r l = do
{- Parses git config --list or git config --null --list output into a
- config map. -}
parse :: S.ByteString -> M.Map S.ByteString [S.ByteString]
parse :: S.ByteString -> M.Map ConfigKey [S.ByteString]
parse s
| S.null s = M.empty
-- --list output will have a '=' in the first line
@ -152,7 +152,7 @@ parse s
firstline = S.takeWhile (/= nl) s
sep c = M.fromListWith (++)
. map (\(k,v) -> (k, [S.drop 1 v]))
. map (\(k,v) -> (ConfigKey k, [S.drop 1 v]))
. map (S.break (== c))
{- Checks if a string from git config is a true value. -}
@ -178,7 +178,7 @@ boolConfig' False = "false"
isBare :: Repo -> Bool
isBare r = fromMaybe False $ isTrue' =<< getMaybe coreBare r
coreBare :: S.ByteString
coreBare :: ConfigKey
coreBare = "core.bare"
{- Runs a command to get the configuration of a repo,
@ -205,8 +205,8 @@ fromFile r f = fromPipe r "git"
{- Changes a git config setting in the specified config file.
- (Creates the file if it does not already exist.) -}
changeFile :: FilePath -> S.ByteString -> S.ByteString -> IO Bool
changeFile f k v = boolSystem "git"
changeFile :: FilePath -> ConfigKey -> S.ByteString -> IO Bool
changeFile f (ConfigKey k) v = boolSystem "git"
[ Param "config"
, Param "--file"
, File f
@ -220,9 +220,9 @@ changeFile f k v = boolSystem "git"
- If unsetting the config fails, including in a read-only repo, or
- when the config is not set, returns Nothing.
-}
unset :: S.ByteString -> Repo -> IO (Maybe Repo)
unset k r = ifM (Git.Command.runBool ps r)
( return $ Just $ r { config = M.delete k (config r) }
unset :: ConfigKey -> Repo -> IO (Maybe Repo)
unset ck@(ConfigKey k) r = ifM (Git.Command.runBool ps r)
( return $ Just $ r { config = M.delete ck (config r) }
, return Nothing
)
where

View file

@ -28,7 +28,6 @@ import System.Posix.User
#endif
import qualified Data.Map as M
import Network.URI
import qualified Data.ByteString as S
import Common
import Git.Types
@ -139,7 +138,7 @@ remoteNamed n constructor = do
{- Sets the name of a remote based on the git config key, such as
- "remote.foo.url". -}
remoteNamedFromKey :: S.ByteString -> IO Repo -> IO Repo
remoteNamedFromKey :: ConfigKey -> IO Repo -> IO Repo
remoteNamedFromKey = remoteNamed . remoteKeyToRemoteName
{- Constructs a new Repo for one of a Repo's remotes using a given

View file

@ -100,14 +100,15 @@ getParticiantList globalconfigrepo repo remotename = KeyIds $ parse $ firstJust
parse (Just b) = words (decodeBS' b)
parse Nothing = []
remoteParticipantConfigKey :: RemoteName -> S.ByteString
remoteParticipantConfigKey :: RemoteName -> ConfigKey
remoteParticipantConfigKey = remoteConfigKey "gcrypt-participants"
remotePublishParticipantConfigKey :: RemoteName -> S.ByteString
remotePublishParticipantConfigKey :: RemoteName -> ConfigKey
remotePublishParticipantConfigKey = remoteConfigKey "gcrypt-publish-participants"
remoteSigningKey :: RemoteName -> S.ByteString
remoteSigningKey :: RemoteName -> ConfigKey
remoteSigningKey = remoteConfigKey "gcrypt-signingkey"
remoteConfigKey :: S.ByteString -> RemoteName -> S.ByteString
remoteConfigKey key remotename = "remote." <> encodeBS' remotename <> "." <> key
remoteConfigKey :: S.ByteString -> RemoteName -> ConfigKey
remoteConfigKey key remotename = ConfigKey $
"remote." <> encodeBS' remotename <> "." <> key

View file

@ -24,12 +24,13 @@ import Git.FilePath
#endif
{- Is a git config key one that specifies the location of a remote? -}
isRemoteKey :: S.ByteString -> Bool
isRemoteKey k = "remote." `S.isPrefixOf` k && ".url" `S.isSuffixOf` k
isRemoteKey :: ConfigKey -> Bool
isRemoteKey (ConfigKey k) = "remote." `S.isPrefixOf` k && ".url" `S.isSuffixOf` k
{- Get a remote's name from the config key that specifies its location. -}
remoteKeyToRemoteName :: S.ByteString -> RemoteName
remoteKeyToRemoteName = decodeBS' . S.intercalate "." . dropFromEnd 1 . drop 1 . S8.split '.'
remoteKeyToRemoteName :: ConfigKey -> RemoteName
remoteKeyToRemoteName (ConfigKey k) = decodeBS' $
S.intercalate "." $ dropFromEnd 1 $ drop 1 $ S8.split '.' k
{- Construct a legal git remote name out of an arbitrary input string.
-
@ -83,9 +84,9 @@ parseRemoteLocation s repo = ret $ calcloc s
where
replacement = decodeBS' $ S.drop (S.length prefix) $
S.take (S.length bestkey - S.length suffix) bestkey
(bestkey, bestvalue) = maximumBy longestvalue insteadofs
(ConfigKey bestkey, bestvalue) = maximumBy longestvalue insteadofs
longestvalue (_, a) (_, b) = compare b a
insteadofs = filterconfig $ \(k, v) ->
insteadofs = filterconfig $ \(ConfigKey k, v) ->
prefix `S.isPrefixOf` k &&
suffix `S.isSuffixOf` k &&
v `S.isPrefixOf` encodeBS l

View file

@ -1,6 +1,6 @@
{- git data types
-
- Copyright 2010-2018 Joey Hess <id@joeyh.name>
- Copyright 2010-2019 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -10,11 +10,12 @@
module Git.Types where
import Network.URI
import Data.String
import qualified Data.Map as M
import qualified Data.ByteString as S
import System.Posix.Types
import Utility.SafeCommand
import Utility.FileSystemEncoding
{- Support repositories on local disk, and repositories accessed via an URL.
-
@ -35,9 +36,9 @@ data RepoLocation
data Repo = Repo
{ location :: RepoLocation
, config :: M.Map S.ByteString S.ByteString
, config :: M.Map ConfigKey S.ByteString
-- a given git config key can actually have multiple values
, fullconfig :: M.Map S.ByteString [S.ByteString]
, fullconfig :: M.Map ConfigKey [S.ByteString]
-- remoteName holds the name used for this repo in some other
-- repo's list of remotes, when this repo is such a remote
, remoteName :: Maybe RemoteName
@ -48,6 +49,18 @@ data Repo = Repo
, gitGlobalOpts :: [CommandParam]
} deriving (Show, Eq, Ord)
newtype ConfigKey = ConfigKey S.ByteString
deriving (Ord, Eq)
fromConfigKey :: ConfigKey -> String
fromConfigKey (ConfigKey s) = decodeBS' s
instance Show ConfigKey where
show = fromConfigKey
instance IsString ConfigKey where
fromString = ConfigKey . encodeBS'
type RemoteName = String
{- A git ref. Can be a sha1, or a branch or tag name. -}