xmpp git push is working!

Various final bug fixes, and tweaks that got it working.

Currently pushes a hardcoded ref, which needs to be fixed, etc.
This commit is contained in:
Joey Hess 2012-11-09 17:40:59 -04:00
parent 1deda1db13
commit 62fa648455

View file

@ -114,16 +114,19 @@ xmppPush cid remote refs = runPush (SendPushRunning cid) handleDeferred $ do
return ok return ok
where where
toxmpp inh = forever $ do toxmpp inh = forever $ do
b <- liftIO $ B.hGetSome inh 1024 b <- liftIO $ B.hGetSome inh chunkSize
if B.null b if B.null b
then liftIO $ killThread =<< myThreadId then liftIO $ killThread =<< myThreadId
else sendNetMessage $ SendPackOutput cid b else sendNetMessage $ SendPackOutput cid b
fromxmpp outh controlh = forever $ do fromxmpp outh controlh = forever $ do
m <- waitNetPushMessage m <- waitNetPushMessage
case m of case m of
(ReceivePackOutput _ b) -> liftIO $ B.hPut outh b (ReceivePackOutput _ b) -> liftIO $ do
(ReceivePackDone _ exitcode) -> do B.hPut outh b
liftIO $ hPutStrLn controlh (show exitcode) hFlush outh
(ReceivePackDone _ exitcode) -> liftIO $ do
hPutStrLn controlh (show exitcode)
hFlush controlh
_ -> noop _ -> noop
installwrapper tmpdir = liftIO $ do installwrapper tmpdir = liftIO $ do
createDirectoryIfMissing True tmpdir createDirectoryIfMissing True tmpdir
@ -151,7 +154,13 @@ relayHandle var = do
Nothing -> error $ var ++ " not set" Nothing -> error $ var ++ " not set"
Just n -> fdToHandle $ Fd n Just n -> fdToHandle $ Fd n
{- Called by git-annex xmppgit. -} {- Called by git-annex xmppgit.
-
- git-push is talking to us on stdin
- we're talking to git-push on stdout
- git-receive-pack is talking to us on relayIn (via XMPP)
- we're talking to git-receive-pack on relayOut (via XMPP)
-}
xmppGitRelay :: IO () xmppGitRelay :: IO ()
xmppGitRelay = do xmppGitRelay = do
inh <- relayHandle relayIn inh <- relayHandle relayIn
@ -162,11 +171,21 @@ xmppGitRelay = do
{- Is it possible to set up pipes and not need to copy the data {- Is it possible to set up pipes and not need to copy the data
- ourselves? See splice(2) -} - ourselves? See splice(2) -}
void $ forkIO $ forever $ do void $ forkIO $ forever $ do
b <- B.hGetSome inh 1024 b <- B.hGetSome inh chunkSize
when (B.null b) $ when (B.null b) $ do
hClose inh
hClose stdout
killThread =<< myThreadId killThread =<< myThreadId
B.hPut stdout b B.hPut stdout b
void $ forkIO $ forever $ B.hGetSome stdin 1024 >>= B.hPut outh hFlush stdout
void $ forkIO $ forever $ do
b <- B.hGetSome stdin chunkSize
when (B.null b) $ do
hClose outh
hClose stdin
killThread =<< myThreadId
B.hPut outh b
hFlush outh
controlh <- relayHandle relayControl controlh <- relayHandle relayControl
s <- hGetLine controlh s <- hGetLine controlh
@ -191,15 +210,15 @@ xmppReceivePack cid = runPush (ReceivePushRunning cid) handleDeferred $ do
} }
liftIO $ do liftIO $ do
(Just inh, Just outh, _, pid) <- createProcess p (Just inh, Just outh, _, pid) <- createProcess p
feedertid <- forkIO $ feeder outh readertid <- forkIO $ reader inh
void $ reader inh void $ feeder outh
code <- waitForProcess pid code <- waitForProcess pid
void $ sendexitcode code void $ sendexitcode code
killThread feedertid killThread readertid
return $ code == ExitSuccess return $ code == ExitSuccess
where where
toxmpp outh = do toxmpp outh = do
b <- liftIO $ B.hGetSome outh 1024 b <- liftIO $ B.hGetSome outh chunkSize
if B.null b if B.null b
then return () -- EOF then return () -- EOF
else do else do
@ -208,7 +227,9 @@ xmppReceivePack cid = runPush (ReceivePushRunning cid) handleDeferred $ do
fromxmpp inh = forever $ do fromxmpp inh = forever $ do
m <- waitNetPushMessage m <- waitNetPushMessage
case m of case m of
(SendPackOutput _ b) -> liftIO $ B.hPut inh b (SendPackOutput _ b) -> liftIO $ do
B.hPut inh b
hFlush inh
_ -> noop _ -> noop
xmppRemotes :: ClientID -> Assistant [Remote] xmppRemotes :: ClientID -> Assistant [Remote]
@ -234,10 +255,14 @@ handlePushMessage (CanPush cid) = do
handlePushMessage (PushRequest cid) = do handlePushMessage (PushRequest cid) = do
rs <- xmppRemotes cid rs <- xmppRemotes cid
current <- liftAnnex $ inRepo Git.Branch.current current <- liftAnnex $ inRepo Git.Branch.current
let refs = catMaybes [current, Just Annex.Branch.fullname] --let refs = catMaybes [current, Just Annex.Branch.fullname] -- TODO
let refs = [Ref "master:refs/xmpp/newmaster"]
forM_ rs $ \r -> xmppPush cid r refs forM_ rs $ \r -> xmppPush cid r refs
handlePushMessage (StartingPush cid) = do handlePushMessage (StartingPush cid) = do
rs <- xmppRemotes cid rs <- xmppRemotes cid
unless (null rs) $ unless (null rs) $
void $ xmppReceivePack cid void $ xmppReceivePack cid
handlePushMessage _ = noop handlePushMessage _ = noop
chunkSize :: Int
chunkSize = 1024