summaryrefslogtreecommitdiff
path: root/Branch.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-10-03 15:41:25 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-10-03 15:41:25 -0400
commitf77979b8b5ef1dc59b45c03ba6febfacdf904491 (patch)
tree952982098f70079e67347fce3e2fd99e515a708e /Branch.hs
parent6dfb94b2d783ef848c651ab20818b05c8a0504a6 (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 'Branch.hs')
-rw-r--r--Branch.hs16
1 files changed, 13 insertions, 3 deletions
diff --git a/Branch.hs b/Branch.hs
index e4caeece7..9340259c7 100644
--- a/Branch.hs
+++ b/Branch.hs
@@ -213,9 +213,19 @@ updateRef ref
liftIO $ Git.UnionMerge.merge g [ref]
return $ Just ref
-{- Records changed content of a file into the journal. -}
-change :: FilePath -> String -> Annex ()
-change file content = do
+{- Applies a function to modifiy the content of a file. -}
+change :: FilePath -> (String -> String) -> Annex ()
+change file a = do
+ lock
+ get file >>= return . a >>= set file
+ unlock
+ where
+ lock = return ()
+ unlock = return ()
+
+{- Records new content of a file into the journal. -}
+set :: FilePath -> String -> Annex ()
+set file content = do
setJournalFile file content
setCache file content