{-# LANGUAGE OverloadedStrings, StandaloneDeriving #-}
module Darcs.Patch.Prim.FileUUID.Core
( Prim(..)
, Hunk(..)
, HunkMove(..)
, Object(..)
, UUID(..)
, Location(..)
, Name
, FileContent
) where
import Prelude ()
import Darcs.Prelude
import Darcs.Patch.Witnesses.Eq ( Eq2(..) )
import Darcs.Patch.Witnesses.Show ( Show1(..), Show2(..), ShowDict(ShowDictClass) )
import Darcs.Patch.Witnesses.Unsafe
import Darcs.Patch.FileHunk( IsHunk(..) )
import Darcs.Patch.Invert ( Invert(..) )
import Darcs.Patch.Inspect ( PatchInspect(..) )
import Darcs.Patch.Prim.Class ( PrimConstruct(..), PrimClassify(..) )
import Darcs.Patch.Prim.FileUUID.ObjectMap
data Hunk wX wY = H !Int !FileContent !FileContent
deriving (Hunk wX wY -> Hunk wX wY -> Bool
(Hunk wX wY -> Hunk wX wY -> Bool)
-> (Hunk wX wY -> Hunk wX wY -> Bool) -> Eq (Hunk wX wY)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall wX wY. Hunk wX wY -> Hunk wX wY -> Bool
/= :: Hunk wX wY -> Hunk wX wY -> Bool
$c/= :: forall wX wY. Hunk wX wY -> Hunk wX wY -> Bool
== :: Hunk wX wY -> Hunk wX wY -> Bool
$c== :: forall wX wY. Hunk wX wY -> Hunk wX wY -> Bool
Eq, Int -> Hunk wX wY -> ShowS
[Hunk wX wY] -> ShowS
Hunk wX wY -> String
(Int -> Hunk wX wY -> ShowS)
-> (Hunk wX wY -> String)
-> ([Hunk wX wY] -> ShowS)
-> Show (Hunk wX wY)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall wX wY. Int -> Hunk wX wY -> ShowS
forall wX wY. [Hunk wX wY] -> ShowS
forall wX wY. Hunk wX wY -> String
showList :: [Hunk wX wY] -> ShowS
$cshowList :: forall wX wY. [Hunk wX wY] -> ShowS
show :: Hunk wX wY -> String
$cshow :: forall wX wY. Hunk wX wY -> String
showsPrec :: Int -> Hunk wX wY -> ShowS
$cshowsPrec :: forall wX wY. Int -> Hunk wX wY -> ShowS
Show)
instance Show1 (Hunk wX) where
showDict1 :: ShowDict (Hunk wX wX)
showDict1 = ShowDict (Hunk wX wX)
forall a. Show a => ShowDict a
ShowDictClass
instance Show2 Hunk where
showDict2 :: ShowDict (Hunk wX wY)
showDict2 = ShowDict (Hunk wX wY)
forall a. Show a => ShowDict a
ShowDictClass
invertHunk :: Hunk wX wY -> Hunk wY wX
invertHunk :: Hunk wX wY -> Hunk wY wX
invertHunk (H off :: Int
off old :: FileContent
old new :: FileContent
new) = Int -> FileContent -> FileContent -> Hunk wY wX
forall wX wY. Int -> FileContent -> FileContent -> Hunk wX wY
H Int
off FileContent
new FileContent
old
instance Eq2 Hunk where
unsafeCompare :: Hunk wA wB -> Hunk wC wD -> Bool
unsafeCompare p :: Hunk wA wB
p q :: Hunk wC wD
q = Hunk wA wB -> Hunk wC wD
forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP Hunk wA wB
p Hunk wC wD -> Hunk wC wD -> Bool
forall a. Eq a => a -> a -> Bool
== Hunk wC wD
q
data HunkMove wX wY = HM !UUID !Int !UUID !Int !FileContent
deriving (HunkMove wX wY -> HunkMove wX wY -> Bool
(HunkMove wX wY -> HunkMove wX wY -> Bool)
-> (HunkMove wX wY -> HunkMove wX wY -> Bool)
-> Eq (HunkMove wX wY)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall wX wY. HunkMove wX wY -> HunkMove wX wY -> Bool
/= :: HunkMove wX wY -> HunkMove wX wY -> Bool
$c/= :: forall wX wY. HunkMove wX wY -> HunkMove wX wY -> Bool
== :: HunkMove wX wY -> HunkMove wX wY -> Bool
$c== :: forall wX wY. HunkMove wX wY -> HunkMove wX wY -> Bool
Eq, Int -> HunkMove wX wY -> ShowS
[HunkMove wX wY] -> ShowS
HunkMove wX wY -> String
(Int -> HunkMove wX wY -> ShowS)
-> (HunkMove wX wY -> String)
-> ([HunkMove wX wY] -> ShowS)
-> Show (HunkMove wX wY)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall wX wY. Int -> HunkMove wX wY -> ShowS
forall wX wY. [HunkMove wX wY] -> ShowS
forall wX wY. HunkMove wX wY -> String
showList :: [HunkMove wX wY] -> ShowS
$cshowList :: forall wX wY. [HunkMove wX wY] -> ShowS
show :: HunkMove wX wY -> String
$cshow :: forall wX wY. HunkMove wX wY -> String
showsPrec :: Int -> HunkMove wX wY -> ShowS
$cshowsPrec :: forall wX wY. Int -> HunkMove wX wY -> ShowS
Show)
invertHunkMove :: HunkMove wX wY -> HunkMove wY wX
invertHunkMove :: HunkMove wX wY -> HunkMove wY wX
invertHunkMove (HM sid :: UUID
sid soff :: Int
soff tid :: UUID
tid toff :: Int
toff content :: FileContent
content) = UUID -> Int -> UUID -> Int -> FileContent -> HunkMove wY wX
forall wX wY.
UUID -> Int -> UUID -> Int -> FileContent -> HunkMove wX wY
HM UUID
tid Int
toff UUID
sid Int
soff FileContent
content
instance Eq2 HunkMove where
unsafeCompare :: HunkMove wA wB -> HunkMove wC wD -> Bool
unsafeCompare (HM sid1 :: UUID
sid1 soff1 :: Int
soff1 tid1 :: UUID
tid1 toff1 :: Int
toff1 c1 :: FileContent
c1) (HM sid2 :: UUID
sid2 soff2 :: Int
soff2 tid2 :: UUID
tid2 toff2 :: Int
toff2 c2 :: FileContent
c2) =
UUID
sid1 UUID -> UUID -> Bool
forall a. Eq a => a -> a -> Bool
== UUID
sid2 Bool -> Bool -> Bool
&& Int
soff1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
soff2 Bool -> Bool -> Bool
&& UUID
tid1 UUID -> UUID -> Bool
forall a. Eq a => a -> a -> Bool
== UUID
tid2 Bool -> Bool -> Bool
&& Int
toff1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
toff2 Bool -> Bool -> Bool
&& FileContent
c1 FileContent -> FileContent -> Bool
forall a. Eq a => a -> a -> Bool
== FileContent
c2
data Prim wX wY where
Hunk :: !UUID -> !(Hunk wX wY) -> Prim wX wY
HunkMove :: !(HunkMove wX wY) -> Prim wX wY
Manifest :: !UUID -> !Location -> Prim wX wY
Demanifest :: !UUID -> !Location -> Prim wX wY
Identity :: Prim wX wX
deriving instance Eq (Prim wX wY)
deriving instance Show (Prim wX wY)
instance Show1 (Prim wX) where
showDict1 :: ShowDict (Prim wX wX)
showDict1 = ShowDict (Prim wX wX)
forall a. Show a => ShowDict a
ShowDictClass
instance Show2 Prim where
showDict2 :: ShowDict (Prim wX wY)
showDict2 = ShowDict (Prim wX wY)
forall a. Show a => ShowDict a
ShowDictClass
instance PrimClassify Prim where
primIsAddfile :: Prim wX wY -> Bool
primIsAddfile _ = Bool
False
primIsRmfile :: Prim wX wY -> Bool
primIsRmfile _ = Bool
False
primIsAdddir :: Prim wX wY -> Bool
primIsAdddir _ = Bool
False
primIsRmdir :: Prim wX wY -> Bool
primIsRmdir _ = Bool
False
primIsHunk :: Prim wX wY -> Bool
primIsHunk _ = Bool
False
primIsMove :: Prim wX wY -> Bool
primIsMove _ = Bool
False
primIsBinary :: Prim wX wY -> Bool
primIsBinary _ = Bool
False
primIsTokReplace :: Prim wX wY -> Bool
primIsTokReplace _ = Bool
False
primIsSetpref :: Prim wX wY -> Bool
primIsSetpref _ = Bool
False
is_filepatch :: Prim wX wY -> Maybe FileName
is_filepatch _ = Maybe FileName
forall a. Maybe a
Nothing
instance PrimConstruct Prim where
addfile :: String -> Prim wX wY
addfile _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct addfile"
rmfile :: String -> Prim wX wY
rmfile _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct rmfile"
adddir :: String -> Prim wX wY
adddir _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct adddir"
rmdir :: String -> Prim wX wY
rmdir _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct rmdir"
move :: String -> String -> Prim wX wY
move _ _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct move"
changepref :: String -> String -> String -> Prim wX wY
changepref _ _ _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct changepref"
hunk :: String -> Int -> [FileContent] -> [FileContent] -> Prim wX wY
hunk _ _ _ _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct hunk"
tokreplace :: String -> String -> String -> String -> Prim wX wY
tokreplace _ _ _ _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct tokreplace"
binary :: String -> FileContent -> FileContent -> Prim wX wY
binary _ _ _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct binary"
primFromHunk :: FileHunk wX wY -> Prim wX wY
primFromHunk _ = String -> Prim wX wY
forall a. HasCallStack => String -> a
error "PrimConstruct primFromHunk"
anIdentity :: Prim wX wX
anIdentity = Prim wX wX
forall wX. Prim wX wX
Identity
instance IsHunk Prim where
isHunk :: Prim wX wY -> Maybe (FileHunk wX wY)
isHunk _ = Maybe (FileHunk wX wY)
forall a. Maybe a
Nothing
instance Invert Prim where
invert :: Prim wX wY -> Prim wY wX
invert (Hunk x :: UUID
x h :: Hunk wX wY
h) = UUID -> Hunk wY wX -> Prim wY wX
forall wX wY. UUID -> Hunk wX wY -> Prim wX wY
Hunk UUID
x (Hunk wY wX -> Prim wY wX) -> Hunk wY wX -> Prim wY wX
forall a b. (a -> b) -> a -> b
$ Hunk wX wY -> Hunk wY wX
forall wX wY. Hunk wX wY -> Hunk wY wX
invertHunk Hunk wX wY
h
invert (HunkMove hm :: HunkMove wX wY
hm) = HunkMove wY wX -> Prim wY wX
forall wX wY. HunkMove wX wY -> Prim wX wY
HunkMove (HunkMove wY wX -> Prim wY wX) -> HunkMove wY wX -> Prim wY wX
forall a b. (a -> b) -> a -> b
$ HunkMove wX wY -> HunkMove wY wX
forall wX wY. HunkMove wX wY -> HunkMove wY wX
invertHunkMove HunkMove wX wY
hm
invert (Manifest x :: UUID
x y :: Location
y) = UUID -> Location -> Prim wY wX
forall wX wY. UUID -> Location -> Prim wX wY
Demanifest UUID
x Location
y
invert (Demanifest x :: UUID
x y :: Location
y) = UUID -> Location -> Prim wY wX
forall wX wY. UUID -> Location -> Prim wX wY
Manifest UUID
x Location
y
invert Identity = Prim wY wX
forall wX. Prim wX wX
Identity
instance PatchInspect Prim where
listTouchedFiles :: Prim wX wY -> [String]
listTouchedFiles _ = []
hunkMatches :: (FileContent -> Bool) -> Prim wX wY -> Bool
hunkMatches _ _ = Bool
False
instance Eq2 Prim where
unsafeCompare :: Prim wA wB -> Prim wC wD -> Bool
unsafeCompare (Hunk a :: UUID
a b :: Hunk wA wB
b) (Hunk c :: UUID
c d :: Hunk wC wD
d) = UUID
a UUID -> UUID -> Bool
forall a. Eq a => a -> a -> Bool
== UUID
c Bool -> Bool -> Bool
&& Hunk wA wB
b Hunk wA wB -> Hunk wC wD -> Bool
forall (p :: * -> * -> *) wA wB wC wD.
Eq2 p =>
p wA wB -> p wC wD -> Bool
`unsafeCompare` Hunk wC wD
d
unsafeCompare (Manifest a :: UUID
a b :: Location
b) (Manifest c :: UUID
c d :: Location
d) = UUID
a UUID -> UUID -> Bool
forall a. Eq a => a -> a -> Bool
== UUID
c Bool -> Bool -> Bool
&& Location
b Location -> Location -> Bool
forall a. Eq a => a -> a -> Bool
== Location
d
unsafeCompare (Demanifest a :: UUID
a b :: Location
b) (Demanifest c :: UUID
c d :: Location
d) = UUID
a UUID -> UUID -> Bool
forall a. Eq a => a -> a -> Bool
== UUID
c Bool -> Bool -> Bool
&& Location
b Location -> Location -> Bool
forall a. Eq a => a -> a -> Bool
== Location
d
unsafeCompare Identity Identity = Bool
True
unsafeCompare _ _ = Bool
False