summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-05-15 18:10:13 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-05-15 21:36:03 -0400
commit973180b077e60b5d12d7c57d926878d11d7f2105 (patch)
tree7d3bc5e651d330c1945c81f356b59eca90e73ea2 /Annex
parent0d85a42333484e1acb8e4942a619087768bc62fb (diff)
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.
Diffstat (limited to 'Annex')
-rw-r--r--Annex/DirHashes.hs24
-rw-r--r--Annex/Ssh.hs4
-rw-r--r--Annex/VariantFile.hs5
3 files changed, 21 insertions, 12 deletions
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 <id@joeyh.name>
+ - Copyright 2010-2017 Joey Hess <id@joeyh.name>
-
- 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