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.
This commit is contained in:
Joey Hess 2011-10-03 15:41:25 -04:00
parent 6dfb94b2d7
commit f77979b8b5
7 changed files with 34 additions and 30 deletions

16
UUID.hs
View file

@ -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 = ("", "")