From 973180b077e60b5d12d7c57d926878d11d7f2105 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 15 May 2017 18:10:13 -0400 Subject: stop using MissingH for MD5 Cryptonite is faster and allocates less, and I want to get rid of MissingH use. Note that the new dependency on memory is free; it's a dependency of cryptonite. This commit was supported by the NSF-funded DataLad project. --- Annex/DirHashes.hs | 24 +++++++++++++++++------- Annex/Ssh.hs | 4 ++-- Annex/VariantFile.hs | 5 ++--- 3 files changed, 21 insertions(+), 12 deletions(-) (limited to 'Annex') diff --git a/Annex/DirHashes.hs b/Annex/DirHashes.hs index 82d751eee..f8438484d 100644 --- a/Annex/DirHashes.hs +++ b/Annex/DirHashes.hs @@ -1,6 +1,6 @@ {- git-annex file locations - - - Copyright 2010-2015 Joey Hess + - Copyright 2010-2017 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -19,14 +19,15 @@ module Annex.DirHashes ( import Data.Bits import Data.Word -import Data.Hash.MD5 import Data.Default +import qualified Data.ByteArray import Common import Key import Types.GitConfig import Types.Difference import Utility.FileSystemEncoding +import Utility.Hash type Hasher = Key -> FilePath @@ -62,15 +63,24 @@ hashDirs :: HashLevels -> Int -> String -> FilePath 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 $ md5 $ + encodeBS $ key2file $ 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 $ display_32bits_as_dir =<< [a,b,c,d] +hashDirMixed n k = hashDirs n 2 $ take 4 $ concatMap display_32bits_as_dir $ + encodeWord32 $ map fromIntegral $ Data.ByteArray.unpack $ + Utility.Hash.md5 $ encodeBS $ key2file $ nonChunkKey k where - ABCD (a,b,c,d) = md5 $ md5FilePath $ key2file $ nonChunkKey k - -hashDirLower :: HashLevels -> Hasher -hashDirLower n k = hashDirs n 3 $ take 6 $ md5s $ md5FilePath $ key2file $ nonChunkKey k + encodeWord32 (b1:b2:b3:b4:rest) = + (shiftL b4 24 .|. shiftL b3 16 .|. shiftL b2 8 .|. b1) + : encodeWord32 rest + encodeWord32 _ = [] {- modified version of display_32bits_as_hex from Data.Hash.MD5 + - in MissingH - Copyright (C) 2001 Ian Lynagh - License: Either BSD or GPL -} diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs index c53802941..a9ff91751 100644 --- a/Annex/Ssh.hs +++ b/Annex/Ssh.hs @@ -33,6 +33,7 @@ import Config import Annex.Path import Utility.Env import Utility.FileSystemEncoding +import Utility.Hash import Types.CleanupActions import Types.Concurrency import Git.Env @@ -42,7 +43,6 @@ import Annex.Perms import Annex.LockPool #endif -import Data.Hash.MD5 import Control.Concurrent.STM {- Some ssh commands are fed stdin on a pipe and so should be allowed to @@ -287,7 +287,7 @@ hostport2socket host Nothing = hostport2socket' host hostport2socket host (Just port) = hostport2socket' $ host ++ "!" ++ show port hostport2socket' :: String -> FilePath hostport2socket' s - | length s > lengthofmd5s = md5s (Str s) + | length s > lengthofmd5s = show $ md5 $ encodeBS s | otherwise = s where lengthofmd5s = 32 diff --git a/Annex/VariantFile.hs b/Annex/VariantFile.hs index 17658a9c6..8365073d5 100644 --- a/Annex/VariantFile.hs +++ b/Annex/VariantFile.hs @@ -9,8 +9,7 @@ module Annex.VariantFile where import Annex.Common import Utility.FileSystemEncoding - -import Data.Hash.MD5 +import Utility.Hash variantMarker :: String variantMarker = ".variant-" @@ -42,4 +41,4 @@ variantFile file key doubleconflict = variantMarker `isInfixOf` file shortHash :: String -> String -shortHash = take 4 . md5s . md5FilePath +shortHash = take 4 . show . md5 . encodeBS -- cgit v1.2.3