module Darcs.Repository.InternalTypes ( Repository, PristineType(..)
, repoCache, modifyCache
, repoPatchType
, repoFormat
, repoLocation
, withRepoLocation
, repoPristineType
, coerceR
, coerceU
, coerceT
, mkRepo
) where
import Prelude ()
import Darcs.Prelude
import Data.Coerce ( coerce )
import Data.List ( nub, sortBy )
import Darcs.Repository.Cache ( Cache (..) , compareByLocality )
import Darcs.Repository.Format ( RepoFormat )
import Darcs.Patch ( RepoType )
import Darcs.Patch.Type ( PatchType(..) )
import Darcs.Util.File ( withCurrentDirectory )
data PristineType
= NoPristine
| PlainPristine
| HashedPristine
deriving ( Show, Eq )
data Repository (rt :: RepoType) (p :: * -> * -> *) wRecordedstate wUnrecordedstate wTentativestate =
Repo !String !RepoFormat !PristineType Cache deriving ( Show )
repoLocation :: Repository rt p wR wU wT -> String
repoLocation (Repo loc _ _ _) = loc
withRepoLocation :: Repository rt p wR wU wT -> IO a -> IO a
withRepoLocation repo = withCurrentDirectory (repoLocation repo)
repoFormat :: Repository rt p wR wU wT -> RepoFormat
repoFormat (Repo _ fmt _ _) = fmt
repoPristineType :: Repository rt p wR wU wT -> PristineType
repoPristineType (Repo _ _ pr _) = pr
repoCache :: Repository rt p wR wU wT -> Cache
repoCache (Repo _ _ _ c) = c
modifyCache :: forall rt p wR wU wT . Repository rt p wR wU wT -> (Cache -> Cache) -> Repository rt p wR wU wT
modifyCache (Repo dir rf pristine cache) f
= Repo dir rf pristine $ cmap ( sortBy compareByLocality . nub ) $ f cache
where cmap g (Ca c) = Ca (g c)
repoPatchType :: Repository rt p wR wU wT -> PatchType rt p
repoPatchType _ = PatchType
coerceR :: Repository rt p wR wU wT -> Repository rt p wR' wU wT
coerceR = coerce
coerceU :: Repository rt p wR wU wT -> Repository rt p wR wU' wT
coerceU = coerce
coerceT :: Repository rt p wR wU wT -> Repository rt p wR wU wT'
coerceT = coerce
mkRepo :: String -> RepoFormat -> PristineType -> Cache -> Repository rt p wR wU wT
mkRepo = Repo