#include "gadts.h"
module Darcs.Repository.InternalTypes ( Repository(..), RepoType(..), Pristine(..)
, extractCache, extractOptions, modifyCache
) where
import Data.List ( nub, sortBy )
import Darcs.Repository.Cache ( Cache (..) , compareByLocality )
import Darcs.Flags ( DarcsFlag )
import Darcs.Repository.Format ( RepoFormat )
import Darcs.Patch ( RepoPatch )
data Pristine
= NoPristine !String
| PlainPristine !String
| HashedPristine
deriving ( Show )
data Repository (p :: * C(-> * -> *)) C(recordedstate unrecordedstate tentativestate) = Repo !String ![DarcsFlag] !RepoFormat !(RepoType p) deriving ( Show )
data RepoType (p :: * C(-> * -> *)) = DarcsRepository !Pristine Cache deriving ( Show )
extractCache :: Repository p C(r u t) -> Cache
extractCache (Repo _ _ _ (DarcsRepository _ c)) = c
extractOptions :: Repository p C(r u t) -> [DarcsFlag]
extractOptions (Repo _ opts _ _) = opts
modifyCache :: FORALL(p r u t) (RepoPatch p) => Repository p C(r u t) -> (Cache -> Cache) -> Repository p C(r u t)
modifyCache (Repo dir opts rf (DarcsRepository pristine cache)) f = Repo dir opts rf dr
where dr = DarcsRepository pristine . cmap ( sortBy compareByLocality . nub ) $ f cache
cmap f (Ca c) = Ca (f c)