git-annex/Assistant/Changes.hs

45 lines
1.4 KiB
Haskell
Raw Normal View History

2012-06-19 06:40:21 +00:00
{- git-annex assistant change tracking
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
2012-06-23 05:20:40 +00:00
-
- Licensed under the GNU GPL version 3 or higher.
2012-06-19 06:40:21 +00:00
-}
module Assistant.Changes where
2012-10-29 23:30:23 +00:00
import Assistant.Common
import Assistant.Types.Changes
2012-06-22 17:39:44 +00:00
import Utility.TSet
2012-06-19 06:40:21 +00:00
import Data.Time.Clock
import Control.Concurrent.STM
2012-06-19 06:40:21 +00:00
{- Handlers call this when they made a change that needs to get committed. -}
madeChange :: FilePath -> ChangeInfo -> Assistant (Maybe Change)
2012-10-29 23:30:23 +00:00
madeChange f t = Just <$> (Change <$> liftIO getCurrentTime <*> pure f <*> pure t)
2012-06-19 06:40:21 +00:00
2012-10-29 23:30:23 +00:00
noChange :: Assistant (Maybe Change)
2012-06-19 06:40:21 +00:00
noChange = return Nothing
{- Indicates an add needs to be done, but has not started yet. -}
2012-10-29 23:30:23 +00:00
pendingAddChange :: FilePath -> Assistant (Maybe Change)
pendingAddChange f = Just <$> (PendingAddChange <$> liftIO getCurrentTime <*> pure f)
2012-06-19 06:40:21 +00:00
{- Gets all unhandled changes.
- Blocks until at least one change is made. -}
2012-10-29 23:30:23 +00:00
getChanges :: Assistant [Change]
getChanges = (atomically . getTSet) <<~ changeChan
{- Gets all unhandled changes, without blocking. -}
getAnyChanges :: Assistant [Change]
getAnyChanges = (atomically . readTSet) <<~ changeChan
2012-06-19 06:40:21 +00:00
{- Puts unhandled changes back into the channel.
- Note: Original order is not preserved. -}
2012-10-29 23:30:23 +00:00
refillChanges :: [Change] -> Assistant ()
refillChanges cs = (atomically . flip putTSet cs) <<~ changeChan
2012-06-22 17:39:44 +00:00
{- Records a change in the channel. -}
2012-10-29 23:30:23 +00:00
recordChange :: Change -> Assistant ()
recordChange c = (atomically . flip putTSet1 c) <<~ changeChan