Revert "cache the serialization of a Key"

This reverts commit 4536c93bb2.

That broke Read/Show of a Key, and unfortunately Key is read in at least
one place; the GitAnnexDistribution data type.

It would be worth bringing this optimisation back, but it would need
either a custom Read/Show instance that preserves back-compat, or
wrapping Key in a data type that contains the serialization, or changing
how GitAnnexDistribution is serialized.

Also, the Eq instance would need to compare keys with and without a
cached seralization the same.
This commit is contained in:
Joey Hess 2019-01-16 16:09:53 -04:00
parent 863ed51ae0
commit 96aba8eff7
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
12 changed files with 19 additions and 52 deletions

View file

@ -65,14 +65,14 @@ hashDirs (HashLevels 1) sz s = addTrailingPathSeparator $ take sz s
hashDirs _ sz s = addTrailingPathSeparator $ take sz s </> drop sz s
hashDirLower :: HashLevels -> Hasher
hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5s $ serializeKey' $ nonChunkKey k
hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5 $ serializeKey' $ nonChunkKey k
{- This was originally using Data.Hash.MD5 from MissingH. This new version
- is faster, but ugly as it has to replicate the 4 Word32's that produced. -}
hashDirMixed :: HashLevels -> Hasher
hashDirMixed n k = hashDirs n 2 $ take 4 $ concatMap display_32bits_as_dir $
encodeWord32 $ map fromIntegral $ Data.ByteArray.unpack $
Utility.Hash.md5s $ serializeKey' $ nonChunkKey k
Utility.Hash.md5 $ serializeKey' $ nonChunkKey k
where
encodeWord32 (b1:b2:b3:b4:rest) =
(shiftL b4 24 .|. shiftL b3 16 .|. shiftL b2 8 .|. b1)

View file

@ -42,7 +42,6 @@ exportKey sha = mk <$> catKey sha
, keyMtime = Nothing
, keyChunkSize = Nothing
, keyChunkNum = Nothing
, keySerialization = Nothing
}
exportTree :: Remote.RemoteConfig -> Bool

View file

@ -85,6 +85,7 @@ module Annex.Locations (
import Data.Char
import Data.Default
import qualified Data.ByteString.Char8 as S8
import qualified Data.ByteString.Lazy as L
import Common
import Key
@ -515,7 +516,7 @@ keyFile = fromRawFilePath . keyFile'
keyFile' :: Key -> RawFilePath
keyFile' k =
let b = serializeKey' k
let b = L.toStrict (serializeKey' k)
in if any (`S8.elem` b) ['&', '%', ':', '/']
then S8.concatMap esc b
else b

View file

@ -10,7 +10,7 @@ module Annex.VariantFile where
import Annex.Common
import Utility.Hash
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
variantMarker :: String
variantMarker = ".variant-"
@ -41,5 +41,5 @@ variantFile file key
where
doubleconflict = variantMarker `isInfixOf` file
shortHash :: S.ByteString -> String
shortHash = take 4 . show . md5s
shortHash :: L.ByteString -> String
shortHash = take 4 . show . md5