-- it is stupid that we need UndecidableInstances just to call another
-- type function (see instance Apply below which requires this)
{-# LANGUAGE UndecidableInstances #-}
module Darcs.Patch.V1.Prim ( Prim(..) ) where

import Darcs.Prelude

import Data.Coerce ( coerce )

import Darcs.Patch.Annotate ( Annotate(..) )
import Darcs.Patch.Apply ( Apply(..) )
import Darcs.Patch.Commute ( Commute(..) )
import Darcs.Patch.FileHunk ( IsHunk(..) )
import Darcs.Patch.Format
    ( PatchListFormat(..)
    , ListFormat(ListFormatV1)
    , FileNameFormat(FileNameFormatV1,FileNameFormatDisplay) )
import Darcs.Patch.Inspect ( PatchInspect )
import Darcs.Patch.Invert ( Invert )
import Darcs.Patch.Merge ( CleanMerge )
import Darcs.Patch.Read ( ReadPatch(..) )
import Darcs.Patch.Repair ( RepairToFL(..) )
import Darcs.Patch.Show
    ( ShowPatchBasic(..)
    , ShowPatchFor(..)
    , ShowPatch(..)
    , ShowContextPatch(..)
    )
import Darcs.Patch.Summary ( plainSummaryPrim, plainSummaryPrims )

import Darcs.Patch.Witnesses.Eq ( Eq2 )
import Darcs.Patch.Witnesses.Show ( Show1, Show2 )
import Darcs.Patch.Witnesses.Sealed ( mapSeal )

import Darcs.Patch.Prim.Class
    ( PrimConstruct(..), PrimCanonize(..)
    , PrimClassify(..), PrimDetails(..)
    , PrimShow(..), PrimRead(..)
    , PrimApply(..)
    , PrimSift(..)
    , PrimMangleUnravelled(..)
    )
import qualified Darcs.Patch.Prim.V1 as Base ( Prim )

newtype Prim x y = Prim { forall x y. Prim x y -> Prim x y
unPrim :: Base.Prim x y } deriving
    ( forall wX wY. Prim wX wY -> AnnotatedM ()
forall (p :: * -> * -> *).
(forall wX wY. p wX wY -> AnnotatedM ()) -> Annotate p
annotate :: forall wX wY. Prim wX wY -> AnnotatedM ()
$cannotate :: forall wX wY. Prim wX wY -> AnnotatedM ()
Annotate
    , forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
Prim wX wY -> m ()
forall (p :: * -> * -> *).
(forall (m :: * -> *) wX wY.
 ApplyMonad (ApplyState p) m =>
 p wX wY -> m ())
-> (forall (m :: * -> *) wX wY.
    ApplyMonad (ApplyState p) m =>
    p wX wY -> m ())
-> Apply p
unapply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
Prim wX wY -> m ()
$cunapply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
Prim wX wY -> m ()
apply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
Prim wX wY -> m ()
$capply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
Prim wX wY -> m ()
Apply
    , forall wX wY.
(:\/:) Prim Prim wX wY -> Maybe ((:/\:) Prim Prim wX wY)
forall (p :: * -> * -> *).
(forall wX wY. (:\/:) p p wX wY -> Maybe ((:/\:) p p wX wY))
-> CleanMerge p
cleanMerge :: forall wX wY.
(:\/:) Prim Prim wX wY -> Maybe ((:/\:) Prim Prim wX wY)
$ccleanMerge :: forall wX wY.
(:\/:) Prim Prim wX wY -> Maybe ((:/\:) Prim Prim wX wY)
CleanMerge
    , forall wX wY. (:>) Prim Prim wX wY -> Maybe ((:>) Prim Prim wX wY)
forall (p :: * -> * -> *).
(forall wX wY. (:>) p p wX wY -> Maybe ((:>) p p wX wY))
-> Commute p
commute :: forall wX wY. (:>) Prim Prim wX wY -> Maybe ((:>) Prim Prim wX wY)
$ccommute :: forall wX wY. (:>) Prim Prim wX wY -> Maybe ((:>) Prim Prim wX wY)
Commute
    , forall wX wY. Prim wX wY -> Prim wY wX
forall (p :: * -> * -> *).
(forall wX wY. p wX wY -> p wY wX) -> Invert p
invert :: forall wX wY. Prim wX wY -> Prim wY wX
$cinvert :: forall wX wY. Prim wX wY -> Prim wY wX
Invert
    , forall wX wY. Prim wX wY -> Maybe (FileHunk wX wY)
forall (p :: * -> * -> *).
(forall wX wY. p wX wY -> Maybe (FileHunk wX wY)) -> IsHunk p
isHunk :: forall wX wY. Prim wX wY -> Maybe (FileHunk wX wY)
$cisHunk :: forall wX wY. Prim wX wY -> Maybe (FileHunk wX wY)
IsHunk
    , forall wA wB wC. Prim wA wB -> Prim wA wC -> EqCheck wB wC
forall wA wC wB. Prim wA wC -> Prim wB wC -> EqCheck wA wB
forall wA wB wC wD. Prim wA wB -> Prim wC wD -> Bool
forall (p :: * -> * -> *).
(forall wA wB wC wD. p wA wB -> p wC wD -> Bool)
-> (forall wA wB wC. p wA wB -> p wA wC -> EqCheck wB wC)
-> (forall wA wC wB. p wA wC -> p wB wC -> EqCheck wA wB)
-> Eq2 p
=/\= :: forall wA wC wB. Prim wA wC -> Prim wB wC -> EqCheck wA wB
$c=/\= :: forall wA wC wB. Prim wA wC -> Prim wB wC -> EqCheck wA wB
=\/= :: forall wA wB wC. Prim wA wB -> Prim wA wC -> EqCheck wB wC
$c=\/= :: forall wA wB wC. Prim wA wB -> Prim wA wC -> EqCheck wB wC
unsafeCompare :: forall wA wB wC wD. Prim wA wB -> Prim wC wD -> Bool
$cunsafeCompare :: forall wA wB wC wD. Prim wA wB -> Prim wC wD -> Bool
Eq2
    , forall wX wY. Prim wX wY -> [AnchoredPath]
forall wX wY. (ByteString -> Bool) -> Prim wX wY -> Bool
forall (p :: * -> * -> *).
(forall wX wY. p wX wY -> [AnchoredPath])
-> (forall wX wY. (ByteString -> Bool) -> p wX wY -> Bool)
-> PatchInspect p
hunkMatches :: forall wX wY. (ByteString -> Bool) -> Prim wX wY -> Bool
$chunkMatches :: forall wX wY. (ByteString -> Bool) -> Prim wX wY -> Bool
listTouchedFiles :: forall wX wY. Prim wX wY -> [AnchoredPath]
$clistTouchedFiles :: forall wX wY. Prim wX wY -> [AnchoredPath]
PatchInspect
    , forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
FL Prim wX wY -> m ()
forall (prim :: * -> * -> *).
(forall (m :: * -> *) wX wY.
 ApplyMonad (ApplyState prim) m =>
 FL prim wX wY -> m ())
-> PrimApply prim
applyPrimFL :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
FL Prim wX wY -> m ()
$capplyPrimFL :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
FL Prim wX wY -> m ()
PrimApply
    , forall wX wY. DiffAlgorithm -> FL Prim wX wY -> FL Prim wX wY
forall wX wY. DiffAlgorithm -> Prim wX wY -> FL Prim wX wY
forall wX wY. FL Prim wX wY -> FL Prim wX wY
forall wX wY. (:>) Prim Prim wX wY -> Maybe (FL Prim wX wY)
forall wX wZ wY. Prim wX wZ -> Prim wX wY -> Maybe (Prim wY wZ)
forall wX wY wZ. Prim wX wY -> Prim wY wZ -> Maybe (Prim wX wZ)
forall (prim :: * -> * -> *).
(forall wX wY. FL prim wX wY -> FL prim wX wY)
-> (forall wX wY. FL prim wX wY -> FL prim wX wY)
-> (forall wX wY. DiffAlgorithm -> prim wX wY -> FL prim wX wY)
-> (forall wX wY. DiffAlgorithm -> FL prim wX wY -> FL prim wX wY)
-> (forall wX wY. (:>) prim prim wX wY -> Maybe (FL prim wX wY))
-> (forall wX wY wZ.
    prim wX wY -> prim wY wZ -> Maybe (prim wX wZ))
-> (forall wX wZ wY.
    prim wX wZ -> prim wX wY -> Maybe (prim wY wZ))
-> PrimCanonize prim
primDecoalesce :: forall wX wZ wY. Prim wX wZ -> Prim wX wY -> Maybe (Prim wY wZ)
$cprimDecoalesce :: forall wX wZ wY. Prim wX wZ -> Prim wX wY -> Maybe (Prim wY wZ)
primCoalesce :: forall wX wY wZ. Prim wX wY -> Prim wY wZ -> Maybe (Prim wX wZ)
$cprimCoalesce :: forall wX wY wZ. Prim wX wY -> Prim wY wZ -> Maybe (Prim wX wZ)
coalesce :: forall wX wY. (:>) Prim Prim wX wY -> Maybe (FL Prim wX wY)
$ccoalesce :: forall wX wY. (:>) Prim Prim wX wY -> Maybe (FL Prim wX wY)
canonizeFL :: forall wX wY. DiffAlgorithm -> FL Prim wX wY -> FL Prim wX wY
$ccanonizeFL :: forall wX wY. DiffAlgorithm -> FL Prim wX wY -> FL Prim wX wY
canonize :: forall wX wY. DiffAlgorithm -> Prim wX wY -> FL Prim wX wY
$ccanonize :: forall wX wY. DiffAlgorithm -> Prim wX wY -> FL Prim wX wY
sortCoalesceFL :: forall wX wY. FL Prim wX wY -> FL Prim wX wY
$csortCoalesceFL :: forall wX wY. FL Prim wX wY -> FL Prim wX wY
tryToShrink :: forall wX wY. FL Prim wX wY -> FL Prim wX wY
$ctryToShrink :: forall wX wY. FL Prim wX wY -> FL Prim wX wY
PrimCanonize
    , forall wX wY. Prim wX wY -> Bool
forall wX wY. Prim wX wY -> Maybe AnchoredPath
forall (prim :: * -> * -> *).
(forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Bool)
-> (forall wX wY. prim wX wY -> Maybe AnchoredPath)
-> PrimClassify prim
is_filepatch :: forall wX wY. Prim wX wY -> Maybe AnchoredPath
$cis_filepatch :: forall wX wY. Prim wX wY -> Maybe AnchoredPath
primIsSetpref :: forall wX wY. Prim wX wY -> Bool
$cprimIsSetpref :: forall wX wY. Prim wX wY -> Bool
primIsBinary :: forall wX wY. Prim wX wY -> Bool
$cprimIsBinary :: forall wX wY. Prim wX wY -> Bool
primIsTokReplace :: forall wX wY. Prim wX wY -> Bool
$cprimIsTokReplace :: forall wX wY. Prim wX wY -> Bool
primIsHunk :: forall wX wY. Prim wX wY -> Bool
$cprimIsHunk :: forall wX wY. Prim wX wY -> Bool
primIsMove :: forall wX wY. Prim wX wY -> Bool
$cprimIsMove :: forall wX wY. Prim wX wY -> Bool
primIsRmdir :: forall wX wY. Prim wX wY -> Bool
$cprimIsRmdir :: forall wX wY. Prim wX wY -> Bool
primIsAdddir :: forall wX wY. Prim wX wY -> Bool
$cprimIsAdddir :: forall wX wY. Prim wX wY -> Bool
primIsRmfile :: forall wX wY. Prim wX wY -> Bool
$cprimIsRmfile :: forall wX wY. Prim wX wY -> Bool
primIsAddfile :: forall wX wY. Prim wX wY -> Bool
$cprimIsAddfile :: forall wX wY. Prim wX wY -> Bool
PrimClassify
    , forall wX wY. String -> String -> String -> Prim wX wY
forall wX wY. AnchoredPath -> Prim wX wY
forall wX wY.
AnchoredPath -> Int -> [ByteString] -> [ByteString] -> Prim wX wY
forall wX wY.
AnchoredPath -> String -> String -> String -> Prim wX wY
forall wX wY.
AnchoredPath -> ByteString -> ByteString -> Prim wX wY
forall wX wY. AnchoredPath -> AnchoredPath -> Prim wX wY
forall wX wY. FileHunk wX wY -> Prim wX wY
forall (prim :: * -> * -> *).
(forall wX wY. AnchoredPath -> prim wX wY)
-> (forall wX wY. AnchoredPath -> prim wX wY)
-> (forall wX wY. AnchoredPath -> prim wX wY)
-> (forall wX wY. AnchoredPath -> prim wX wY)
-> (forall wX wY. AnchoredPath -> AnchoredPath -> prim wX wY)
-> (forall wX wY. String -> String -> String -> prim wX wY)
-> (forall wX wY.
    AnchoredPath -> Int -> [ByteString] -> [ByteString] -> prim wX wY)
-> (forall wX wY.
    AnchoredPath -> String -> String -> String -> prim wX wY)
-> (forall wX wY.
    AnchoredPath -> ByteString -> ByteString -> prim wX wY)
-> (forall wX wY. FileHunk wX wY -> prim wX wY)
-> PrimConstruct prim
primFromHunk :: forall wX wY. FileHunk wX wY -> Prim wX wY
$cprimFromHunk :: forall wX wY. FileHunk wX wY -> Prim wX wY
binary :: forall wX wY.
AnchoredPath -> ByteString -> ByteString -> Prim wX wY
$cbinary :: forall wX wY.
AnchoredPath -> ByteString -> ByteString -> Prim wX wY
tokreplace :: forall wX wY.
AnchoredPath -> String -> String -> String -> Prim wX wY
$ctokreplace :: forall wX wY.
AnchoredPath -> String -> String -> String -> Prim wX wY
hunk :: forall wX wY.
AnchoredPath -> Int -> [ByteString] -> [ByteString] -> Prim wX wY
$chunk :: forall wX wY.
AnchoredPath -> Int -> [ByteString] -> [ByteString] -> Prim wX wY
changepref :: forall wX wY. String -> String -> String -> Prim wX wY
$cchangepref :: forall wX wY. String -> String -> String -> Prim wX wY
move :: forall wX wY. AnchoredPath -> AnchoredPath -> Prim wX wY
$cmove :: forall wX wY. AnchoredPath -> AnchoredPath -> Prim wX wY
rmdir :: forall wX wY. AnchoredPath -> Prim wX wY
$crmdir :: forall wX wY. AnchoredPath -> Prim wX wY
adddir :: forall wX wY. AnchoredPath -> Prim wX wY
$cadddir :: forall wX wY. AnchoredPath -> Prim wX wY
rmfile :: forall wX wY. AnchoredPath -> Prim wX wY
$crmfile :: forall wX wY. AnchoredPath -> Prim wX wY
addfile :: forall wX wY. AnchoredPath -> Prim wX wY
$caddfile :: forall wX wY. AnchoredPath -> Prim wX wY
PrimConstruct
    , forall wX wY. Prim wX wY -> [SummDetail]
forall (prim :: * -> * -> *).
(forall wX wY. prim wX wY -> [SummDetail]) -> PrimDetails prim
summarizePrim :: forall wX wY. Prim wX wY -> [SummDetail]
$csummarizePrim :: forall wX wY. Prim wX wY -> [SummDetail]
PrimDetails
    , forall wX. Unravelled Prim wX -> Maybe (Mangled Prim wX)
forall (prim :: * -> * -> *).
(forall wX. Unravelled prim wX -> Maybe (Mangled prim wX))
-> PrimMangleUnravelled prim
mangleUnravelled :: forall wX. Unravelled Prim wX -> Maybe (Mangled Prim wX)
$cmangleUnravelled :: forall wX. Unravelled Prim wX -> Maybe (Mangled Prim wX)
PrimMangleUnravelled
    , forall wX wY. FL Prim wX wY -> Sealed (FL Prim wX)
forall (prim :: * -> * -> *).
(forall wX wY. FL prim wX wY -> Sealed (FL prim wX))
-> PrimSift prim
siftForPending :: forall wX wY. FL Prim wX wY -> Sealed (FL Prim wX)
$csiftForPending :: forall wX wY. FL Prim wX wY -> Sealed (FL Prim wX)
PrimSift
    , Int -> Prim x y -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall x y. Int -> Prim x y -> ShowS
forall x y. [Prim x y] -> ShowS
forall x y. Prim x y -> String
showList :: [Prim x y] -> ShowS
$cshowList :: forall x y. [Prim x y] -> ShowS
show :: Prim x y -> String
$cshow :: forall x y. Prim x y -> String
showsPrec :: Int -> Prim x y -> ShowS
$cshowsPrec :: forall x y. Int -> Prim x y -> ShowS
Show
    )

instance Show1 (Prim wX)

instance Show2 Prim

instance ReadPatch Prim where
  readPatch' :: forall wX. Parser (Sealed (Prim wX))
readPatch' = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (a :: * -> *) (b :: * -> *).
(forall wX. a wX -> b wX) -> Sealed a -> Sealed b
mapSeal forall x y. Prim x y -> Prim x y
Prim) (forall (prim :: * -> * -> *) wX.
PrimRead prim =>
FileNameFormat -> Parser (Sealed (prim wX))
readPrim FileNameFormat
FileNameFormatV1)

fileNameFormat :: ShowPatchFor -> FileNameFormat
fileNameFormat :: ShowPatchFor -> FileNameFormat
fileNameFormat ShowPatchFor
ForDisplay = FileNameFormat
FileNameFormatDisplay
fileNameFormat ShowPatchFor
ForStorage = FileNameFormat
FileNameFormatV1

instance ShowPatchBasic Prim where
  showPatch :: forall wX wY. ShowPatchFor -> Prim wX wY -> Doc
showPatch ShowPatchFor
fmt = forall (prim :: * -> * -> *) wA wB.
PrimShow prim =>
FileNameFormat -> prim wA wB -> Doc
showPrim (ShowPatchFor -> FileNameFormat
fileNameFormat ShowPatchFor
fmt) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x y. Prim x y -> Prim x y
unPrim

instance ShowContextPatch Prim where
  showContextPatch :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
ShowPatchFor -> Prim wX wY -> m Doc
showContextPatch ShowPatchFor
fmt = forall (prim :: * -> * -> *) (m :: * -> *) wA wB.
(PrimShow prim, ApplyMonad (ApplyState prim) m) =>
FileNameFormat -> prim wA wB -> m Doc
showPrimCtx (ShowPatchFor -> FileNameFormat
fileNameFormat ShowPatchFor
fmt) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x y. Prim x y -> Prim x y
unPrim

instance ShowPatch Prim where
  summary :: forall wX wY. Prim wX wY -> Doc
summary = forall (prim :: * -> * -> *) wX wY.
PrimDetails prim =>
prim wX wY -> Doc
plainSummaryPrim forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x y. Prim x y -> Prim x y
unPrim
  summaryFL :: forall wX wY. FL Prim wX wY -> Doc
summaryFL = forall (prim :: * -> * -> *) wX wY.
PrimDetails prim =>
Bool -> FL prim wX wY -> Doc
plainSummaryPrims Bool
False
  thing :: forall x y. Prim x y -> String
thing Prim wX wY
_ = String
"change"

instance PatchListFormat Prim where
  patchListFormat :: ListFormat Prim
patchListFormat = forall (p :: * -> * -> *). ListFormat p
ListFormatV1

instance RepairToFL Prim where
  applyAndTryToFixFL :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState Prim) m =>
Prim wX wY -> m (Maybe (String, FL Prim wX wY))
applyAndTryToFixFL = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap coerce :: forall a b. Coercible a b => a -> b
coerce forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(RepairToFL p, ApplyMonad (ApplyState p) m) =>
p wX wY -> m (Maybe (String, FL p wX wY))
applyAndTryToFixFL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x y. Prim x y -> Prim x y
unPrim