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.
This commit is contained in:
parent
a3c9d06a26
commit
c3fbe07d7a
5 changed files with 43 additions and 13 deletions
12
Annex.hs
12
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue