simplification now that all logs use Builder

This commit is contained in:
Joey Hess 2019-01-09 14:10:05 -04:00
parent 2fef43dd71
commit 232b1a08f3
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 13 additions and 7 deletions

View file

@ -34,6 +34,7 @@ import qualified Data.Set as S
import qualified Data.Map as M
import Data.Function
import Data.Char
import Data.ByteString.Builder
import Control.Concurrent (threadDelay)
import Annex.Common
@ -586,7 +587,8 @@ performTransitionsLocked jl ts neednewlocalbranch transitionedrefs = do
-- File is deleted; can't run any other
-- transitions on it.
return ()
ChangeFile content' -> do
ChangeFile builder -> do
let content' = toLazyByteString builder
sha <- hashBlob content'
Annex.Queue.addUpdateIndex $ Git.UpdateIndex.pureStreamer $
Git.UpdateIndex.updateIndexLine sha TreeFile (asTopFilePath file)

View file

@ -27,7 +27,7 @@ import qualified Data.ByteString.Lazy as L
import Data.ByteString.Builder
data FileTransition
= ChangeFile L.ByteString
= ChangeFile Builder
| RemoveFile
| PreserveFile
@ -44,25 +44,25 @@ dropDead f content trustmap = case getLogVariety f of
-- because git remotes may still exist, and they need
-- to still know it's dead.
| f == trustLog -> PreserveFile
| otherwise -> ChangeFile $ toLazyByteString $
| otherwise -> ChangeFile $
UUIDBased.buildLog (byteString . encodeBS) $
dropDeadFromMapLog trustmap id $ UUIDBased.parseLog Just (decodeBL content)
Just NewUUIDBasedLog -> ChangeFile $ toLazyByteString $
Just NewUUIDBasedLog -> ChangeFile $
UUIDBased.buildLogNew (byteString . encodeBS) $
dropDeadFromMapLog trustmap id $
UUIDBased.parseLogNew Just (decodeBL content)
Just (ChunkLog _) -> ChangeFile $ toLazyByteString $
Just (ChunkLog _) -> ChangeFile $
Chunk.buildLog $ dropDeadFromMapLog trustmap fst $ Chunk.parseLog (decodeBL content)
Just (PresenceLog _) ->
let newlog = Presence.compactLog $ dropDeadFromPresenceLog trustmap $ Presence.parseLog content
in if null newlog
then RemoveFile
else ChangeFile $ toLazyByteString $ Presence.buildLog newlog
else ChangeFile $ Presence.buildLog newlog
Just RemoteMetaDataLog ->
let newlog = dropDeadFromRemoteMetaDataLog trustmap $ MetaData.simplifyLog $ MetaData.parseLog content
in if S.null newlog
then RemoveFile
else ChangeFile $ toLazyByteString $ MetaData.buildLog newlog
else ChangeFile $ MetaData.buildLog newlog
Just OtherLog -> PreserveFile
Nothing -> PreserveFile

View file

@ -19,6 +19,7 @@ import Utility.Tmp
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
import Data.ByteString.Builder
type HashObjectHandle = CoProcess.CoProcessHandle
@ -49,6 +50,9 @@ instance HashableBlob L.ByteString where
instance HashableBlob S.ByteString where
hashableBlobToHandle = S.hPut
instance HashableBlob Builder where
hashableBlobToHandle = hPutBuilder
{- Injects a blob into git. Unfortunately, the current git-hash-object
- interface does not allow batch hashing without using temp files. -}
hashBlob :: HashableBlob b => HashObjectHandle -> b -> IO Sha