2014-04-05 20:04:37 +00:00
|
|
|
{- git-annex-shell command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-04-05 20:04:37 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.NotifyChanges where
|
|
|
|
|
|
|
|
import Command
|
2016-12-09 18:52:38 +00:00
|
|
|
import Annex.ChangedRefs
|
2014-04-06 23:06:03 +00:00
|
|
|
import RemoteDaemon.Transport.Ssh.Types
|
2016-12-09 17:34:00 +00:00
|
|
|
import Utility.SimpleProtocol
|
2014-04-05 20:04:37 +00:00
|
|
|
|
|
|
|
import Control.Concurrent.Async
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-08 19:08:02 +00:00
|
|
|
cmd = noCommit $
|
|
|
|
command "notifychanges" SectionPlumbing
|
|
|
|
"sends notification when git refs are changed"
|
|
|
|
paramNothing (withParams seek)
|
2014-04-05 20:04:37 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2018-10-01 18:12:06 +00:00
|
|
|
seek = withNothing (commandAction start)
|
2014-04-05 20:04:37 +00:00
|
|
|
|
|
|
|
start :: CommandStart
|
2016-12-09 20:27:20 +00:00
|
|
|
start = go =<< watchChangedRefs
|
|
|
|
where
|
|
|
|
go (Just h) = do
|
|
|
|
-- No messages need to be received from the caller,
|
|
|
|
-- but when it closes the connection, notice and terminate.
|
|
|
|
let receiver = forever $ void $ getProtocolLine stdin
|
|
|
|
let sender = forever $ send . CHANGED =<< waitChangedRefs h
|
|
|
|
|
|
|
|
liftIO $ send READY
|
|
|
|
void $ liftIO $ concurrently sender receiver
|
|
|
|
liftIO $ stopWatchingChangedRefs h
|
|
|
|
stop
|
|
|
|
go Nothing = stop
|
2014-04-05 20:04:37 +00:00
|
|
|
|
|
|
|
send :: Notification -> IO ()
|
|
|
|
send n = do
|
|
|
|
putStrLn $ unwords $ formatMessage n
|
|
|
|
hFlush stdout
|