xmppgit now actually works
But I could not find a way to implement it using just FD piping; it has to copy the data.
This commit is contained in:
parent
cb7523b9e8
commit
68a5c98acc
1 changed files with 22 additions and 12 deletions
|
@ -24,6 +24,8 @@ import Network.Protocol.XMPP
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import System.Posix.Env
|
import System.Posix.Env
|
||||||
import System.Posix.Types
|
import System.Posix.Types
|
||||||
|
import Control.Concurrent
|
||||||
|
import qualified Data.ByteString as B
|
||||||
|
|
||||||
configKey :: Remote -> ConfigKey
|
configKey :: Remote -> ConfigKey
|
||||||
configKey r = remoteConfig (Remote.repo r) "xmppaddress"
|
configKey r = remoteConfig (Remote.repo r) "xmppaddress"
|
||||||
|
@ -73,8 +75,8 @@ makeXMPPGitRemote buddyname jid u = do
|
||||||
- We listen at the other end of the pipe and relay to and from XMPP.
|
- We listen at the other end of the pipe and relay to and from XMPP.
|
||||||
-}
|
-}
|
||||||
xmppPush :: Remote -> [Ref] -> Assistant Bool
|
xmppPush :: Remote -> [Ref] -> Assistant Bool
|
||||||
xmppPush remote refs = do
|
xmppPush _remote _refs = do
|
||||||
program <- liftIO readProgramFile
|
_program <- liftIO readProgramFile
|
||||||
|
|
||||||
-- GIT_SSH=program git -c remote.xmppremote.url=xmppgit:dummy push xmppremote refs
|
-- GIT_SSH=program git -c remote.xmppremote.url=xmppgit:dummy push xmppremote refs
|
||||||
error "TODO"
|
error "TODO"
|
||||||
|
@ -88,23 +90,32 @@ relayOut = "GIT_ANNEX_XMPPGIT_OUT"
|
||||||
relayControl :: String
|
relayControl :: String
|
||||||
relayControl = "GIT_ANNEX_XMPPGIT_CONTROL"
|
relayControl = "GIT_ANNEX_XMPPGIT_CONTROL"
|
||||||
|
|
||||||
relayFd :: String -> IO Fd
|
relayHandle :: String -> IO Handle
|
||||||
relayFd var = do
|
relayHandle var = do
|
||||||
v <- getEnv var
|
v <- getEnv var
|
||||||
case readish =<< v of
|
case readish =<< v of
|
||||||
Nothing -> error $ var ++ " not set"
|
Nothing -> error $ var ++ " not set"
|
||||||
Just n -> return $ Fd n
|
Just n -> fdToHandle $ Fd n
|
||||||
|
|
||||||
{- Called by git-annex xmppgit. -}
|
{- Called by git-annex xmppgit. -}
|
||||||
xmppGitRelay :: IO ()
|
xmppGitRelay :: IO ()
|
||||||
xmppGitRelay = do
|
xmppGitRelay = do
|
||||||
inf <- relayFd relayIn
|
inh <- relayHandle relayIn
|
||||||
outf <-relayFd relayOut
|
outh <- relayHandle relayOut
|
||||||
|
|
||||||
void $ dupTo stdInput outf
|
hSetBuffering stdout NoBuffering
|
||||||
void $ dupTo inf stdOutput
|
hSetBuffering outh NoBuffering
|
||||||
|
|
||||||
controlh <- fdToHandle =<< relayFd relayControl
|
{- Is it possible to set up pipes and not need to copy the data
|
||||||
|
- ourselves? -}
|
||||||
|
void $ forkIO $ forever $ do
|
||||||
|
b <- B.hGetSome inh 1024
|
||||||
|
when (B.null b) $
|
||||||
|
killThread =<< myThreadId
|
||||||
|
B.hPut stdout b
|
||||||
|
void $ forkIO $ forever $ B.hGetSome stdin 1024 >>= B.hPut outh
|
||||||
|
|
||||||
|
controlh <- relayHandle relayControl
|
||||||
s <- hGetLine controlh
|
s <- hGetLine controlh
|
||||||
exitWith $ case readish s of
|
exitWith $ case readish s of
|
||||||
Just n
|
Just n
|
||||||
|
@ -112,7 +123,6 @@ xmppGitRelay = do
|
||||||
| otherwise -> ExitFailure n
|
| otherwise -> ExitFailure n
|
||||||
Nothing -> ExitFailure 1
|
Nothing -> ExitFailure 1
|
||||||
|
|
||||||
{- Relays git receive-pack to and from XMPP. The command needs no
|
{- Relays git receive-pack to and from XMPP, and propigates its exit status. -}
|
||||||
- parameters except the directory to run in. -}
|
|
||||||
xmppReceivePack :: Assistant Bool
|
xmppReceivePack :: Assistant Bool
|
||||||
xmppReceivePack = error "TODO"
|
xmppReceivePack = error "TODO"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue