{-# OPTIONS_GHC -fno-warn-orphans #-}
module Darcs.Patch.V3 ( RepoPatchV3 ) where

import Darcs.Prelude

import Darcs.Patch.Annotate ()
import Darcs.Patch.FromPrim ( FromPrim(..) )
import Darcs.Patch.Prim.Named
  ( PrimPatchId
  , anonymousNamedPrim, namedPrim, positivePrimPatchIds
  )
import Darcs.Patch.Witnesses.Ordered ( FL(..) )
import qualified Darcs.Patch.V3.Core as Core ( RepoPatchV3(..) )
import Darcs.Patch.V3.Resolution ()

type RepoPatchV3 = Core.RepoPatchV3 PrimPatchId

-- This instance is specialised to PrimPatchId because it is dependent
-- on the relationship between PatchInfo and PrimPatchId
instance FromPrim (RepoPatchV3 prim) where
  fromAnonymousPrim :: PrimOf (RepoPatchV3 prim) wX wY -> RepoPatchV3 prim wX wY
fromAnonymousPrim = PrimWithName PrimPatchId prim wX wY -> RepoPatchV3 prim wX wY
forall name (prim :: * -> * -> *) wX wY.
PrimWithName name prim wX wY -> RepoPatchV3 name prim wX wY
Core.Prim (PrimWithName PrimPatchId prim wX wY -> RepoPatchV3 prim wX wY)
-> (prim wX wY -> PrimWithName PrimPatchId prim wX wY)
-> prim wX wY
-> RepoPatchV3 prim wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. prim wX wY -> PrimWithName PrimPatchId prim wX wY
forall (p :: * -> * -> *) wX wY. p wX wY -> NamedPrim p wX wY
anonymousNamedPrim
  fromPrim :: PatchId (RepoPatchV3 prim)
-> PrimOf (RepoPatchV3 prim) wX wY -> RepoPatchV3 prim wX wY
fromPrim PatchId (RepoPatchV3 prim)
pid PrimOf (RepoPatchV3 prim) wX wY
p = PrimWithName PrimPatchId prim wX wY -> RepoPatchV3 prim wX wY
forall name (prim :: * -> * -> *) wX wY.
PrimWithName name prim wX wY -> RepoPatchV3 name prim wX wY
Core.Prim (PrimPatchId -> prim wX wY -> PrimWithName PrimPatchId prim wX wY
forall (p :: * -> * -> *) wX wY.
PrimPatchId -> p wX wY -> NamedPrim p wX wY
namedPrim PatchId (RepoPatchV3 prim)
PrimPatchId
pid prim wX wY
PrimOf (RepoPatchV3 prim) wX wY
p)
  fromPrims :: PatchInfo
-> FL (PrimOf (RepoPatchV3 prim)) wX wY
-> FL (RepoPatchV3 prim) wX wY
fromPrims = [PrimPatchId] -> FL prim wX wY -> FL (RepoPatchV3 prim) wX wY
forall wX wY.
[PrimPatchId] -> FL prim wX wY -> FL (RepoPatchV3 prim) wX wY
go ([PrimPatchId] -> FL prim wX wY -> FL (RepoPatchV3 prim) wX wY)
-> (PatchInfo -> [PrimPatchId])
-> PatchInfo
-> FL prim wX wY
-> FL (RepoPatchV3 prim) wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfo -> [PrimPatchId]
positivePrimPatchIds
    where
      go :: [PrimPatchId] -> FL prim wX wY -> FL (RepoPatchV3 prim) wX wY
      go :: [PrimPatchId] -> FL prim wX wY -> FL (RepoPatchV3 prim) wX wY
go [PrimPatchId]
_ FL prim wX wY
NilFL = FL (RepoPatchV3 prim) wX wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
      go (PrimPatchId
pid:[PrimPatchId]
pids) (prim wX wY
p:>:FL prim wY wY
ps) = PatchId (RepoPatchV3 prim)
-> PrimOf (RepoPatchV3 prim) wX wY -> RepoPatchV3 prim wX wY
forall (p :: * -> * -> *) wX wY.
FromPrim p =>
PatchId p -> PrimOf p wX wY -> p wX wY
fromPrim PatchId (RepoPatchV3 prim)
PrimPatchId
pid prim wX wY
PrimOf (RepoPatchV3 prim) wX wY
p RepoPatchV3 prim wX wY
-> FL (RepoPatchV3 prim) wY wY -> FL (RepoPatchV3 prim) wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: [PrimPatchId] -> FL prim wY wY -> FL (RepoPatchV3 prim) wY wY
forall wX wY.
[PrimPatchId] -> FL prim wX wY -> FL (RepoPatchV3 prim) wX wY
go [PrimPatchId]
pids FL prim wY wY
ps
      go [] FL prim wX wY
_ = [Char] -> FL (RepoPatchV3 prim) wX wY
forall a. HasCallStack => [Char] -> a
error [Char]
"positivePrimPatchIds should return an infinite list"