2013-01-01 17:52:47 +00:00
|
|
|
{- git-annex configuration
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Types.GitConfig (
|
|
|
|
GitConfig(..),
|
|
|
|
extractGitConfig,
|
|
|
|
RemoteGitConfig(..),
|
|
|
|
extractRemoteGitConfig,
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Common
|
|
|
|
import qualified Git
|
|
|
|
import qualified Git.Config
|
|
|
|
import Utility.DataUnits
|
2013-03-13 20:16:01 +00:00
|
|
|
import Config.Cost
|
2013-01-01 17:52:47 +00:00
|
|
|
|
|
|
|
{- Main git-annex settings. Each setting corresponds to a git-config key
|
|
|
|
- such as annex.foo -}
|
|
|
|
data GitConfig = GitConfig
|
|
|
|
{ annexVersion :: Maybe String
|
|
|
|
, annexNumCopies :: Int
|
|
|
|
, annexDiskReserve :: Integer
|
|
|
|
, annexDirect :: Bool
|
|
|
|
, annexBackends :: [String]
|
|
|
|
, annexQueueSize :: Maybe Int
|
|
|
|
, annexBloomCapacity :: Maybe Int
|
|
|
|
, annexBloomAccuracy :: Maybe Int
|
|
|
|
, annexSshCaching :: Maybe Bool
|
|
|
|
, annexAlwaysCommit :: Bool
|
|
|
|
, annexDelayAdd :: Maybe Int
|
|
|
|
, annexHttpHeaders :: [String]
|
|
|
|
, annexHttpHeadersCommand :: Maybe String
|
2013-01-27 11:43:05 +00:00
|
|
|
, annexAutoCommit :: Bool
|
2013-01-27 13:33:19 +00:00
|
|
|
, annexWebOptions :: [String]
|
2013-04-09 03:34:05 +00:00
|
|
|
, annexWebDownloadCommand :: Maybe String
|
2013-02-14 18:10:36 +00:00
|
|
|
, annexCrippledFileSystem :: Bool
|
2013-03-29 20:17:13 +00:00
|
|
|
, annexLargeFiles :: Maybe String
|
2013-02-15 20:02:35 +00:00
|
|
|
, coreSymlinks :: Bool
|
2013-01-01 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extractGitConfig :: Git.Repo -> GitConfig
|
|
|
|
extractGitConfig r = GitConfig
|
2013-02-15 20:02:35 +00:00
|
|
|
{ annexVersion = notempty $ getmaybe (annex "version")
|
|
|
|
, annexNumCopies = get (annex "numcopies") 1
|
2013-01-01 17:52:47 +00:00
|
|
|
, annexDiskReserve = fromMaybe onemegabyte $
|
2013-02-15 20:02:35 +00:00
|
|
|
readSize dataUnits =<< getmaybe (annex "diskreserve")
|
|
|
|
, annexDirect = getbool (annex "direct") False
|
|
|
|
, annexBackends = getwords (annex "backends")
|
|
|
|
, annexQueueSize = getmayberead (annex "queuesize")
|
|
|
|
, annexBloomCapacity = getmayberead (annex "bloomcapacity")
|
|
|
|
, annexBloomAccuracy = getmayberead (annex "bloomaccuracy")
|
|
|
|
, annexSshCaching = getmaybebool (annex "sshcaching")
|
|
|
|
, annexAlwaysCommit = getbool (annex "alwayscommit") True
|
|
|
|
, annexDelayAdd = getmayberead (annex "delayadd")
|
|
|
|
, annexHttpHeaders = getlist (annex "http-headers")
|
|
|
|
, annexHttpHeadersCommand = getmaybe (annex "http-headers-command")
|
|
|
|
, annexAutoCommit = getbool (annex "autocommit") True
|
|
|
|
, annexWebOptions = getwords (annex "web-options")
|
2013-04-09 03:34:05 +00:00
|
|
|
, annexWebDownloadCommand = getmaybe (annex "web-download-command")
|
2013-02-15 20:02:35 +00:00
|
|
|
, annexCrippledFileSystem = getbool (annex "crippledfilesystem") False
|
2013-03-29 20:17:13 +00:00
|
|
|
, annexLargeFiles = getmaybe (annex "largefiles")
|
2013-02-15 20:02:35 +00:00
|
|
|
, coreSymlinks = getbool "core.symlinks" True
|
2013-01-01 17:52:47 +00:00
|
|
|
}
|
|
|
|
where
|
|
|
|
get k def = fromMaybe def $ getmayberead k
|
|
|
|
getbool k def = fromMaybe def $ getmaybebool k
|
|
|
|
getmaybebool k = Git.Config.isTrue =<< getmaybe k
|
|
|
|
getmayberead k = readish =<< getmaybe k
|
2013-02-15 20:02:35 +00:00
|
|
|
getmaybe k = Git.Config.getMaybe k r
|
|
|
|
getlist k = Git.Config.getList k r
|
2013-01-27 13:33:19 +00:00
|
|
|
getwords k = fromMaybe [] $ words <$> getmaybe k
|
2013-01-01 17:52:47 +00:00
|
|
|
|
2013-02-15 20:02:35 +00:00
|
|
|
annex k = "annex." ++ k
|
2013-01-01 17:52:47 +00:00
|
|
|
|
|
|
|
onemegabyte = 1000000
|
|
|
|
|
|
|
|
{- Per-remote git-annex settings. Each setting corresponds to a git-config
|
|
|
|
- key such as <remote>.annex-foo, or if that is not set, a default from
|
|
|
|
- annex.foo -}
|
|
|
|
data RemoteGitConfig = RemoteGitConfig
|
2013-03-13 20:16:01 +00:00
|
|
|
{ remoteAnnexCost :: Maybe Cost
|
2013-01-01 17:52:47 +00:00
|
|
|
, remoteAnnexCostCommand :: Maybe String
|
|
|
|
, remoteAnnexIgnore :: Bool
|
|
|
|
, remoteAnnexSync :: Bool
|
|
|
|
, remoteAnnexTrustLevel :: Maybe String
|
|
|
|
, remoteAnnexStartCommand :: Maybe String
|
|
|
|
, remoteAnnexStopCommand :: Maybe String
|
|
|
|
|
2013-04-04 19:46:33 +00:00
|
|
|
{- These settings are specific to particular types of remotes
|
|
|
|
- including special remotes. -}
|
2013-01-01 17:52:47 +00:00
|
|
|
, remoteAnnexSshOptions :: [String]
|
|
|
|
, remoteAnnexRsyncOptions :: [String]
|
2013-04-13 22:10:49 +00:00
|
|
|
, remoteAnnexRsyncTransport :: [String]
|
2013-03-11 01:33:13 +00:00
|
|
|
, remoteAnnexGnupgOptions :: [String]
|
2013-01-01 17:52:47 +00:00
|
|
|
, remoteAnnexRsyncUrl :: Maybe String
|
|
|
|
, remoteAnnexBupRepo :: Maybe String
|
|
|
|
, remoteAnnexBupSplitOptions :: [String]
|
|
|
|
, remoteAnnexDirectory :: Maybe FilePath
|
|
|
|
, remoteAnnexHookType :: Maybe String
|
2013-04-04 19:46:33 +00:00
|
|
|
{- A regular git remote's git repository config. -}
|
|
|
|
, remoteGitConfig :: Maybe GitConfig
|
2013-01-01 17:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extractRemoteGitConfig :: Git.Repo -> String -> RemoteGitConfig
|
|
|
|
extractRemoteGitConfig r remotename = RemoteGitConfig
|
|
|
|
{ remoteAnnexCost = getmayberead "cost"
|
|
|
|
, remoteAnnexCostCommand = notempty $ getmaybe "cost-command"
|
|
|
|
, remoteAnnexIgnore = getbool "ignore" False
|
|
|
|
, remoteAnnexSync = getbool "sync" True
|
|
|
|
, remoteAnnexTrustLevel = notempty $ getmaybe "trustlevel"
|
|
|
|
, remoteAnnexStartCommand = notempty $ getmaybe "start-command"
|
|
|
|
, remoteAnnexStopCommand = notempty $ getmaybe "stop-command"
|
|
|
|
|
|
|
|
, remoteAnnexSshOptions = getoptions "ssh-options"
|
|
|
|
, remoteAnnexRsyncOptions = getoptions "rsync-options"
|
2013-04-13 22:10:49 +00:00
|
|
|
, remoteAnnexRsyncTransport = getoptions "rsync-transport"
|
2013-03-11 01:33:13 +00:00
|
|
|
, remoteAnnexGnupgOptions = getoptions "gnupg-options"
|
2013-01-01 17:52:47 +00:00
|
|
|
, remoteAnnexRsyncUrl = notempty $ getmaybe "rsyncurl"
|
|
|
|
, remoteAnnexBupRepo = getmaybe "buprepo"
|
|
|
|
, remoteAnnexBupSplitOptions = getoptions "bup-split-options"
|
|
|
|
, remoteAnnexDirectory = notempty $ getmaybe "directory"
|
|
|
|
, remoteAnnexHookType = notempty $ getmaybe "hooktype"
|
2013-04-04 19:46:33 +00:00
|
|
|
, remoteGitConfig = Nothing
|
2013-01-01 17:52:47 +00:00
|
|
|
}
|
|
|
|
where
|
|
|
|
getbool k def = fromMaybe def $ getmaybebool k
|
|
|
|
getmaybebool k = Git.Config.isTrue =<< getmaybe k
|
|
|
|
getmayberead k = readish =<< getmaybe k
|
2013-04-03 07:52:41 +00:00
|
|
|
getmaybe k = mplus (Git.Config.getMaybe (key k) r)
|
|
|
|
(Git.Config.getMaybe (remotekey k) r)
|
2013-01-01 17:52:47 +00:00
|
|
|
getoptions k = fromMaybe [] $ words <$> getmaybe k
|
|
|
|
|
|
|
|
key k = "annex." ++ k
|
|
|
|
remotekey k = "remote." ++ remotename ++ ".annex-" ++ k
|
|
|
|
|
|
|
|
notempty :: Maybe String -> Maybe String
|
|
|
|
notempty Nothing = Nothing
|
|
|
|
notempty (Just "") = Nothing
|
|
|
|
notempty (Just s) = Just s
|
|
|
|
|