diff options
author | Joey Hess <joey@kitenet.net> | 2011-10-06 16:07:51 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-10-06 16:07:58 -0400 |
commit | f011033869bbeeb7941c1c6e16a2a138b11c92e4 (patch) | |
tree | 09cf18fdfbc1fa29757baf45227e68d11e83062a /RemoteLog.hs | |
parent | f929d0229c05ebf0fe2c26d443fe6f843f270983 (diff) |
add timestamps to remote.log
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 |