--  Copyright (C) 2002-2003,2007 David Roundy
--
--  This program is free software; you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation; either version 2, or (at your option)
--  any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program; see the file COPYING.  If not, write to
--  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
--  Boston, MA 02110-1301, USA.

module Darcs.Patch.Prim.V1.Core
       ( Prim(..),
         DirPatchType(..), FilePatchType(..),
         isIdentity,
         comparePrim,
       )
       where

import Darcs.Prelude

import qualified Data.ByteString as B (ByteString)

import Darcs.Util.Path ( AnchoredPath )
import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) )
import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP )
import Darcs.Patch.Debug ( PatchDebug(..) )
import Darcs.Patch.FileHunk ( FileHunk(..), IsHunk(..) )
import Darcs.Patch.Invert ( Invert(..) )
import Darcs.Patch.Inspect ( PatchInspect(..) )
import Darcs.Patch.Permutations () -- for Invert instance of FL
import Darcs.Patch.Prim.Class ( PrimConstruct(..), PrimClassify(..) )

data Prim wX wY where
    Move :: !AnchoredPath -> !AnchoredPath -> Prim wX wY
    DP :: !AnchoredPath -> !(DirPatchType wX wY) -> Prim wX wY
    FP :: !AnchoredPath -> !(FilePatchType wX wY) -> Prim wX wY
    ChangePref :: !String -> !String -> !String -> Prim wX wY

data FilePatchType wX wY
    = RmFile
    | AddFile
    | Hunk !Int [B.ByteString] [B.ByteString]
    | TokReplace !String !String !String
    | Binary B.ByteString B.ByteString
    deriving (FilePatchType wX wY -> FilePatchType wX wY -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall wX wY. FilePatchType wX wY -> FilePatchType wX wY -> Bool
/= :: FilePatchType wX wY -> FilePatchType wX wY -> Bool
$c/= :: forall wX wY. FilePatchType wX wY -> FilePatchType wX wY -> Bool
== :: FilePatchType wX wY -> FilePatchType wX wY -> Bool
$c== :: forall wX wY. FilePatchType wX wY -> FilePatchType wX wY -> Bool
Eq,FilePatchType wX wY -> FilePatchType wX wY -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall wX wY. Eq (FilePatchType wX wY)
forall wX wY. FilePatchType wX wY -> FilePatchType wX wY -> Bool
forall wX wY.
FilePatchType wX wY -> FilePatchType wX wY -> Ordering
forall wX wY.
FilePatchType wX wY -> FilePatchType wX wY -> FilePatchType wX wY
min :: FilePatchType wX wY -> FilePatchType wX wY -> FilePatchType wX wY
$cmin :: forall wX wY.
FilePatchType wX wY -> FilePatchType wX wY -> FilePatchType wX wY
max :: FilePatchType wX wY -> FilePatchType wX wY -> FilePatchType wX wY
$cmax :: forall wX wY.
FilePatchType wX wY -> FilePatchType wX wY -> FilePatchType wX wY
>= :: FilePatchType wX wY -> FilePatchType wX wY -> Bool
$c>= :: forall wX wY. FilePatchType wX wY -> FilePatchType wX wY -> Bool
> :: FilePatchType wX wY -> FilePatchType wX wY -> Bool
$c> :: forall wX wY. FilePatchType wX wY -> FilePatchType wX wY -> Bool
<= :: FilePatchType wX wY -> FilePatchType wX wY -> Bool
$c<= :: forall wX wY. FilePatchType wX wY -> FilePatchType wX wY -> Bool
< :: FilePatchType wX wY -> FilePatchType wX wY -> Bool
$c< :: forall wX wY. FilePatchType wX wY -> FilePatchType wX wY -> Bool
compare :: FilePatchType wX wY -> FilePatchType wX wY -> Ordering
$ccompare :: forall wX wY.
FilePatchType wX wY -> FilePatchType wX wY -> Ordering
Ord)

type role FilePatchType nominal nominal

data DirPatchType wX wY = RmDir | AddDir
                           deriving (DirPatchType wX wY -> DirPatchType wX wY -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Bool
/= :: DirPatchType wX wY -> DirPatchType wX wY -> Bool
$c/= :: forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Bool
== :: DirPatchType wX wY -> DirPatchType wX wY -> Bool
$c== :: forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Bool
Eq,DirPatchType wX wY -> DirPatchType wX wY -> Bool
DirPatchType wX wY -> DirPatchType wX wY -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall wX wY. Eq (DirPatchType wX wY)
forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Bool
forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Ordering
forall wX wY.
DirPatchType wX wY -> DirPatchType wX wY -> DirPatchType wX wY
min :: DirPatchType wX wY -> DirPatchType wX wY -> DirPatchType wX wY
$cmin :: forall wX wY.
DirPatchType wX wY -> DirPatchType wX wY -> DirPatchType wX wY
max :: DirPatchType wX wY -> DirPatchType wX wY -> DirPatchType wX wY
$cmax :: forall wX wY.
DirPatchType wX wY -> DirPatchType wX wY -> DirPatchType wX wY
>= :: DirPatchType wX wY -> DirPatchType wX wY -> Bool
$c>= :: forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Bool
> :: DirPatchType wX wY -> DirPatchType wX wY -> Bool
$c> :: forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Bool
<= :: DirPatchType wX wY -> DirPatchType wX wY -> Bool
$c<= :: forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Bool
< :: DirPatchType wX wY -> DirPatchType wX wY -> Bool
$c< :: forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Bool
compare :: DirPatchType wX wY -> DirPatchType wX wY -> Ordering
$ccompare :: forall wX wY. DirPatchType wX wY -> DirPatchType wX wY -> Ordering
Ord)

type role DirPatchType nominal nominal

instance Eq2 FilePatchType where
    unsafeCompare :: forall wA wB wC wD.
FilePatchType wA wB -> FilePatchType wC wD -> Bool
unsafeCompare FilePatchType wA wB
a FilePatchType wC wD
b = FilePatchType wA wB
a forall a. Eq a => a -> a -> Bool
== forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP FilePatchType wC wD
b

instance Invert FilePatchType where
    invert :: forall wX wY. FilePatchType wX wY -> FilePatchType wY wX
invert FilePatchType wX wY
RmFile = forall wX wY. FilePatchType wX wY
AddFile
    invert FilePatchType wX wY
AddFile = forall wX wY. FilePatchType wX wY
RmFile
    invert (Hunk Int
line [ByteString]
old [ByteString]
new) = forall wX wY.
Int -> [ByteString] -> [ByteString] -> FilePatchType wX wY
Hunk Int
line [ByteString]
new [ByteString]
old
    invert (TokReplace String
t String
o String
n) = forall wX wY. String -> String -> String -> FilePatchType wX wY
TokReplace String
t String
n String
o
    invert (Binary ByteString
o ByteString
n) = forall wX wY. ByteString -> ByteString -> FilePatchType wX wY
Binary ByteString
n ByteString
o

instance Eq2 DirPatchType where
    unsafeCompare :: forall wA wB wC wD.
DirPatchType wA wB -> DirPatchType wC wD -> Bool
unsafeCompare DirPatchType wA wB
a DirPatchType wC wD
b = DirPatchType wA wB
a forall a. Eq a => a -> a -> Bool
== forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP DirPatchType wC wD
b

instance Invert DirPatchType where
    invert :: forall wX wY. DirPatchType wX wY -> DirPatchType wY wX
invert DirPatchType wX wY
RmDir = forall wX wY. DirPatchType wX wY
AddDir
    invert DirPatchType wX wY
AddDir = forall wX wY. DirPatchType wX wY
RmDir

isIdentity :: Prim wX wY -> EqCheck wX wY
isIdentity :: forall wX wY. Prim wX wY -> EqCheck wX wY
isIdentity (FP AnchoredPath
_ (Binary ByteString
old ByteString
new)) | ByteString
old forall a. Eq a => a -> a -> Bool
== ByteString
new = forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP forall wA. EqCheck wA wA
IsEq
isIdentity (FP AnchoredPath
_ (Hunk Int
_ [ByteString]
old [ByteString]
new)) | [ByteString]
old forall a. Eq a => a -> a -> Bool
== [ByteString]
new = forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP forall wA. EqCheck wA wA
IsEq
isIdentity (FP AnchoredPath
_ (TokReplace String
_ String
old String
new)) | String
old forall a. Eq a => a -> a -> Bool
== String
new = forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP forall wA. EqCheck wA wA
IsEq
isIdentity (Move AnchoredPath
old AnchoredPath
new) | AnchoredPath
old forall a. Eq a => a -> a -> Bool
== AnchoredPath
new = forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP forall wA. EqCheck wA wA
IsEq
isIdentity Prim wX wY
_ = forall wA wB. EqCheck wA wB
NotEq

instance PrimClassify Prim where
   primIsAddfile :: forall wX wY. Prim wX wY -> Bool
primIsAddfile (FP AnchoredPath
_ FilePatchType wX wY
AddFile) = Bool
True
   primIsAddfile Prim wX wY
_ = Bool
False

   primIsRmfile :: forall wX wY. Prim wX wY -> Bool
primIsRmfile (FP AnchoredPath
_ FilePatchType wX wY
RmFile) = Bool
True
   primIsRmfile Prim wX wY
_ = Bool
False

   primIsAdddir :: forall wX wY. Prim wX wY -> Bool
primIsAdddir (DP AnchoredPath
_ DirPatchType wX wY
AddDir) = Bool
True
   primIsAdddir Prim wX wY
_ = Bool
False

   primIsRmdir :: forall wX wY. Prim wX wY -> Bool
primIsRmdir (DP AnchoredPath
_ DirPatchType wX wY
RmDir) = Bool
True
   primIsRmdir Prim wX wY
_ = Bool
False

   primIsMove :: forall wX wY. Prim wX wY -> Bool
primIsMove (Move AnchoredPath
_ AnchoredPath
_) = Bool
True
   primIsMove Prim wX wY
_ = Bool
False

   primIsHunk :: forall wX wY. Prim wX wY -> Bool
primIsHunk (FP AnchoredPath
_ (Hunk Int
_ [ByteString]
_ [ByteString]
_)) = Bool
True
   primIsHunk Prim wX wY
_ = Bool
False

   primIsTokReplace :: forall wX wY. Prim wX wY -> Bool
primIsTokReplace (FP AnchoredPath
_ (TokReplace String
_ String
_ String
_)) = Bool
True
   primIsTokReplace Prim wX wY
_ = Bool
False

   primIsBinary :: forall wX wY. Prim wX wY -> Bool
primIsBinary (FP AnchoredPath
_ (Binary ByteString
_ ByteString
_)) = Bool
True
   primIsBinary Prim wX wY
_ = Bool
False

   primIsSetpref :: forall wX wY. Prim wX wY -> Bool
primIsSetpref (ChangePref String
_ String
_ String
_) = Bool
True
   primIsSetpref Prim wX wY
_ = Bool
False

   is_filepatch :: forall wX wY. Prim wX wY -> Maybe AnchoredPath
is_filepatch (FP AnchoredPath
f FilePatchType wX wY
_) = forall a. a -> Maybe a
Just AnchoredPath
f
   is_filepatch Prim wX wY
_ = forall a. Maybe a
Nothing

evalargs :: (a -> b -> c) -> a -> b -> c
evalargs :: forall a b c. (a -> b -> c) -> a -> b -> c
evalargs a -> b -> c
f a
x b
y = (a -> b -> c
f forall a b. (a -> b) -> a -> b
$! a
x) forall a b. (a -> b) -> a -> b
$! b
y

instance PrimConstruct Prim where
   addfile :: forall wX wY. AnchoredPath -> Prim wX wY
addfile AnchoredPath
f = forall wX wY. AnchoredPath -> FilePatchType wX wY -> Prim wX wY
FP AnchoredPath
f forall wX wY. FilePatchType wX wY
AddFile
   rmfile :: forall wX wY. AnchoredPath -> Prim wX wY
rmfile AnchoredPath
f = forall wX wY. AnchoredPath -> FilePatchType wX wY -> Prim wX wY
FP AnchoredPath
f forall wX wY. FilePatchType wX wY
RmFile
   adddir :: forall wX wY. AnchoredPath -> Prim wX wY
adddir AnchoredPath
d = forall wX wY. AnchoredPath -> DirPatchType wX wY -> Prim wX wY
DP AnchoredPath
d forall wX wY. DirPatchType wX wY
AddDir
   rmdir :: forall wX wY. AnchoredPath -> Prim wX wY
rmdir AnchoredPath
d = forall wX wY. AnchoredPath -> DirPatchType wX wY -> Prim wX wY
DP AnchoredPath
d forall wX wY. DirPatchType wX wY
RmDir
   move :: forall wX wY. AnchoredPath -> AnchoredPath -> Prim wX wY
move AnchoredPath
old AnchoredPath
new = forall wX wY. AnchoredPath -> AnchoredPath -> Prim wX wY
Move AnchoredPath
old AnchoredPath
new
   changepref :: forall wX wY. String -> String -> String -> Prim wX wY
changepref String
p String
f String
t = forall wX wY. String -> String -> String -> Prim wX wY
ChangePref String
p String
f String
t
   hunk :: forall wX wY.
AnchoredPath -> Int -> [ByteString] -> [ByteString] -> Prim wX wY
hunk AnchoredPath
f Int
line [ByteString]
old [ByteString]
new = forall a b c. (a -> b -> c) -> a -> b -> c
evalargs forall wX wY. AnchoredPath -> FilePatchType wX wY -> Prim wX wY
FP AnchoredPath
f (forall wX wY.
Int -> [ByteString] -> [ByteString] -> FilePatchType wX wY
Hunk Int
line [ByteString]
old [ByteString]
new)
   tokreplace :: forall wX wY.
AnchoredPath -> String -> String -> String -> Prim wX wY
tokreplace AnchoredPath
f String
tokchars String
old String
new =
       forall a b c. (a -> b -> c) -> a -> b -> c
evalargs forall wX wY. AnchoredPath -> FilePatchType wX wY -> Prim wX wY
FP AnchoredPath
f (forall wX wY. String -> String -> String -> FilePatchType wX wY
TokReplace String
tokchars String
old String
new)
   binary :: forall wX wY.
AnchoredPath -> ByteString -> ByteString -> Prim wX wY
binary AnchoredPath
f ByteString
old ByteString
new = forall wX wY. AnchoredPath -> FilePatchType wX wY -> Prim wX wY
FP AnchoredPath
f forall a b. (a -> b) -> a -> b
$ forall wX wY. ByteString -> ByteString -> FilePatchType wX wY
Binary ByteString
old ByteString
new
   primFromHunk :: forall wX wY. FileHunk wX wY -> Prim wX wY
primFromHunk (FileHunk AnchoredPath
f Int
line [ByteString]
before [ByteString]
after) = forall wX wY. AnchoredPath -> FilePatchType wX wY -> Prim wX wY
FP AnchoredPath
f (forall wX wY.
Int -> [ByteString] -> [ByteString] -> FilePatchType wX wY
Hunk Int
line [ByteString]
before [ByteString]
after)

instance IsHunk Prim where
   isHunk :: forall wX wY. Prim wX wY -> Maybe (FileHunk wX wY)
isHunk (FP AnchoredPath
f (Hunk Int
line [ByteString]
before [ByteString]
after)) = forall a. a -> Maybe a
Just (forall wX wY.
AnchoredPath
-> Int -> [ByteString] -> [ByteString] -> FileHunk wX wY
FileHunk AnchoredPath
f Int
line [ByteString]
before [ByteString]
after)
   isHunk Prim wX wY
_ = forall a. Maybe a
Nothing

instance Invert Prim where
    invert :: forall wX wY. Prim wX wY -> Prim wY wX
invert (FP AnchoredPath
f FilePatchType wX wY
p)  = forall wX wY. AnchoredPath -> FilePatchType wX wY -> Prim wX wY
FP AnchoredPath
f (forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FilePatchType wX wY
p)
    invert (DP AnchoredPath
d DirPatchType wX wY
p) = forall wX wY. AnchoredPath -> DirPatchType wX wY -> Prim wX wY
DP AnchoredPath
d (forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert DirPatchType wX wY
p)
    invert (Move AnchoredPath
f AnchoredPath
f') = forall wX wY. AnchoredPath -> AnchoredPath -> Prim wX wY
Move AnchoredPath
f' AnchoredPath
f
    invert (ChangePref String
p String
f String
t) = forall wX wY. String -> String -> String -> Prim wX wY
ChangePref String
p String
t String
f

instance PatchInspect Prim where
    -- Recurse on everything, these are potentially spoofed patches
    listTouchedFiles :: forall wX wY. Prim wX wY -> [AnchoredPath]
listTouchedFiles (Move AnchoredPath
f1 AnchoredPath
f2) = [AnchoredPath
f1, AnchoredPath
f2]
    listTouchedFiles (FP AnchoredPath
f FilePatchType wX wY
_) = [AnchoredPath
f]
    listTouchedFiles (DP AnchoredPath
d DirPatchType wX wY
_) = [AnchoredPath
d]
    listTouchedFiles (ChangePref String
_ String
_ String
_) = []

    hunkMatches :: forall wX wY. (ByteString -> Bool) -> Prim wX wY -> Bool
hunkMatches ByteString -> Bool
f (FP AnchoredPath
_ (Hunk Int
_ [ByteString]
remove [ByteString]
add)) = [ByteString] -> Bool
anyMatches [ByteString]
remove Bool -> Bool -> Bool
|| [ByteString] -> Bool
anyMatches [ByteString]
add
        where anyMatches :: [ByteString] -> Bool
anyMatches = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Bool -> Bool -> Bool
(||) forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Bool
f) Bool
False
    hunkMatches ByteString -> Bool
_ (FP AnchoredPath
_ FilePatchType wX wY
_) = Bool
False
    hunkMatches ByteString -> Bool
_ (DP AnchoredPath
_ DirPatchType wX wY
_) = Bool
False
    hunkMatches ByteString -> Bool
_ (ChangePref String
_ String
_ String
_) = Bool
False
    hunkMatches ByteString -> Bool
_ (Move AnchoredPath
_ AnchoredPath
_) = Bool
False

instance PatchDebug Prim

instance Eq2 Prim where
    unsafeCompare :: forall wA wB wC wD. Prim wA wB -> Prim wC wD -> Bool
unsafeCompare (Move AnchoredPath
a AnchoredPath
b) (Move AnchoredPath
c AnchoredPath
d) = AnchoredPath
a forall a. Eq a => a -> a -> Bool
== AnchoredPath
c Bool -> Bool -> Bool
&& AnchoredPath
b forall a. Eq a => a -> a -> Bool
== AnchoredPath
d
    unsafeCompare (DP AnchoredPath
d1 DirPatchType wA wB
p1) (DP AnchoredPath
d2 DirPatchType wC wD
p2)
        = AnchoredPath
d1 forall a. Eq a => a -> a -> Bool
== AnchoredPath
d2 Bool -> Bool -> Bool
&& DirPatchType wA wB
p1 forall (p :: * -> * -> *) wA wB wC wD.
Eq2 p =>
p wA wB -> p wC wD -> Bool
`unsafeCompare` DirPatchType wC wD
p2
    unsafeCompare (FP AnchoredPath
f1 FilePatchType wA wB
fp1) (FP AnchoredPath
f2 FilePatchType wC wD
fp2)
        = AnchoredPath
f1 forall a. Eq a => a -> a -> Bool
== AnchoredPath
f2 Bool -> Bool -> Bool
&& FilePatchType wA wB
fp1 forall (p :: * -> * -> *) wA wB wC wD.
Eq2 p =>
p wA wB -> p wC wD -> Bool
`unsafeCompare` FilePatchType wC wD
fp2
    unsafeCompare (ChangePref String
a1 String
b1 String
c1) (ChangePref String
a2 String
b2 String
c2)
        = String
c1 forall a. Eq a => a -> a -> Bool
== String
c2 Bool -> Bool -> Bool
&& String
b1 forall a. Eq a => a -> a -> Bool
== String
b2 Bool -> Bool -> Bool
&& String
a1 forall a. Eq a => a -> a -> Bool
== String
a2
    unsafeCompare Prim wA wB
_ Prim wC wD
_ = Bool
False

instance Eq (Prim wX wY) where
    == :: Prim wX wY -> Prim wX wY -> Bool
(==) = forall (p :: * -> * -> *) wA wB wC wD.
Eq2 p =>
p wA wB -> p wC wD -> Bool
unsafeCompare

-- | 'comparePrim' @p1 p2@ is used to provide an arbitrary ordering between
--   @p1@ and @p2@.  Basically, identical patches are equal and
--   @Move < DP < FP < ChangePref@.
--   Everything else is compared in dictionary order of its arguments.
comparePrim :: Prim wX wY -> Prim wW wZ -> Ordering
comparePrim :: forall wX wY wW wZ. Prim wX wY -> Prim wW wZ -> Ordering
comparePrim (Move AnchoredPath
a AnchoredPath
b) (Move AnchoredPath
c AnchoredPath
d) = forall a. Ord a => a -> a -> Ordering
compare (AnchoredPath
a, AnchoredPath
b) (AnchoredPath
c, AnchoredPath
d)
comparePrim (Move AnchoredPath
_ AnchoredPath
_) Prim wW wZ
_ = Ordering
LT
comparePrim Prim wX wY
_ (Move AnchoredPath
_ AnchoredPath
_) = Ordering
GT
comparePrim (DP AnchoredPath
d1 DirPatchType wX wY
p1) (DP AnchoredPath
d2 DirPatchType wW wZ
p2) = forall a. Ord a => a -> a -> Ordering
compare (AnchoredPath
d1, DirPatchType wX wY
p1) forall a b. (a -> b) -> a -> b
$ forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP (AnchoredPath
d2, DirPatchType wW wZ
p2)
comparePrim (DP AnchoredPath
_ DirPatchType wX wY
_) Prim wW wZ
_ = Ordering
LT
comparePrim Prim wX wY
_ (DP AnchoredPath
_ DirPatchType wW wZ
_) = Ordering
GT
comparePrim (FP AnchoredPath
f1 FilePatchType wX wY
fp1) (FP AnchoredPath
f2 FilePatchType wW wZ
fp2) = forall a. Ord a => a -> a -> Ordering
compare (AnchoredPath
f1, FilePatchType wX wY
fp1) forall a b. (a -> b) -> a -> b
$ forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP (AnchoredPath
f2, FilePatchType wW wZ
fp2)
comparePrim (FP AnchoredPath
_ FilePatchType wX wY
_) Prim wW wZ
_ = Ordering
LT
comparePrim Prim wX wY
_ (FP AnchoredPath
_ FilePatchType wW wZ
_) = Ordering
GT
comparePrim (ChangePref String
a1 String
b1 String
c1) (ChangePref String
a2 String
b2 String
c2)
 = forall a. Ord a => a -> a -> Ordering
compare (String
c1, String
b1, String
a1) (String
c2, String
b2, String
a2)