diff options
author | Joey Hess <joey@kitenet.net> | 2011-06-29 23:56:47 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-06-29 23:56:47 -0400 |
commit | b089fba7b4e68c4482909319f562d32a3f00f379 (patch) | |
tree | 5cd1a2895920a4ff8ebe45d9e3f6eec60a30a935 /Branch.hs | |
parent | 899ecbfba1c015c2c80f729c7e0d5544d7bcc415 (diff) |
use ByteString for hGet
Avoids the crazy low-level hGetBuf stuff. Also slightly faster.
Diffstat (limited to 'Branch.hs')
-rw-r--r-- | Branch.hs | 20 |
1 files changed, 3 insertions, 17 deletions
@@ -26,9 +26,7 @@ import System.Cmd.Utils import Data.Maybe import Data.List import System.IO -import System.IO.Unsafe -import Foreign -import Data.Char +import qualified Data.ByteString.Char8 as B import Types.BranchState import qualified GitRepo as Git @@ -258,23 +256,11 @@ catFile file = do else do let [_sha, _type, size] = words header let bytes = read size - fp <- mallocForeignPtrBytes (fromIntegral bytes) - len <- withForeignPtr fp $ \buf -> hGetBuf from buf (fromIntegral bytes) - when (len /= bytes) $ - error "short read from git cat-file" - content <- lazySlurp fp 0 len + content <- B.hGet from bytes c <- hGetChar from when (c /= '\n') $ error "missing newline from git cat-file" - return content - -lazySlurp :: ForeignPtr Word8 -> Int -> Int -> IO String -lazySlurp fp ix len - | ix == len = return [] - | otherwise = do - c <- withForeignPtr fp $ \p -> peekElemOff p ix - cs <- unsafeInterleaveIO (lazySlurp fp (ix+1) len) - return $ chr (fromIntegral c) : cs + return $ B.unpack content {- Lists all files on the branch. There may be duplicates in the list. -} files :: Annex [FilePath] |