diff options
author | Joey Hess <joey@kitenet.net> | 2011-10-03 15:41:25 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-10-03 15:41:25 -0400 |
commit | f77979b8b5ef1dc59b45c03ba6febfacdf904491 (patch) | |
tree | 952982098f70079e67347fce3e2fd99e515a708e /UUID.hs | |
parent | 6dfb94b2d783ef848c651ab20818b05c8a0504a6 (diff) |
improved git-annex branch changing
All changes to files in the branch are now made via pure functions that
transform the old file into the new. This will allow adding locking
to prevent read/write races. It also makes the code nicer, and purer.
I noticed a behavior change, really a sort of bug fix. Before,
'git annex untrust foo --trust bar' would change both trust levels
permanantly, now the --trust doesn't get stored.
Diffstat (limited to 'UUID.hs')
-rw-r--r-- | UUID.hs | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -23,6 +23,7 @@ module UUID ( ) where import Control.Monad.State +import Control.Applicative import System.Cmd.Utils import System.IO import qualified Data.Map as M @@ -87,18 +88,17 @@ prepUUID = do {- Records a description for a uuid in the uuidLog. -} describeUUID :: UUID -> String -> Annex () -describeUUID uuid desc = do - m <- uuidMap - let m' = M.insert uuid desc m - Branch.change uuidLog (serialize m') +describeUUID uuid desc = Branch.change uuidLog $ + serialize . M.insert uuid desc . parse where serialize m = unlines $ map (\(u, d) -> u++" "++d) $ M.toList m -{- Read and parse the uuidLog into a Map -} +{- Read the uuidLog into a Map -} uuidMap :: Annex (M.Map UUID String) -uuidMap = do - s <- Branch.get uuidLog - return $ M.fromList $ map pair $ lines s +uuidMap = parse <$> Branch.get uuidLog + +parse :: String -> M.Map UUID String +parse = M.fromList . map pair . lines where pair l | null ws = ("", "") |