diff options
author | Joey Hess <joey@kitenet.net> | 2011-10-06 15:31:25 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-10-06 15:31:25 -0400 |
commit | 3e0d2a080333f3566312da0e1982739873603457 (patch) | |
tree | f168ffd2f7cd18f1070f7e18f6e6d8694cbd27a3 /UUID.hs | |
parent | 52fa4096480ba74c355dffcddbda766994f4d5b7 (diff) |
add timestamp to uuid.log
* New or changed repository descriptions in uuid.log now have a timestamp,
which is used to ensure the newest description is used when the uuid.log
has been merged.
* Note that older versions of git-annex will display the timestamp as part
of the repository description, which is ugly but otherwise harmless.
Diffstat (limited to 'UUID.hs')
-rw-r--r-- | UUID.hs | 41 |
1 files changed, 17 insertions, 24 deletions
@@ -6,7 +6,9 @@ - UUIDs of remotes are cached in git config, using keys named - remote.<name>.annex-uuid - - - Copyright 2010 Joey Hess <joey@kitenet.net> + - uuid.log stores a list of known uuids, and their descriptions. + - + - Copyright 2010-2011 Joey Hess <joey@kitenet.net> - - Licensed under the GNU GPL version 3 or higher. -} @@ -18,11 +20,11 @@ module UUID ( prepUUID, genUUID, describeUUID, - uuidMap, - uuidLog + uuidMap ) where import qualified Data.Map as M +import Data.Time.Clock.POSIX import Common.Annex import qualified Git @@ -30,13 +32,14 @@ import qualified Annex.Branch import Types.UUID import qualified Build.SysConfig as SysConfig import Config +import UUIDLog configkey :: String configkey = "annex.uuid" {- Filename of uuid.log. -} -uuidLog :: FilePath -uuidLog = "uuid.log" +logfile :: FilePath +logfile = "uuid.log" {- Generates a UUID. There is a library for this, but it's not packaged, - so use the command line tool. -} @@ -50,8 +53,7 @@ genUUID = liftIO $ pOpen ReadFromPipe command params $ \h -> hGetLine h -- uuidgen generates random uuid by default else [] -{- Looks up a repo's UUID. May return "" if none is known. - -} +{- Looks up a repo's UUID. May return "" if none is known. -} getUUID :: Git.Repo -> Annex UUID getUUID r = do g <- gitRepo @@ -76,26 +78,17 @@ getUncachedUUID r = Git.configGet r configkey "" prepUUID :: Annex () prepUUID = do u <- getUUID =<< gitRepo - when ("" == u) $ do + when (null u) $ do uuid <- liftIO genUUID setConfig configkey uuid -{- Records a description for a uuid in the uuidLog. -} +{- Records a description for a uuid in the log. -} describeUUID :: UUID -> String -> Annex () -describeUUID uuid desc = Annex.Branch.change uuidLog $ - serialize . M.insert uuid desc . parse - where - serialize m = unlines $ map (\(u, d) -> u++" "++d) $ M.toList m +describeUUID uuid desc = do + ts <- liftIO $ getPOSIXTime + Annex.Branch.change logfile $ + showLog id . changeLog ts uuid desc . parseLog Just -{- Read the uuidLog into a Map -} +{- Read the uuidLog into a simple Map -} uuidMap :: Annex (M.Map UUID String) -uuidMap = parse <$> Annex.Branch.get uuidLog - -parse :: String -> M.Map UUID String -parse = M.fromList . map pair . lines - where - pair l - | null ws = ("", "") - | otherwise = (head ws, unwords $ drop 1 ws) - where - ws = words l +uuidMap = (simpleMap . parseLog Just) <$> Annex.Branch.get logfile |