convert formatLsTree to ByteString for speed

This commit is contained in:
Joey Hess 2021-05-17 10:46:24 -04:00
parent 309c1bc1f0
commit 1d16654a22
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 10 additions and 8 deletions

View file

@ -28,6 +28,7 @@ import Utility.Attoparsec
import Numeric import Numeric
import Data.Either import Data.Either
import Data.Char
import System.Posix.Types import System.Posix.Types
import qualified Data.ByteString as S import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy as L
@ -146,9 +147,9 @@ parserLsTree long = case long of
{- Inverse of parseLsTree. Note that the long output format is not {- Inverse of parseLsTree. Note that the long output format is not
- generated, so any size information is not included. -} - generated, so any size information is not included. -}
formatLsTree :: TreeItem -> String formatLsTree :: TreeItem -> S.ByteString
formatLsTree ti = unwords formatLsTree ti = S.intercalate (S.singleton (fromIntegral (ord ' ')))
[ showOct (mode ti) "" [ encodeBS' (showOct (mode ti) "")
, decodeBS (typeobj ti) , typeobj ti
, fromRef (sha ti) , fromRef' (sha ti)
] ++ ('\t' : fromRawFilePath (getTopFilePath (file ti))) ] <> (S.cons (fromIntegral (ord '\t')) (getTopFilePath (file ti)))

View file

@ -23,6 +23,7 @@ module Logs.Export (
) where ) where
import qualified Data.Map as M import qualified Data.Map as M
import qualified Data.ByteString as B
import Annex.Common import Annex.Common
import qualified Annex.Branch import qualified Annex.Branch
@ -119,10 +120,10 @@ logExportExcluded :: UUID -> ((Git.Tree.TreeItem -> IO ()) -> Annex a) -> Annex
logExportExcluded u a = do logExportExcluded u a = do
logf <- fromRepo $ gitAnnexExportExcludeLog u logf <- fromRepo $ gitAnnexExportExcludeLog u
withLogHandle logf $ \logh -> do withLogHandle logf $ \logh -> do
liftIO $ hSetNewlineMode logh noNewlineTranslation
a (writer logh) a (writer logh)
where where
writer logh = hPutStrLn logh writer logh = B.hPutStr logh
. flip B.snoc (fromIntegral (ord '\n'))
. Git.LsTree.formatLsTree . Git.LsTree.formatLsTree
. Git.Tree.treeItemToLsTreeItem . Git.Tree.treeItemToLsTreeItem