split up Types

This commit is contained in:
Joey Hess 2010-10-11 17:19:55 -04:00
parent de3dafae80
commit af82586adf
11 changed files with 49 additions and 55 deletions

View file

@ -8,11 +8,28 @@ import System.Directory
import GitRepo
import Utility
import Locations
import Types
import Backend
import BackendList
import LocationLog
-- git-annex's runtime state
data State = State {
repo :: GitRepo,
gitconfig :: GitConfig
}
data GitConfig = GitConfig {
annex_name :: String,
annex_numcopies :: Int,
annex_backends :: [Backend]
}
{- An annexed file's content is stored somewhere under .git/annex/ -}
annexDir :: GitRepo -> Key -> IO FilePath
annexDir repo key = do
dir <- gitDir repo
return $ dir ++ "/annex/" ++ key
{- On startup, examine the git repo, prepare it, and record state for
- later. -}
startAnnex :: IO State

View file

@ -22,7 +22,23 @@ import System.Directory
import Locations
import GitRepo
import Utility
import Types
-- annexed filenames are mapped into keys
type Key = FilePath
-- this structure represents a key/value backend
data Backend = Backend {
-- name of this backend
name :: String,
-- converts a filename to a key
getKey :: GitRepo -> FilePath -> IO (Maybe Key),
-- stores a file's contents to a key
storeFileKey :: GitRepo -> FilePath -> Key -> IO Bool,
-- retrieves a key's contents to a file
retrieveKeyFile :: Key -> FilePath -> IO Bool,
-- removes a key
removeKey :: Key -> IO Bool
}
instance Show Backend where
show backend = "Backend { name =\"" ++ (name backend) ++ "\" }"

View file

@ -3,9 +3,10 @@
module BackendChecksum (backend) where
import Types
import qualified BackendFile
import Data.Digest.Pure.SHA
import Backend
import GitRepo
-- based on BackendFile just with a different key type
backend = BackendFile.backend {

View file

@ -3,7 +3,8 @@
module BackendFile (backend) where
import Types
import Backend
import GitRepo
backend = Backend {
name = "file",

View file

@ -3,8 +3,9 @@
module BackendList where
import Backend
-- When adding a new backend, import it here and add it to the list.
import Types
import qualified BackendFile
import qualified BackendChecksum
import qualified BackendUrl

View file

@ -3,7 +3,8 @@
module BackendUrl (backend) where
import Types
import Backend
import GitRepo
backend = Backend {
name = "url",

View file

@ -7,7 +7,6 @@
module CmdLine where
import System.Console.GetOpt
import Types
import Annex
data Mode = Add | Push | Pull | Want | Get | Drop | Unannex

View file

@ -10,7 +10,12 @@ import System.IO
import Data.String.Utils
import Control.Exception
import Utility
import Types
-- a git repository
data GitRepo = GitRepo {
top :: FilePath,
bare :: Bool
}
{- GitRepo constructor -}
gitRepo :: FilePath -> IO GitRepo

View file

@ -28,7 +28,6 @@ import Data.Char
import GitRepo
import Utility
import Locations
import Types
data LogLine = LogLine {
date :: POSIXTime,

View file

@ -3,15 +3,8 @@
module Locations where
import Types
import GitRepo
{- An annexed file's content is stored somewhere under .git/annex/ -}
annexDir :: GitRepo -> Key -> IO FilePath
annexDir repo key = do
dir <- gitDir repo
return $ dir ++ "/annex/" ++ key
{- Long-term, cross-repo state is stored in files inside the .git-annex
- directory, in the git repository. -}
stateLoc = ".git-annex"

View file

@ -1,39 +0,0 @@
{- git-annex data types
- -}
module Types where
-- annexed filenames are mapped into keys
type Key = String
-- this structure represents a key/value backend
data Backend = Backend {
-- name of this backend
name :: String,
-- converts a filename to a key
getKey :: GitRepo -> FilePath -> IO (Maybe Key),
-- stores a file's contents to a key
storeFileKey :: GitRepo -> FilePath -> Key -> IO Bool,
-- retrieves a key's contents to a file
retrieveKeyFile :: Key -> FilePath -> IO Bool,
-- removes a key
removeKey :: Key -> IO Bool
}
-- a git repository
data GitRepo = GitRepo {
top :: FilePath,
bare :: Bool
}
-- git-annex's runtime state
data State = State {
repo :: GitRepo,
gitconfig :: GitConfig
}
data GitConfig = GitConfig {
annex_name :: String,
annex_numcopies :: Int,
annex_backends :: [Backend]
}