{-# LANGUAGE UndecidableInstances #-}
module Darcs.Patch.Rebase.Legacy.Item
( RebaseItem(..)
, toRebaseChanges
) where
import Darcs.Prelude
import Darcs.Patch.Format ( PatchListFormat(..) )
import Darcs.Patch.Named ( Named(..) )
import Darcs.Patch.Read ( ReadPatch(..) )
import Darcs.Patch.FromPrim ( PrimPatchBase, PrimOf )
import Darcs.Patch.Rebase.Change ( RebaseChange(..), addNamedToRebase )
import Darcs.Patch.Rebase.Fixup ( RebaseFixup(..) )
import Darcs.Patch.RepoPatch ( RepoPatch )
import Darcs.Util.Parser ( Parser, lexString )
import Darcs.Patch.Witnesses.Ordered
import Darcs.Patch.Witnesses.Sealed
import Darcs.Patch.Witnesses.Show ( Show1, Show2 )
import qualified Darcs.Util.Diff as D
import Control.Applicative ( (<|>) )
import qualified Data.ByteString as B ( ByteString )
import qualified Data.ByteString.Char8 as BC ( pack )
data RebaseItem p wX wY where
ToEdit :: Named p wX wY -> RebaseItem p wX wY
Fixup :: RebaseFixup (PrimOf p) wX wY -> RebaseItem p wX wY
deriving instance (Show2 p, Show2 (PrimOf p)) => Show (RebaseItem p wX wY)
instance (Show2 p, Show2 (PrimOf p)) => Show1 (RebaseItem p wX)
instance (Show2 p, Show2 (PrimOf p)) => Show2 (RebaseItem p)
toRebaseChanges :: RepoPatch p
=> FL (RebaseItem p) wX wY
-> Sealed (FL (RebaseChange (PrimOf p)) wX)
toRebaseChanges :: forall (p :: * -> * -> *) wX wY.
RepoPatch p =>
FL (RebaseItem p) wX wY -> Sealed (FL (RebaseChange (PrimOf p)) wX)
toRebaseChanges FL (RebaseItem p) wX wY
NilFL = FL (RebaseChange (PrimOf p)) wX wX
-> Sealed (FL (RebaseChange (PrimOf p)) wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed FL (RebaseChange (PrimOf p)) wX wX
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
toRebaseChanges (Fixup RebaseFixup (PrimOf p) wX wY
f :>: FL (RebaseItem p) wY wY
ps) =
case FL (RebaseItem p) wY wY -> Sealed (FL (RebaseChange (PrimOf p)) wY)
forall (p :: * -> * -> *) wX wY.
RepoPatch p =>
FL (RebaseItem p) wX wY -> Sealed (FL (RebaseChange (PrimOf p)) wX)
toRebaseChanges FL (RebaseItem p) wY wY
ps of
Sealed (RC FL (RebaseFixup (PrimOf p)) wY wY1
fixups Named (PrimOf p) wY1 wY
toedit :>: FL (RebaseChange (PrimOf p)) wY wX
rest) -> FL (RebaseChange (PrimOf p)) wX wX
-> Sealed (FL (RebaseChange (PrimOf p)) wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (FL (RebaseFixup (PrimOf p)) wX wY1
-> Named (PrimOf p) wY1 wY -> RebaseChange (PrimOf p) wX wY
forall (prim :: * -> * -> *) wX wY1 wY.
FL (RebaseFixup prim) wX wY1
-> Named prim wY1 wY -> RebaseChange prim wX wY
RC (RebaseFixup (PrimOf p) wX wY
f RebaseFixup (PrimOf p) wX wY
-> FL (RebaseFixup (PrimOf p)) wY wY1
-> FL (RebaseFixup (PrimOf p)) wX wY1
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RebaseFixup (PrimOf p)) wY wY1
fixups) Named (PrimOf p) wY1 wY
toedit RebaseChange (PrimOf p) wX wY
-> FL (RebaseChange (PrimOf p)) wY wX
-> FL (RebaseChange (PrimOf p)) wX wX
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (RebaseChange (PrimOf p)) wY wX
rest)
Sealed FL (RebaseChange (PrimOf p)) wY wX
NilFL -> String -> Sealed (FL (RebaseChange (PrimOf p)) wX)
forall a. HasCallStack => String -> a
error String
"rebase chain with Fixup at end"
toRebaseChanges (ToEdit Named p wX wY
te :>: FL (RebaseItem p) wY wY
ps) =
(forall wX.
FL (RebaseChange (PrimOf p)) wY wX
-> Sealed (FL (RebaseChange (PrimOf p)) wX))
-> Sealed (FL (RebaseChange (PrimOf p)) wY)
-> Sealed (FL (RebaseChange (PrimOf p)) wX)
forall (a :: * -> *) b. (forall wX. a wX -> b) -> Sealed a -> b
unseal (DiffAlgorithm
-> Named p wX wY
-> FL (RebaseChange (PrimOf p)) wY wX
-> Sealed (FL (RebaseChange (PrimOf p)) wX)
forall (p :: * -> * -> *) wX wY wZ.
RepoPatch p =>
DiffAlgorithm
-> Named p wX wY
-> FL (RebaseChange (PrimOf p)) wY wZ
-> Sealed (FL (RebaseChange (PrimOf p)) wX)
addNamedToRebase DiffAlgorithm
D.MyersDiff Named p wX wY
te) (FL (RebaseItem p) wY wY -> Sealed (FL (RebaseChange (PrimOf p)) wY)
forall (p :: * -> * -> *) wX wY.
RepoPatch p =>
FL (RebaseItem p) wX wY -> Sealed (FL (RebaseChange (PrimOf p)) wX)
toRebaseChanges FL (RebaseItem p) wY wY
ps)
instance (PrimPatchBase p, PatchListFormat p, ReadPatch p) => ReadPatch (RebaseItem p) where
readPatch' :: forall wX. Parser (Sealed (RebaseItem p wX))
readPatch' = (forall wX. Named p wX wX -> RebaseItem p wX wX)
-> Sealed (Named p wX) -> Sealed (RebaseItem p wX)
forall (a :: * -> *) (b :: * -> *).
(forall wX. a wX -> b wX) -> Sealed a -> Sealed b
mapSeal Named p wX wX -> RebaseItem p wX wX
forall wX. Named p wX wX -> RebaseItem p wX wX
forall (p :: * -> * -> *) wX wY.
Named p wX wY -> RebaseItem p wX wY
ToEdit (Sealed (Named p wX) -> Sealed (RebaseItem p wX))
-> Parser ByteString (Sealed (Named p wX))
-> Parser ByteString (Sealed (RebaseItem p wX))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Parser ByteString (Sealed (Named p wX))
forall (q :: * -> * -> *) wX.
ReadPatch q =>
ByteString -> Parser (Sealed (q wX))
readWith (String -> ByteString
BC.pack String
"rebase-toedit") Parser ByteString (Sealed (RebaseItem p wX))
-> Parser ByteString (Sealed (RebaseItem p wX))
-> Parser ByteString (Sealed (RebaseItem p wX))
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(forall wX. PrimOf p wX wX -> RebaseItem p wX wX)
-> Sealed (PrimOf p wX) -> Sealed (RebaseItem p wX)
forall (a :: * -> *) (b :: * -> *).
(forall wX. a wX -> b wX) -> Sealed a -> Sealed b
mapSeal (RebaseFixup (PrimOf p) wX wX -> RebaseItem p wX wX
forall (p :: * -> * -> *) wX wY.
RebaseFixup (PrimOf p) wX wY -> RebaseItem p wX wY
Fixup (RebaseFixup (PrimOf p) wX wX -> RebaseItem p wX wX)
-> (PrimOf p wX wX -> RebaseFixup (PrimOf p) wX wX)
-> PrimOf p wX wX
-> RebaseItem p wX wX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimOf p wX wX -> RebaseFixup (PrimOf p) wX wX
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RebaseFixup prim wX wY
PrimFixup) (Sealed (PrimOf p wX) -> Sealed (RebaseItem p wX))
-> Parser ByteString (Sealed (PrimOf p wX))
-> Parser ByteString (Sealed (RebaseItem p wX))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Parser ByteString (Sealed (PrimOf p wX))
forall (q :: * -> * -> *) wX.
ReadPatch q =>
ByteString -> Parser (Sealed (q wX))
readWith (String -> ByteString
BC.pack String
"rebase-fixup" ) Parser ByteString (Sealed (RebaseItem p wX))
-> Parser ByteString (Sealed (RebaseItem p wX))
-> Parser ByteString (Sealed (RebaseItem p wX))
forall a.
Parser ByteString a -> Parser ByteString a -> Parser ByteString a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(forall wX. RebaseName wX wX -> RebaseItem p wX wX)
-> Sealed (RebaseName wX) -> Sealed (RebaseItem p wX)
forall (a :: * -> *) (b :: * -> *).
(forall wX. a wX -> b wX) -> Sealed a -> Sealed b
mapSeal (RebaseFixup (PrimOf p) wX wX -> RebaseItem p wX wX
forall (p :: * -> * -> *) wX wY.
RebaseFixup (PrimOf p) wX wY -> RebaseItem p wX wY
Fixup (RebaseFixup (PrimOf p) wX wX -> RebaseItem p wX wX)
-> (RebaseName wX wX -> RebaseFixup (PrimOf p) wX wX)
-> RebaseName wX wX
-> RebaseItem p wX wX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RebaseName wX wX -> RebaseFixup (PrimOf p) wX wX
forall wX wY (prim :: * -> * -> *).
RebaseName wX wY -> RebaseFixup prim wX wY
NameFixup) (Sealed (RebaseName wX) -> Sealed (RebaseItem p wX))
-> Parser ByteString (Sealed (RebaseName wX))
-> Parser ByteString (Sealed (RebaseItem p wX))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Parser ByteString (Sealed (RebaseName wX))
forall (q :: * -> * -> *) wX.
ReadPatch q =>
ByteString -> Parser (Sealed (q wX))
readWith (String -> ByteString
BC.pack String
"rebase-name" )
where readWith :: forall q wX . ReadPatch q => B.ByteString -> Parser (Sealed (q wX))
readWith :: forall (q :: * -> * -> *) wX.
ReadPatch q =>
ByteString -> Parser (Sealed (q wX))
readWith ByteString
str = do ByteString -> Parser ()
lexString ByteString
str
ByteString -> Parser ()
lexString (String -> ByteString
BC.pack String
"(")
Sealed (q wX)
res <- Parser (Sealed (q wX))
forall wX. Parser (Sealed (q wX))
forall (p :: * -> * -> *) wX. ReadPatch p => Parser (Sealed (p wX))
readPatch'
ByteString -> Parser ()
lexString (String -> ByteString
BC.pack String
")")
Sealed (q wX) -> Parser (Sealed (q wX))
forall a. a -> Parser ByteString a
forall (m :: * -> *) a. Monad m => a -> m a
return Sealed (q wX)
res