git-annex/Types/Backend.hs
Joey Hess 9c4650358c
add KeyVariety type
Where before the "name" of a key and a backend was a string, this makes
it a concrete data type.

This is groundwork for allowing some varieties of keys to be disabled
in file2key, so git-annex won't use them at all.

Benchmarks ran in my big repo:

old git-annex info:

real	0m3.338s
user	0m3.124s
sys	0m0.244s

new git-annex info:

real	0m3.216s
user	0m3.024s
sys	0m0.220s

new git-annex find:

real	0m7.138s
user	0m6.924s
sys	0m0.252s

old git-annex find:

real	0m7.433s
user	0m7.240s
sys	0m0.232s

Surprising result; I'd have expected it to be slower since it now parses
all the key varieties. But, the parser is very simple and perhaps
sharing KeyVarieties uses less memory or something like that.

This commit was supported by the NSF-funded DataLad project.
2017-02-24 15:16:56 -04:00

34 lines
1 KiB
Haskell

{- git-annex key backend data type
-
- Most things should not need this, using Types instead
-
- Copyright 2010-2017 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Types.Backend where
import Types.Key
import Types.KeySource
data BackendA a = Backend
{ backendVariety :: KeyVariety
, getKey :: KeySource -> a (Maybe Key)
-- Verifies the content of a key.
, verifyKeyContent :: Maybe (Key -> FilePath -> a Bool)
-- Checks if a key can be upgraded to a better form.
, canUpgradeKey :: Maybe (Key -> Bool)
-- Checks if there is a fast way to migrate a key to a different
-- backend (ie, without re-hashing).
, fastMigrate :: Maybe (Key -> BackendA a -> AssociatedFile -> Maybe Key)
-- Checks if a key is known (or assumed) to always refer to the
-- same data.
, isStableKey :: Key -> Bool
}
instance Show (BackendA a) where
show backend = "Backend { name =\"" ++ formatKeyVariety (backendVariety backend) ++ "\" }"
instance Eq (BackendA a) where
a == b = backendVariety a == backendVariety b