1-- Copyright (C) 2006-2007 David Roundy 2-- 3-- This program is free software; you can redistribute it and/or modify 4-- it under the terms of the GNU General Public License as published by 5-- the Free Software Foundation; either version 2, or (at your option) 6-- any later version. 7-- 8-- This program is distributed in the hope that it will be useful, 9-- but WITHOUT ANY WARRANTY; without even the implied warranty of 10-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11-- GNU General Public License for more details. 12-- 13-- You should have received a copy of the GNU General Public License 14-- along with this program; if not, write to the Free Software Foundation, 15-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16module Darcs.Repository.InternalTypes ( Repository, PristineType(..) 17 , repoCache, modifyCache 18 , repoFormat 19 , repoLocation 20 , withRepoLocation 21 , repoPristineType 22 , unsafeCoerceRepoType 23 , unsafeCoercePatchType 24 , unsafeCoerceR 25 , unsafeCoerceU 26 , unsafeCoerceT 27 , mkRepo 28 ) where 29 30import Darcs.Prelude 31 32import Darcs.Repository.Cache ( Cache ) 33import Darcs.Repository.Format ( RepoFormat ) 34import Darcs.Patch ( RepoType ) 35import Darcs.Util.File ( withCurrentDirectory ) 36import Unsafe.Coerce ( unsafeCoerce ) 37 38data PristineType 39 = NoPristine 40 | PlainPristine 41 | HashedPristine 42 deriving ( Show, Eq ) 43 44-- |A @Repository@ is a token representing the state of a repository on disk. 45-- It is parameterized by the patch type in the repository, and witnesses for 46-- the recorded state of the repository (i.e. what darcs get would retrieve), 47-- the unrecorded state (what's in the working tree now), 48-- and the tentative state, which represents work in progress that will 49-- eventually become the new recorded state unless something goes wrong. 50data Repository (rt :: RepoType) (p :: * -> * -> *) wRecordedstate wUnrecordedstate wTentativestate = 51 Repo !String !RepoFormat !PristineType Cache deriving ( Show ) 52 53type role Repository nominal nominal nominal nominal nominal 54 55repoLocation :: Repository rt p wR wU wT -> String 56repoLocation (Repo loc _ _ _) = loc 57 58withRepoLocation :: Repository rt p wR wU wT -> IO a -> IO a 59withRepoLocation repo = withCurrentDirectory (repoLocation repo) 60 61repoFormat :: Repository rt p wR wU wT -> RepoFormat 62repoFormat (Repo _ fmt _ _) = fmt 63 64repoPristineType :: Repository rt p wR wU wT -> PristineType 65repoPristineType (Repo _ _ pr _) = pr 66 67repoCache :: Repository rt p wR wU wT -> Cache 68repoCache (Repo _ _ _ c) = c 69 70modifyCache :: (Cache -> Cache) -> Repository rt p wR wU wT -> Repository rt p wR wU wT 71modifyCache g (Repo l f p c) = Repo l f p (g c) 72 73unsafeCoerceRepoType :: Repository rt p wR wU wT -> Repository rt' p wR wU wT 74unsafeCoerceRepoType = unsafeCoerce 75 76unsafeCoercePatchType :: Repository rt p wR wU wT -> Repository rt p' wR wU wT 77unsafeCoercePatchType = unsafeCoerce 78 79unsafeCoerceR :: Repository rt p wR wU wT -> Repository rt p wR' wU wT 80unsafeCoerceR = unsafeCoerce 81 82unsafeCoerceU :: Repository rt p wR wU wT -> Repository rt p wR wU' wT 83unsafeCoerceU = unsafeCoerce 84 85unsafeCoerceT :: Repository rt p wR wU wT -> Repository rt p wR wU wT' 86unsafeCoerceT = unsafeCoerce 87 88mkRepo :: String -> RepoFormat -> PristineType -> Cache -> Repository rt p wR wU wT 89mkRepo = Repo 90