diff options
author | Joey Hess <joey@kitenet.net> | 2013-12-27 03:10:00 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-12-27 03:10:00 -0400 |
commit | 0d24eb208614288067ddc3118fe4654ca2e86e77 (patch) | |
tree | 8a31a975b4e7777b8483c94114ed764bd28d0152 | |
parent | 690c690e97ecc3808755e95acd0d45bfe03ed366 (diff) |
make --debug show transcript of special remote protocol messages
-rw-r--r-- | Remote/External.hs | 15 | ||||
-rw-r--r-- | doc/special_remotes/external.mdwn | 2 |
2 files changed, 16 insertions, 1 deletions
diff --git a/Remote/External.hs b/Remote/External.hs index 5a09d1de0..3863383d8 100644 --- a/Remote/External.hs +++ b/Remote/External.hs @@ -25,6 +25,7 @@ import Annex.Exception import Control.Concurrent.STM import System.Process (std_in, std_out, std_err) +import System.Log.Logger (debugM) import qualified Data.Map as M remote :: RemoteType @@ -194,7 +195,11 @@ handleRequest' lck external req mp responsehandler = do sendMessage :: Sendable m => ExternalLock -> External -> m -> Annex () sendMessage lck external m = fromExternal lck external externalSend $ \h -> - liftIO $ hPutStrLn h $ unwords $ formatMessage m + liftIO $ do + protocolDebug external True line + hPutStrLn h line + where + line = unwords $ formatMessage m {- Waits for a message from the external remote, and passes it to the - apppropriate handler. @@ -209,6 +214,7 @@ receiveMessage -> Annex a receiveMessage lck external handleresponse handlerequest handleasync = do s <- fromExternal lck external externalReceive $ liftIO . hGetLine + liftIO $ protocolDebug external False s case parseMessage s :: Maybe Response of Just resp -> maybe (protocolError s) id (handleresponse resp) Nothing -> case parseMessage s :: Maybe RemoteRequest of @@ -219,6 +225,13 @@ receiveMessage lck external handleresponse handlerequest handleasync = do where protocolError s = error $ "external special remote protocol error, unexpectedly received \"" ++ s ++ "\"" +protocolDebug :: External -> Bool -> String -> IO () +protocolDebug external sendto line = debugM "external" $ unwords + [ externalRemoteProgram (externalType external) + , if sendto then "<--" else "-->" + , line + ] + {- Starts up the external remote if it's not yet running, - and passes a value extracted from its state to an action. -} diff --git a/doc/special_remotes/external.mdwn b/doc/special_remotes/external.mdwn index c69d00425..3cbc1093e 100644 --- a/doc/special_remotes/external.mdwn +++ b/doc/special_remotes/external.mdwn @@ -14,6 +14,8 @@ It's not hard! * Install it in PATH. * When the user runs `git annex initremote foo type=external externaltype=$bar`, it will use your program. +* If things don't seem to work, pass `--debug` and you'll see, amoung other + things, a transcript of git-annex's communication with your program. * If you build a new special remote, please add it to the list of [[special_remotes]]. |