diff options
Diffstat (limited to 'RemoteLog.hs')
-rw-r--r-- | RemoteLog.hs | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/RemoteLog.hs b/RemoteLog.hs index 149104fba..d49635b93 100644 --- a/RemoteLog.hs +++ b/RemoteLog.hs @@ -6,7 +6,6 @@ -} module RemoteLog ( - remoteLog, readRemoteLog, configSet, keyValToConfig, @@ -16,12 +15,14 @@ module RemoteLog ( ) where import qualified Data.Map as M +import Data.Time.Clock.POSIX import Data.Char import Common.Annex import qualified Annex.Branch import Types.Remote import UUID +import UUIDLog {- Filename of remote.log. -} remoteLog :: FilePath @@ -29,27 +30,20 @@ remoteLog = "remote.log" {- Adds or updates a remote's config in the log. -} configSet :: UUID -> RemoteConfig -> Annex () -configSet u c = Annex.Branch.change remoteLog $ - serialize . M.insert u c . remoteLogParse - where - serialize = unlines . sort . map toline . M.toList - toline (u', c') = u' ++ " " ++ unwords (configToKeyVal c') +configSet u c = do + ts <- liftIO $ getPOSIXTime + Annex.Branch.change remoteLog $ + showLog showConfig . changeLog ts u c . parseLog parseConfig {- Map of remotes by uuid containing key/value config maps. -} readRemoteLog :: Annex (M.Map UUID RemoteConfig) -readRemoteLog = remoteLogParse <$> Annex.Branch.get remoteLog +readRemoteLog = (simpleMap . parseLog parseConfig) <$> Annex.Branch.get remoteLog -remoteLogParse :: String -> M.Map UUID RemoteConfig -remoteLogParse s = - M.fromList $ mapMaybe parseline $ filter (not . null) $ lines s - where - parseline l - | length w > 2 = Just (u, c) - | otherwise = Nothing - where - w = words l - u = head w - c = keyValToConfig $ tail w +parseConfig :: String -> Maybe RemoteConfig +parseConfig = Just . keyValToConfig . words + +showConfig :: RemoteConfig -> String +showConfig = unwords . configToKeyVal {- Given Strings like "key=value", generates a RemoteConfig. -} keyValToConfig :: [String] -> RemoteConfig |