aboutsummaryrefslogtreecommitdiff
path: root/Annex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-02-25 18:02:49 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-02-25 18:02:49 -0400
commitc3fbe07d7ad03944d0967ebfa2b8f65cbc2ad5dc (patch)
treef5c1d22fdc51b597cb291bfe689e4514b0e5610a /Annex.hs
parenta3c9d06a265b2d6d3003af805b8345e4ddd3d87c (diff)
do a cleanup commit after moving data from or to a git remote
Added Annex.cleanup, which is a general purpose interface for adding actions to run at the end. Remotes with the old git-annex-shell will commit every time, and have no commit command, so hide stderr when running the commit command.
Diffstat (limited to 'Annex.hs')
-rw-r--r--Annex.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/Annex.hs b/Annex.hs
index 123c9facf..ef95ff174 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -21,6 +21,7 @@ module Annex (
setField,
getFlag,
getField,
+ addCleanup,
gitRepo,
inRepo,
fromRepo,
@@ -93,6 +94,7 @@ data AnnexState = AnnexState
, lockpool :: M.Map FilePath Fd
, flags :: M.Map String Bool
, fields :: M.Map String String
+ , cleanup :: M.Map String (Annex ())
}
newState :: Git.Repo -> AnnexState
@@ -117,6 +119,7 @@ newState gitrepo = AnnexState
, lockpool = M.empty
, flags = M.empty
, fields = M.empty
+ , cleanup = M.empty
}
{- Create and returns an Annex state object for the specified git repo. -}
@@ -132,12 +135,17 @@ eval s a = evalStateT (runAnnex a) s
{- Sets a flag to True -}
setFlag :: String -> Annex ()
setFlag flag = changeState $ \s ->
- s { flags = M.insert flag True $ flags s }
+ s { flags = M.insertWith' const flag True $ flags s }
{- Sets a field to a value -}
setField :: String -> String -> Annex ()
setField field value = changeState $ \s ->
- s { fields = M.insert field value $ fields s }
+ s { fields = M.insertWith' const field value $ fields s }
+
+{- Adds a cleanup action to perform. -}
+addCleanup :: String -> Annex () -> Annex ()
+addCleanup uid a = changeState $ \s ->
+ s { cleanup = M.insertWith' const uid a $ cleanup s }
{- Checks if a flag was set. -}
getFlag :: String -> Annex Bool