2010-10-18 06:06:27 +00:00
|
|
|
{- git-annex internal data types
|
2010-10-14 06:52:17 +00:00
|
|
|
-
|
2010-10-18 06:06:27 +00:00
|
|
|
- Most things should not need this, using Types and/or Annex instead.
|
2010-10-27 20:53:54 +00:00
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
2010-10-14 06:52:17 +00:00
|
|
|
-}
|
2010-10-12 19:52:18 +00:00
|
|
|
|
2010-10-18 06:06:27 +00:00
|
|
|
module TypeInternals where
|
2010-10-12 19:52:18 +00:00
|
|
|
|
2010-10-14 23:36:11 +00:00
|
|
|
import Control.Monad.State (StateT)
|
2010-10-13 00:04:36 +00:00
|
|
|
import Data.String.Utils
|
2010-10-21 20:30:16 +00:00
|
|
|
import qualified Data.Map as M
|
2010-10-16 20:20:49 +00:00
|
|
|
|
2010-10-14 06:36:41 +00:00
|
|
|
import qualified GitRepo as Git
|
2010-10-26 19:59:50 +00:00
|
|
|
import qualified GitQueue
|
2010-10-12 19:52:18 +00:00
|
|
|
|
2010-10-21 20:30:16 +00:00
|
|
|
-- command-line flags
|
|
|
|
type FlagName = String
|
|
|
|
data Flag =
|
|
|
|
FlagBool Bool |
|
|
|
|
FlagString String
|
2010-10-19 17:08:05 +00:00
|
|
|
deriving (Eq, Read, Show)
|
2010-10-15 01:10:59 +00:00
|
|
|
|
2010-10-14 06:52:17 +00:00
|
|
|
-- git-annex's runtime state type doesn't really belong here,
|
|
|
|
-- but it uses Backend, so has to be here to avoid a depends loop.
|
2010-10-14 01:28:47 +00:00
|
|
|
data AnnexState = AnnexState {
|
2010-10-14 06:36:41 +00:00
|
|
|
repo :: Git.Repo,
|
2010-10-15 01:10:59 +00:00
|
|
|
backends :: [Backend],
|
2010-10-17 15:47:36 +00:00
|
|
|
supportedBackends :: [Backend],
|
2010-10-26 19:59:50 +00:00
|
|
|
flags :: M.Map FlagName Flag,
|
|
|
|
repoqueue :: GitQueue.Queue
|
2010-10-12 20:06:10 +00:00
|
|
|
} deriving (Show)
|
|
|
|
|
2010-10-14 01:28:47 +00:00
|
|
|
-- git-annex's monad
|
|
|
|
type Annex = StateT AnnexState IO
|
|
|
|
|
2010-10-14 23:36:11 +00:00
|
|
|
-- annexed filenames are mapped through a backend into keys
|
2010-10-25 22:32:29 +00:00
|
|
|
type KeyName = String
|
2010-10-14 23:36:11 +00:00
|
|
|
type BackendName = String
|
2010-11-07 21:26:21 +00:00
|
|
|
data Key = Key (BackendName, KeyName) deriving (Eq, Ord)
|
2010-10-13 06:31:24 +00:00
|
|
|
|
2010-10-21 20:30:16 +00:00
|
|
|
-- constructs a key in a backend
|
2010-10-25 22:32:29 +00:00
|
|
|
genKey :: Backend -> KeyName -> Key
|
2010-10-21 20:30:16 +00:00
|
|
|
genKey b f = Key (name b,f)
|
|
|
|
|
2010-10-14 23:36:11 +00:00
|
|
|
-- show a key to convert it to a string; the string includes the
|
|
|
|
-- name of the backend to avoid collisions between key strings
|
2010-10-13 06:31:24 +00:00
|
|
|
instance Show Key where
|
2010-10-14 23:36:11 +00:00
|
|
|
show (Key (b, k)) = b ++ ":" ++ k
|
|
|
|
|
|
|
|
instance Read Key where
|
|
|
|
readsPrec _ s = [((Key (b,k)) ,"")]
|
|
|
|
where
|
|
|
|
l = split ":" s
|
|
|
|
b = l !! 0
|
|
|
|
k = join ":" $ drop 1 l
|
2010-10-12 20:06:10 +00:00
|
|
|
|
2010-10-15 00:05:04 +00:00
|
|
|
backendName :: Key -> BackendName
|
2010-10-31 20:00:32 +00:00
|
|
|
backendName (Key (b,_)) = b
|
2010-10-25 22:32:29 +00:00
|
|
|
keyName :: Key -> KeyName
|
2010-10-31 20:00:32 +00:00
|
|
|
keyName (Key (_,k)) = k
|
2010-10-15 00:05:04 +00:00
|
|
|
|
2010-10-16 20:15:31 +00:00
|
|
|
-- this structure represents a key-value backend
|
2010-10-12 20:06:10 +00:00
|
|
|
data Backend = Backend {
|
|
|
|
-- name of this backend
|
|
|
|
name :: String,
|
|
|
|
-- converts a filename to a key
|
2010-10-14 01:28:47 +00:00
|
|
|
getKey :: FilePath -> Annex (Maybe Key),
|
2010-10-12 20:06:10 +00:00
|
|
|
-- stores a file's contents to a key
|
2010-10-14 01:28:47 +00:00
|
|
|
storeFileKey :: FilePath -> Key -> Annex Bool,
|
2010-10-12 20:06:10 +00:00
|
|
|
-- retrieves a key's contents to a file
|
2010-10-14 01:28:47 +00:00
|
|
|
retrieveKeyFile :: Key -> FilePath -> Annex Bool,
|
2010-10-12 20:06:10 +00:00
|
|
|
-- removes a key
|
2010-10-14 19:31:44 +00:00
|
|
|
removeKey :: Key -> Annex Bool,
|
|
|
|
-- checks if a backend is storing the content of a key
|
|
|
|
hasKey :: Key -> Annex Bool
|
2010-10-12 19:52:18 +00:00
|
|
|
}
|
2010-10-12 20:06:10 +00:00
|
|
|
|
|
|
|
instance Show Backend where
|
|
|
|
show backend = "Backend { name =\"" ++ (name backend) ++ "\" }"
|