From: Joey Hess Date: Thu, 4 Nov 2021 19:03:12 +0000 (-0400) Subject: reorg X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~2^2^2~57^2~63 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=218e1983ad9acfdb44449af1b32f4368a7c9898c;p=git-annex.git reorg --- diff --git a/Git/FilterProcess.hs b/Git/FilterProcess.hs index b3bcfe12f3..57541a0b73 100644 --- a/Git/FilterProcess.hs +++ b/Git/FilterProcess.hs @@ -14,9 +14,6 @@ module Git.FilterProcess ( WelcomeMessage(..), Version(..), Capability(..), - readUntilFlushPkt, - readUntilFlushPktOrSize, - discardUntilFlushPkt, longRunningProcessHandshake, longRunningFilterProcessHandshake, FilterRequest(..), @@ -77,40 +74,6 @@ decodeCapability pktline = decodeConfigValue pktline >>= \case ConfigValue "capability" c -> Just $ Capability c _ -> Nothing -{- Reads PktLines until a flushPkt (or EOF), - - and returns all except the flushPkt -} -readUntilFlushPkt :: IO [PktLine] -readUntilFlushPkt = go [] - where - go l = readPktLine stdin >>= \case - Just pktline | not (isFlushPkt pktline) -> go (pktline:l) - _ -> return (reverse l) - -{- Reads PktLines until at least the specified number of bytes have been - - read, or until a flushPkt (or EOF). Returns Right if it did read a - - flushPkt/EOF, and Left if there is still content leftover that needs to - - be read. -} -readUntilFlushPktOrSize :: Int -> IO (Either [PktLine] [PktLine]) -readUntilFlushPktOrSize = go [] - where - go l n = readPktLine stdin >>= \case - Just pktline - | isFlushPkt pktline -> return (Right (reverse l)) - | otherwise -> - let len = B.length (pktLineToByteString pktline) - n' = n - len - in if n' <= 0 - then return (Left (reverse (pktline:l))) - else go (pktline:l) n' - Nothing -> return (Right (reverse l)) - -{- Reads PktLines until a flushPkt (or EOF), and throws them away. -} -discardUntilFlushPkt :: IO () -discardUntilFlushPkt = readPktLine stdin >>= \case - Just pktline | isFlushPkt pktline -> return () - Nothing -> return () - _ -> discardUntilFlushPkt - longRunningProcessHandshake :: (WelcomeMessage -> Maybe WelcomeMessage) -> ([Version] -> [Version]) diff --git a/Git/PktLine.hs b/Git/PktLine.hs index 29af14c752..844d3d6a26 100644 --- a/Git/PktLine.hs +++ b/Git/PktLine.hs @@ -19,6 +19,9 @@ module Git.PktLine ( writePktLine, flushPkt, isFlushPkt, + readUntilFlushPkt, + readUntilFlushPktOrSize, + discardUntilFlushPkt, ) where import System.IO @@ -115,3 +118,37 @@ flushPkt = PktLine mempty isFlushPkt :: PktLine -> Bool isFlushPkt (PktLine b) = b == mempty + +{- Reads PktLines until a flushPkt (or EOF), + - and returns all except the flushPkt -} +readUntilFlushPkt :: IO [PktLine] +readUntilFlushPkt = go [] + where + go l = readPktLine stdin >>= \case + Just pktline | not (isFlushPkt pktline) -> go (pktline:l) + _ -> return (reverse l) + +{- Reads PktLines until at least the specified number of bytes have been + - read, or until a flushPkt (or EOF). Returns Right if it did read a + - flushPkt/EOF, and Left if there is still content leftover that needs to + - be read. -} +readUntilFlushPktOrSize :: Int -> IO (Either [PktLine] [PktLine]) +readUntilFlushPktOrSize = go [] + where + go l n = readPktLine stdin >>= \case + Just pktline + | isFlushPkt pktline -> return (Right (reverse l)) + | otherwise -> + let len = B.length (pktLineToByteString pktline) + n' = n - len + in if n' <= 0 + then return (Left (reverse (pktline:l))) + else go (pktline:l) n' + Nothing -> return (Right (reverse l)) + +{- Reads PktLines until a flushPkt (or EOF), and throws them away. -} +discardUntilFlushPkt :: IO () +discardUntilFlushPkt = readPktLine stdin >>= \case + Just pktline | isFlushPkt pktline -> return () + Nothing -> return () + _ -> discardUntilFlushPkt