encoding a git sha as a git-annex key
This is a bijective mapping, and is distinct from SHA1. As git transitions away from sha1, this could contain whatever hash git uses.
This commit is contained in:
parent
d045e39058
commit
1c1edad620
1 changed files with 21 additions and 0 deletions
21
Key.hs
21
Key.hs
|
@ -5,6 +5,7 @@
|
||||||
- Licensed under the GNU AGPL version 3 or higher.
|
- Licensed under the GNU AGPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||||
|
|
||||||
module Key (
|
module Key (
|
||||||
|
@ -22,6 +23,8 @@ module Key (
|
||||||
nonChunkKey,
|
nonChunkKey,
|
||||||
chunkKeyOffset,
|
chunkKeyOffset,
|
||||||
isChunkKey,
|
isChunkKey,
|
||||||
|
gitShaKey,
|
||||||
|
keyGitSha,
|
||||||
isKeyPrefix,
|
isKeyPrefix,
|
||||||
splitKeyNameExtension,
|
splitKeyNameExtension,
|
||||||
|
|
||||||
|
@ -35,6 +38,7 @@ import qualified Data.Attoparsec.ByteString as A
|
||||||
|
|
||||||
import Common
|
import Common
|
||||||
import Types.Key
|
import Types.Key
|
||||||
|
import Git.Types
|
||||||
import Utility.QuickCheck
|
import Utility.QuickCheck
|
||||||
import Utility.Bloom
|
import Utility.Bloom
|
||||||
import Utility.Aeson
|
import Utility.Aeson
|
||||||
|
@ -58,6 +62,23 @@ chunkKeyOffset k = (*)
|
||||||
isChunkKey :: Key -> Bool
|
isChunkKey :: Key -> Bool
|
||||||
isChunkKey k = isJust (fromKey keyChunkSize k) && isJust (fromKey keyChunkNum k)
|
isChunkKey k = isJust (fromKey keyChunkSize k) && isJust (fromKey keyChunkNum k)
|
||||||
|
|
||||||
|
-- Encodes a git sha as a key.
|
||||||
|
--
|
||||||
|
-- This is not the same as a SHA1 key, because the mapping needs to be
|
||||||
|
-- bijective, also because git may not always use SHA1.
|
||||||
|
gitShaKey :: Sha -> Key
|
||||||
|
gitShaKey (Ref s) = mkKey $ \kd -> kd
|
||||||
|
{ keyName = s
|
||||||
|
, keyVariety = OtherKey "GIT"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Reverse of gitShaKey
|
||||||
|
keyGitSha :: Key -> Maybe Sha
|
||||||
|
keyGitSha k
|
||||||
|
| fromKey keyVariety k == OtherKey "GIT" =
|
||||||
|
Just (Ref (fromKey keyName k))
|
||||||
|
| otherwise = Nothing
|
||||||
|
|
||||||
serializeKey :: Key -> String
|
serializeKey :: Key -> String
|
||||||
serializeKey = decodeBS' . serializeKey'
|
serializeKey = decodeBS' . serializeKey'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue