module Darcs.Patch.Prim.Class
( PrimConstruct(..), PrimCanonize(..)
, PrimClassify(..), PrimDetails(..)
, PrimSift(..)
, PrimShow(..), PrimRead(..)
, PrimApply(..)
, PrimPatch
, PrimMangleUnravelled(..)
, Mangled
, Unravelled
, primCleanMerge
)
where
import Darcs.Prelude
import Darcs.Patch.ApplyMonad ( ApplyMonad )
import Darcs.Patch.FileHunk ( FileHunk, IsHunk )
import Darcs.Patch.Format ( FileNameFormat, PatchListFormat )
import Darcs.Patch.Inspect ( PatchInspect )
import Darcs.Patch.Apply ( Apply(..) )
import Darcs.Patch.Commute ( Commute(..) )
import Darcs.Patch.CommuteFn ( PartialMergeFn )
import Darcs.Patch.Invert ( Invert(..) )
import Darcs.Patch.Merge ( CleanMerge(..) )
import Darcs.Patch.Read ( ReadPatch )
import Darcs.Patch.Repair ( RepairToFL )
import Darcs.Patch.Show ( ShowPatch, ShowContextPatch )
import Darcs.Patch.SummaryData ( SummDetail )
import Darcs.Patch.Witnesses.Eq ( Eq2(..) )
import Darcs.Patch.Witnesses.Ordered ( FL, (:>)(..), (:\/:)(..), (:/\:)(..) )
import Darcs.Patch.Witnesses.Show ( Show2 )
import Darcs.Patch.Witnesses.Sealed ( Sealed )
import Darcs.Util.Parser ( Parser )
import Darcs.Util.Path ( AnchoredPath )
import Darcs.Util.Printer ( Doc )
import qualified Darcs.Util.Diff as D ( DiffAlgorithm )
import qualified Data.ByteString as B ( ByteString )
type PrimPatch prim =
( Apply prim
, CleanMerge prim
, Commute prim
, Invert prim
, Eq2 prim
, IsHunk prim
, PatchInspect prim
, RepairToFL prim
, Show2 prim
, PrimConstruct prim
, PrimCanonize prim
, PrimClassify prim
, PrimDetails prim
, PrimApply prim
, PrimSift prim
, PrimMangleUnravelled prim
, ReadPatch prim
, ShowPatch prim
, ShowContextPatch prim
, PatchListFormat prim
)
class PrimClassify prim where
primIsAddfile :: prim wX wY -> Bool
primIsRmfile :: prim wX wY -> Bool
primIsAdddir :: prim wX wY -> Bool
primIsRmdir :: prim wX wY -> Bool
primIsMove :: prim wX wY -> Bool
primIsHunk :: prim wX wY -> Bool
primIsTokReplace :: prim wX wY -> Bool
primIsBinary :: prim wX wY -> Bool
primIsSetpref :: prim wX wY -> Bool
is_filepatch :: prim wX wY -> Maybe AnchoredPath
class PrimConstruct prim where
addfile :: AnchoredPath -> prim wX wY
rmfile :: AnchoredPath -> prim wX wY
adddir :: AnchoredPath -> prim wX wY
rmdir :: AnchoredPath -> prim wX wY
move :: AnchoredPath -> AnchoredPath -> prim wX wY
changepref :: String -> String -> String -> prim wX wY
hunk :: AnchoredPath -> Int -> [B.ByteString] -> [B.ByteString] -> prim wX wY
tokreplace :: AnchoredPath -> String -> String -> String -> prim wX wY
binary :: AnchoredPath -> B.ByteString -> B.ByteString -> prim wX wY
primFromHunk :: FileHunk wX wY -> prim wX wY
class PrimCanonize prim where
tryToShrink :: FL prim wX wY -> FL prim wX wY
sortCoalesceFL :: FL prim wX wY -> FL prim wX wY
canonize :: D.DiffAlgorithm -> prim wX wY -> FL prim wX wY
canonizeFL :: D.DiffAlgorithm -> FL prim wX wY -> FL prim wX wY
coalesce :: (prim :> prim) wX wY -> Maybe (FL prim wX wY)
primCoalesce :: prim wX wY -> prim wY wZ -> Maybe (prim wX wZ)
primDecoalesce :: prim wX wZ -> prim wX wY -> Maybe (prim wY wZ)
class PrimSift prim where
siftForPending :: FL prim wX wY -> Sealed (FL prim wX)
class PrimDetails prim where
summarizePrim :: prim wX wY -> [SummDetail]
class PrimShow prim where
showPrim :: FileNameFormat -> prim wA wB -> Doc
showPrimCtx :: ApplyMonad (ApplyState prim) m => FileNameFormat -> prim wA wB -> m Doc
class PrimRead prim where
readPrim :: FileNameFormat -> Parser (Sealed (prim wX))
class PrimApply prim where
applyPrimFL :: ApplyMonad (ApplyState prim) m => FL prim wX wY -> m ()
type Unravelled prim wX = [Sealed (FL prim wX)]
type Mangled prim wX = Sealed (FL prim wX)
class PrimMangleUnravelled prim where
mangleUnravelled :: Unravelled prim wX -> Maybe (Mangled prim wX)
primCleanMerge :: (Commute prim, Invert prim) => PartialMergeFn prim prim
primCleanMerge (p :\/: q) = do
q' :> ip' <- commute (invert p :> q)
return $ q' :/\: invert ip'