-- Copyright (C) 2006 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.PatchInfoAnd
    ( Hopefully
    , PatchInfoAnd
    , PatchInfoAndG
    , piap
    , n2pia
    , patchInfoAndPatch
    , fmapPIAP
    , fmapFLPIAP
    , hopefully
    , info
    , hopefullyM
    , createHashed
    , extractHash
    , actually
    , unavailable
    , patchDesc
    ) where

import Darcs.Prelude

import Control.Exception ( Exception, throw )
import System.IO.Unsafe ( unsafeInterleaveIO )
import Data.Typeable ( Typeable )

import Darcs.Patch.Apply ( Apply(..) )
import Darcs.Patch.Commute ( Commute(..) )
import Darcs.Patch.Conflict ( Conflict(..) )
import Darcs.Patch.Debug ( PatchDebug(..) )
import Darcs.Patch.Effect ( Effect(..) )
import Darcs.Patch.FileHunk ( IsHunk(..) )
import Darcs.Patch.Format ( PatchListFormat )
import Darcs.Patch.FromPrim ( PrimPatchBase(..) )
import Darcs.Patch.Ident ( Ident(..), PatchId )
import Darcs.Patch.Info ( PatchInfo, displayPatchInfo, justName, showPatchInfo )
import Darcs.Patch.Inspect ( PatchInspect(..) )
import Darcs.Patch.Merge ( CleanMerge(..), Merge(..) )
import Darcs.Patch.Named ( Named, fmapFL_Named )
import Darcs.Patch.Read ( ReadPatch(..) )
import Darcs.Patch.Repair ( Repair(..), RepairToFL )
import Darcs.Patch.Show ( ShowPatch(..) )
import Darcs.Patch.Show ( ShowContextPatch(..), ShowPatchBasic(..) )
import Darcs.Patch.Summary ( Summary )
import Darcs.Patch.Witnesses.Eq ( Eq2(..) )
import Darcs.Patch.Witnesses.Ordered
    ( (:/\:)(..)
    , (:>)(..)
    , (:\/:)(..)
    , FL
    , mapFL
    , mapRL_RL
    )
import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), mapSeal, seal )
import Darcs.Patch.Witnesses.Show ( Show1, Show2 )
import Darcs.Util.Exception ( prettyException )
import Darcs.Util.Printer ( Doc, renderString, text, vcat, ($$) )
import Darcs.Util.SignalHandler ( catchNonSignal )
import Darcs.Util.ValidHash ( PatchHash )

-- | @'Hopefully' p C@ @(x y)@ is @'Either' String (p C@ @(x y))@ in a
-- form adapted to darcs patches. The @C@ @(x y)@ represents the type
-- witness for the patch that should be there. The @Hopefully@ type
-- just tells whether we expect the patch to be hashed or not, and
-- 'SimpleHopefully' does the real work of emulating
-- 'Either'. @Hopefully sh@ represents an expected unhashed patch, and
-- @Hashed hash sh@ represents an expected hashed patch with its hash.
data Hopefully a wX wY
    = Hopefully (SimpleHopefully a wX wY)
    | Hashed PatchHash (SimpleHopefully a wX wY)
    deriving Int -> Hopefully a wX wY -> ShowS
[Hopefully a wX wY] -> ShowS
Hopefully a wX wY -> String
(Int -> Hopefully a wX wY -> ShowS)
-> (Hopefully a wX wY -> String)
-> ([Hopefully a wX wY] -> ShowS)
-> Show (Hopefully a wX wY)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Int -> Hopefully a wX wY -> ShowS
forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
[Hopefully a wX wY] -> ShowS
forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Hopefully a wX wY -> String
$cshowsPrec :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Int -> Hopefully a wX wY -> ShowS
showsPrec :: Int -> Hopefully a wX wY -> ShowS
$cshow :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Hopefully a wX wY -> String
show :: Hopefully a wX wY -> String
$cshowList :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
[Hopefully a wX wY] -> ShowS
showList :: [Hopefully a wX wY] -> ShowS
Show

-- | @SimpleHopefully@ is a variant of @Either String@ adapted for
-- type witnesses. @Actually@ is the equivalent of @Right@, while
-- @Unavailable@ is @Left@.
data SimpleHopefully a wX wY = Actually (a wX wY) | Unavailable String
    deriving Int -> SimpleHopefully a wX wY -> ShowS
[SimpleHopefully a wX wY] -> ShowS
SimpleHopefully a wX wY -> String
(Int -> SimpleHopefully a wX wY -> ShowS)
-> (SimpleHopefully a wX wY -> String)
-> ([SimpleHopefully a wX wY] -> ShowS)
-> Show (SimpleHopefully a wX wY)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Int -> SimpleHopefully a wX wY -> ShowS
forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
[SimpleHopefully a wX wY] -> ShowS
forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
SimpleHopefully a wX wY -> String
$cshowsPrec :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Int -> SimpleHopefully a wX wY -> ShowS
showsPrec :: Int -> SimpleHopefully a wX wY -> ShowS
$cshow :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
SimpleHopefully a wX wY -> String
show :: SimpleHopefully a wX wY -> String
$cshowList :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
[SimpleHopefully a wX wY] -> ShowS
showList :: [SimpleHopefully a wX wY] -> ShowS
Show

type PatchInfoAnd p = PatchInfoAndG (Named p)

-- | @'PatchInfoAnd' p wA wB@ represents a hope we have to get a
-- patch through its info. We're not sure we have the patch, but we
-- know its info.
data PatchInfoAndG p wA wB =
  PIAP !PatchInfo
       (Hopefully p wA wB)
  deriving (Int -> PatchInfoAndG p wA wB -> ShowS
[PatchInfoAndG p wA wB] -> ShowS
PatchInfoAndG p wA wB -> String
(Int -> PatchInfoAndG p wA wB -> ShowS)
-> (PatchInfoAndG p wA wB -> String)
-> ([PatchInfoAndG p wA wB] -> ShowS)
-> Show (PatchInfoAndG p wA wB)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
Int -> PatchInfoAndG p wA wB -> ShowS
forall (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
[PatchInfoAndG p wA wB] -> ShowS
forall (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
PatchInfoAndG p wA wB -> String
$cshowsPrec :: forall (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
Int -> PatchInfoAndG p wA wB -> ShowS
showsPrec :: Int -> PatchInfoAndG p wA wB -> ShowS
$cshow :: forall (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
PatchInfoAndG p wA wB -> String
show :: PatchInfoAndG p wA wB -> String
$cshowList :: forall (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
[PatchInfoAndG p wA wB] -> ShowS
showList :: [PatchInfoAndG p wA wB] -> ShowS
Show)

fmapH :: (a wX wY -> b wW wZ) -> Hopefully a wX wY -> Hopefully b wW wZ
fmapH :: forall (a :: * -> * -> *) wX wY (b :: * -> * -> *) wW wZ.
(a wX wY -> b wW wZ) -> Hopefully a wX wY -> Hopefully b wW wZ
fmapH a wX wY -> b wW wZ
f (Hopefully SimpleHopefully a wX wY
sh) = SimpleHopefully b wW wZ -> Hopefully b wW wZ
forall (a :: * -> * -> *) wX wY.
SimpleHopefully a wX wY -> Hopefully a wX wY
Hopefully (SimpleHopefully a wX wY -> SimpleHopefully b wW wZ
ff SimpleHopefully a wX wY
sh)
    where ff :: SimpleHopefully a wX wY -> SimpleHopefully b wW wZ
ff (Actually a wX wY
a) = b wW wZ -> SimpleHopefully b wW wZ
forall (a :: * -> * -> *) wX wY. a wX wY -> SimpleHopefully a wX wY
Actually (a wX wY -> b wW wZ
f a wX wY
a)
          ff (Unavailable String
e) = String -> SimpleHopefully b wW wZ
forall (a :: * -> * -> *) wX wY. String -> SimpleHopefully a wX wY
Unavailable String
e
fmapH a wX wY -> b wW wZ
f (Hashed PatchHash
_ SimpleHopefully a wX wY
sh) = SimpleHopefully b wW wZ -> Hopefully b wW wZ
forall (a :: * -> * -> *) wX wY.
SimpleHopefully a wX wY -> Hopefully a wX wY
Hopefully (SimpleHopefully a wX wY -> SimpleHopefully b wW wZ
ff SimpleHopefully a wX wY
sh)
    where ff :: SimpleHopefully a wX wY -> SimpleHopefully b wW wZ
ff (Actually a wX wY
a) = b wW wZ -> SimpleHopefully b wW wZ
forall (a :: * -> * -> *) wX wY. a wX wY -> SimpleHopefully a wX wY
Actually (a wX wY -> b wW wZ
f a wX wY
a)
          ff (Unavailable String
e) = String -> SimpleHopefully b wW wZ
forall (a :: * -> * -> *) wX wY. String -> SimpleHopefully a wX wY
Unavailable String
e

info :: PatchInfoAndG p wA wB -> PatchInfo
info :: forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> PatchInfo
info (PIAP PatchInfo
i Hopefully p wA wB
_) = PatchInfo
i

patchDesc :: forall p wX wY . PatchInfoAnd p wX wY -> String
patchDesc :: forall (p :: * -> * -> *) wX wY. PatchInfoAnd p wX wY -> String
patchDesc PatchInfoAnd p wX wY
p = PatchInfo -> String
justName (PatchInfo -> String) -> PatchInfo -> String
forall a b. (a -> b) -> a -> b
$ PatchInfoAnd p wX wY -> PatchInfo
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> PatchInfo
info PatchInfoAnd p wX wY
p

-- | @'piap' i p@ creates a PatchInfoAnd containing p with info i.
piap :: PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
piap :: forall (p :: * -> * -> *) wA wB.
PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
piap PatchInfo
i p wA wB
p = PatchInfo -> Hopefully p wA wB -> PatchInfoAndG p wA wB
forall (p :: * -> * -> *) wA wB.
PatchInfo -> Hopefully p wA wB -> PatchInfoAndG p wA wB
PIAP PatchInfo
i (SimpleHopefully p wA wB -> Hopefully p wA wB
forall (a :: * -> * -> *) wX wY.
SimpleHopefully a wX wY -> Hopefully a wX wY
Hopefully (SimpleHopefully p wA wB -> Hopefully p wA wB)
-> SimpleHopefully p wA wB -> Hopefully p wA wB
forall a b. (a -> b) -> a -> b
$ p wA wB -> SimpleHopefully p wA wB
forall (a :: * -> * -> *) wX wY. a wX wY -> SimpleHopefully a wX wY
Actually p wA wB
p)

-- | @n2pia@ creates a PatchInfoAnd representing a @Named@ patch.
n2pia :: (Ident p, PatchId p ~ PatchInfo) => p wX wY -> PatchInfoAndG p wX wY
n2pia :: forall (p :: * -> * -> *) wX wY.
(Ident p, PatchId p ~ PatchInfo) =>
p wX wY -> PatchInfoAndG p wX wY
n2pia p wX wY
x = p wX wY -> PatchId p
forall wX wY. p wX wY -> PatchId p
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident p wX wY
x PatchInfo -> p wX wY -> PatchInfoAndG p wX wY
forall (p :: * -> * -> *) wA wB.
PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
`piap` p wX wY
x

patchInfoAndPatch :: PatchInfo -> Hopefully p wA wB -> PatchInfoAndG p wA wB
patchInfoAndPatch :: forall (p :: * -> * -> *) wA wB.
PatchInfo -> Hopefully p wA wB -> PatchInfoAndG p wA wB
patchInfoAndPatch =  PatchInfo -> Hopefully p wA wB -> PatchInfoAndG p wA wB
forall (p :: * -> * -> *) wA wB.
PatchInfo -> Hopefully p wA wB -> PatchInfoAndG p wA wB
PIAP

fmapFLPIAP :: (FL p wX wY -> FL q wX wY)
           -> PatchInfoAnd p wX wY -> PatchInfoAnd q wX wY
fmapFLPIAP :: forall (p :: * -> * -> *) wX wY (q :: * -> * -> *).
(FL p wX wY -> FL q wX wY)
-> PatchInfoAnd p wX wY -> PatchInfoAnd q wX wY
fmapFLPIAP FL p wX wY -> FL q wX wY
f (PIAP PatchInfo
i Hopefully (Named p) wX wY
hp) = PatchInfo
-> Hopefully (Named q) wX wY -> PatchInfoAndG (Named q) wX wY
forall (p :: * -> * -> *) wA wB.
PatchInfo -> Hopefully p wA wB -> PatchInfoAndG p wA wB
PIAP PatchInfo
i ((Named p wX wY -> Named q wX wY)
-> Hopefully (Named p) wX wY -> Hopefully (Named q) wX wY
forall (a :: * -> * -> *) wX wY (b :: * -> * -> *) wW wZ.
(a wX wY -> b wW wZ) -> Hopefully a wX wY -> Hopefully b wW wZ
fmapH ((FL p wX wY -> FL q wX wY) -> Named p wX wY -> Named q wX wY
forall (p :: * -> * -> *) wA wB (q :: * -> * -> *) wC wD.
(FL p wA wB -> FL q wC wD) -> Named p wA wB -> Named q wC wD
fmapFL_Named FL p wX wY -> FL q wX wY
f) Hopefully (Named p) wX wY
hp)

fmapPIAP :: (p wX wY -> q wX wY)
           -> PatchInfoAndG p wX wY -> PatchInfoAndG q wX wY
fmapPIAP :: forall (p :: * -> * -> *) wX wY (q :: * -> * -> *).
(p wX wY -> q wX wY)
-> PatchInfoAndG p wX wY -> PatchInfoAndG q wX wY
fmapPIAP p wX wY -> q wX wY
f (PIAP PatchInfo
i Hopefully p wX wY
hp) = PatchInfo -> Hopefully q wX wY -> PatchInfoAndG q wX wY
forall (p :: * -> * -> *) wA wB.
PatchInfo -> Hopefully p wA wB -> PatchInfoAndG p wA wB
PIAP PatchInfo
i ((p wX wY -> q wX wY) -> Hopefully p wX wY -> Hopefully q wX wY
forall (a :: * -> * -> *) wX wY (b :: * -> * -> *) wW wZ.
(a wX wY -> b wW wZ) -> Hopefully a wX wY -> Hopefully b wW wZ
fmapH p wX wY -> q wX wY
f Hopefully p wX wY
hp)

-- | @'hopefully' hp@ tries to get a patch from a 'PatchInfoAnd'
-- value. If it fails, it outputs an error \"failed to read patch:
-- \<description of the patch>\". We get the description of the patch
-- from the info part of 'hp'
hopefully :: PatchInfoAndG p wA wB -> p wA wB
hopefully :: forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully = (Doc -> Doc) -> PatchInfoAndG p wA wB -> p wA wB
forall (p :: * -> * -> *) wA wB.
(Doc -> Doc) -> PatchInfoAndG p wA wB -> p wA wB
conscientiously ((Doc -> Doc) -> PatchInfoAndG p wA wB -> p wA wB)
-> (Doc -> Doc) -> PatchInfoAndG p wA wB -> p wA wB
forall a b. (a -> b) -> a -> b
$ \Doc
e -> String -> Doc
text String
"failed to read patch:" Doc -> Doc -> Doc
$$ Doc
e

-- | Using a special exception type here means that is is treated as
-- regular failure, and not as a bug in Darcs.
data PatchNotAvailable = PatchNotAvailable Doc
  deriving Typeable

instance Exception PatchNotAvailable

instance Show PatchNotAvailable where
  show :: PatchNotAvailable -> String
show (PatchNotAvailable Doc
e) = Doc -> String
renderString Doc
e

-- | @'conscientiously' er hp@ tries to extract a patch from a 'PatchInfoAnd'.
-- If it fails, it applies the error handling function @er@ to a description
-- of the patch info component of @hp@.
-- Note: this function must be lazy in its second argument, which is why we
-- use a lazy pattern match.
conscientiously :: (Doc -> Doc)
                -> PatchInfoAndG p wA wB -> p wA wB
conscientiously :: forall (p :: * -> * -> *) wA wB.
(Doc -> Doc) -> PatchInfoAndG p wA wB -> p wA wB
conscientiously Doc -> Doc
er ~(PIAP PatchInfo
pinf Hopefully p wA wB
hp) =
    case Hopefully p wA wB -> Either String (p wA wB)
forall (a :: * -> * -> *) wX wY.
Hopefully a wX wY -> Either String (a wX wY)
hopefully2either Hopefully p wA wB
hp of
      Right p wA wB
p -> p wA wB
p
      Left String
e -> PatchNotAvailable -> p wA wB
forall a e. Exception e => e -> a
throw (PatchNotAvailable -> p wA wB) -> PatchNotAvailable -> p wA wB
forall a b. (a -> b) -> a -> b
$ Doc -> PatchNotAvailable
PatchNotAvailable (Doc -> PatchNotAvailable) -> Doc -> PatchNotAvailable
forall a b. (a -> b) -> a -> b
$ Doc -> Doc
er (PatchInfo -> Doc
displayPatchInfo PatchInfo
pinf Doc -> Doc -> Doc
$$ String -> Doc
text String
e)

-- | Return 'Just' the patch content or 'Nothing' if it is unavailable.
hopefullyM :: PatchInfoAndG p wA wB -> Maybe (p wA wB)
hopefullyM :: forall (p :: * -> * -> *) wA wB.
PatchInfoAndG p wA wB -> Maybe (p wA wB)
hopefullyM (PIAP PatchInfo
_ Hopefully p wA wB
hp) = case Hopefully p wA wB -> Either String (p wA wB)
forall (a :: * -> * -> *) wX wY.
Hopefully a wX wY -> Either String (a wX wY)
hopefully2either Hopefully p wA wB
hp of
                              Right p wA wB
p -> p wA wB -> Maybe (p wA wB)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return p wA wB
p
                              Left String
_ -> Maybe (p wA wB)
forall a. Maybe a
Nothing

-- Any recommendations for a nice adverb to name the below?
hopefully2either :: Hopefully a wX wY -> Either String (a wX wY)
hopefully2either :: forall (a :: * -> * -> *) wX wY.
Hopefully a wX wY -> Either String (a wX wY)
hopefully2either (Hopefully (Actually a wX wY
p)) = a wX wY -> Either String (a wX wY)
forall a b. b -> Either a b
Right a wX wY
p
hopefully2either (Hashed PatchHash
_ (Actually a wX wY
p)) = a wX wY -> Either String (a wX wY)
forall a b. b -> Either a b
Right a wX wY
p
hopefully2either (Hopefully (Unavailable String
e)) = String -> Either String (a wX wY)
forall a b. a -> Either a b
Left String
e
hopefully2either (Hashed PatchHash
_ (Unavailable String
e)) = String -> Either String (a wX wY)
forall a b. a -> Either a b
Left String
e

actually :: a wX wY -> Hopefully a wX wY
actually :: forall (a :: * -> * -> *) wX wY. a wX wY -> Hopefully a wX wY
actually = SimpleHopefully a wX wY -> Hopefully a wX wY
forall (a :: * -> * -> *) wX wY.
SimpleHopefully a wX wY -> Hopefully a wX wY
Hopefully (SimpleHopefully a wX wY -> Hopefully a wX wY)
-> (a wX wY -> SimpleHopefully a wX wY)
-> a wX wY
-> Hopefully a wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a wX wY -> SimpleHopefully a wX wY
forall (a :: * -> * -> *) wX wY. a wX wY -> SimpleHopefully a wX wY
Actually

createHashed :: PatchHash -> (PatchHash -> IO (Sealed (a wX))) -> IO (Sealed (Hopefully a wX))
createHashed :: forall (a :: * -> * -> *) wX.
PatchHash
-> (PatchHash -> IO (Sealed (a wX)))
-> IO (Sealed (Hopefully a wX))
createHashed PatchHash
h PatchHash -> IO (Sealed (a wX))
f = (forall wX. SimpleHopefully a wX wX -> Hopefully a wX wX)
-> Sealed (SimpleHopefully a wX) -> Sealed (Hopefully a wX)
forall (a :: * -> *) (b :: * -> *).
(forall wX. a wX -> b wX) -> Sealed a -> Sealed b
mapSeal (PatchHash -> SimpleHopefully a wX wX -> Hopefully a wX wX
forall (a :: * -> * -> *) wX wY.
PatchHash -> SimpleHopefully a wX wY -> Hopefully a wX wY
Hashed PatchHash
h) (Sealed (SimpleHopefully a wX) -> Sealed (Hopefully a wX))
-> IO (Sealed (SimpleHopefully a wX))
-> IO (Sealed (Hopefully a wX))
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` IO (Sealed (SimpleHopefully a wX))
-> IO (Sealed (SimpleHopefully a wX))
forall a. IO a -> IO a
unsafeInterleaveIO (IO (Sealed (SimpleHopefully a wX))
f' IO (Sealed (SimpleHopefully a wX))
-> (SomeException -> IO (Sealed (SimpleHopefully a wX)))
-> IO (Sealed (SimpleHopefully a wX))
forall a. IO a -> (SomeException -> IO a) -> IO a
`catchNonSignal` SomeException -> IO (Sealed (SimpleHopefully a wX))
forall {m :: * -> *} {a :: * -> * -> *} {wX}.
Monad m =>
SomeException -> m (Sealed (SimpleHopefully a wX))
handler)
  where
  f' :: IO (Sealed (SimpleHopefully a wX))
f' = do Sealed a wX wX
x <- PatchHash -> IO (Sealed (a wX))
f PatchHash
h
          Sealed (SimpleHopefully a wX) -> IO (Sealed (SimpleHopefully a wX))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (SimpleHopefully a wX wX -> Sealed (SimpleHopefully a wX)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (a wX wX -> SimpleHopefully a wX wX
forall (a :: * -> * -> *) wX wY. a wX wY -> SimpleHopefully a wX wY
Actually a wX wX
x))
  handler :: SomeException -> m (Sealed (SimpleHopefully a wX))
handler SomeException
e = Sealed (SimpleHopefully a wX) -> m (Sealed (SimpleHopefully a wX))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed (SimpleHopefully a wX)
 -> m (Sealed (SimpleHopefully a wX)))
-> Sealed (SimpleHopefully a wX)
-> m (Sealed (SimpleHopefully a wX))
forall a b. (a -> b) -> a -> b
$ SimpleHopefully a wX Any -> Sealed (SimpleHopefully a wX)
forall (a :: * -> *) wX. a wX -> Sealed a
seal (SimpleHopefully a wX Any -> Sealed (SimpleHopefully a wX))
-> SimpleHopefully a wX Any -> Sealed (SimpleHopefully a wX)
forall a b. (a -> b) -> a -> b
$ String -> SimpleHopefully a wX Any
forall (a :: * -> * -> *) wX wY. String -> SimpleHopefully a wX wY
Unavailable (String -> SimpleHopefully a wX Any)
-> String -> SimpleHopefully a wX Any
forall a b. (a -> b) -> a -> b
$ SomeException -> String
prettyException SomeException
e

extractHash :: PatchInfoAndG p wA wB -> Either (p wA wB) PatchHash
extractHash :: forall (p :: * -> * -> *) wA wB.
PatchInfoAndG p wA wB -> Either (p wA wB) PatchHash
extractHash (PIAP PatchInfo
_ (Hashed PatchHash
sh SimpleHopefully p wA wB
_)) = PatchHash -> Either (p wA wB) PatchHash
forall a b. b -> Either a b
Right PatchHash
sh
extractHash PatchInfoAndG p wA wB
hp = p wA wB -> Either (p wA wB) PatchHash
forall a b. a -> Either a b
Left (p wA wB -> Either (p wA wB) PatchHash)
-> p wA wB -> Either (p wA wB) PatchHash
forall a b. (a -> b) -> a -> b
$ (Doc -> Doc) -> PatchInfoAndG p wA wB -> p wA wB
forall (p :: * -> * -> *) wA wB.
(Doc -> Doc) -> PatchInfoAndG p wA wB -> p wA wB
conscientiously (\Doc
e -> String -> Doc
text String
"unable to read patch:" Doc -> Doc -> Doc
$$ Doc
e) PatchInfoAndG p wA wB
hp

unavailable :: String -> Hopefully a wX wY
unavailable :: forall (a :: * -> * -> *) wX wY. String -> Hopefully a wX wY
unavailable = SimpleHopefully a wX wY -> Hopefully a wX wY
forall (a :: * -> * -> *) wX wY.
SimpleHopefully a wX wY -> Hopefully a wX wY
Hopefully (SimpleHopefully a wX wY -> Hopefully a wX wY)
-> (String -> SimpleHopefully a wX wY)
-> String
-> Hopefully a wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SimpleHopefully a wX wY
forall (a :: * -> * -> *) wX wY. String -> SimpleHopefully a wX wY
Unavailable

-- * Instances defined only for PatchInfoAnd

instance Show2 p => Show1 (PatchInfoAnd p wX)

instance Show2 p => Show2 (PatchInfoAnd p)

instance RepairToFL p => Repair (PatchInfoAnd p) where
    applyAndTryToFix :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (PatchInfoAnd p)) m =>
PatchInfoAnd p wX wY -> m (Maybe (String, PatchInfoAnd p wX wY))
applyAndTryToFix PatchInfoAnd p wX wY
p = do Maybe (String, Named p wX wY)
mp' <- Named p wX wY -> m (Maybe (String, Named p wX wY))
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (Named p)) m =>
Named p wX wY -> m (Maybe (String, Named p wX wY))
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(Repair p, ApplyMonad (ApplyState p) m) =>
p wX wY -> m (Maybe (String, p wX wY))
applyAndTryToFix (Named p wX wY -> m (Maybe (String, Named p wX wY)))
-> Named p wX wY -> m (Maybe (String, Named p wX wY))
forall a b. (a -> b) -> a -> b
$ PatchInfoAnd p wX wY -> Named p wX wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully PatchInfoAnd p wX wY
p
                            case Maybe (String, Named p wX wY)
mp' of
                              Maybe (String, Named p wX wY)
Nothing -> Maybe (String, PatchInfoAnd p wX wY)
-> m (Maybe (String, PatchInfoAnd p wX wY))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (String, PatchInfoAnd p wX wY)
forall a. Maybe a
Nothing
                              Just (String
e,Named p wX wY
p') -> Maybe (String, PatchInfoAnd p wX wY)
-> m (Maybe (String, PatchInfoAnd p wX wY))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (String, PatchInfoAnd p wX wY)
 -> m (Maybe (String, PatchInfoAnd p wX wY)))
-> Maybe (String, PatchInfoAnd p wX wY)
-> m (Maybe (String, PatchInfoAnd p wX wY))
forall a b. (a -> b) -> a -> b
$ (String, PatchInfoAnd p wX wY)
-> Maybe (String, PatchInfoAnd p wX wY)
forall a. a -> Maybe a
Just (String
e, Named p wX wY -> PatchInfoAnd p wX wY
forall (p :: * -> * -> *) wX wY.
(Ident p, PatchId p ~ PatchInfo) =>
p wX wY -> PatchInfoAndG p wX wY
n2pia Named p wX wY
p')

-- * Instances defined for PatchInfoAndG

instance PrimPatchBase p => PrimPatchBase (PatchInfoAndG p) where
   type PrimOf (PatchInfoAndG p) = PrimOf p

getHopefully :: Hopefully p wX wY -> SimpleHopefully p wX wY
getHopefully :: forall (p :: * -> * -> *) wX wY.
Hopefully p wX wY -> SimpleHopefully p wX wY
getHopefully (Hashed PatchHash
_ SimpleHopefully p wX wY
x) = SimpleHopefully p wX wY
x
getHopefully (Hopefully SimpleHopefully p wX wY
x) = SimpleHopefully p wX wY
x

instance Eq2 p => Eq2 (SimpleHopefully p) where
    Actually p wA wB
p1 unsafeCompare :: forall wA wB wC wD.
SimpleHopefully p wA wB -> SimpleHopefully p wC wD -> Bool
`unsafeCompare` Actually p wC wD
p2 = p wA wB
p1 p wA wB -> p wC wD -> Bool
forall wA wB wC wD. p wA wB -> p wC wD -> Bool
forall (p :: * -> * -> *) wA wB wC wD.
Eq2 p =>
p wA wB -> p wC wD -> Bool
`unsafeCompare` p wC wD
p2
    SimpleHopefully p wA wB
_ `unsafeCompare` SimpleHopefully p wC wD
_ = String -> Bool
forall a. HasCallStack => String -> a
error String
"cannot compare unavailable patches"

instance Eq2 p => Eq2 (Hopefully p) where
    Hashed PatchHash
h1 SimpleHopefully p wA wB
_ unsafeCompare :: forall wA wB wC wD. Hopefully p wA wB -> Hopefully p wC wD -> Bool
`unsafeCompare` Hashed PatchHash
h2 SimpleHopefully p wC wD
_ = PatchHash
h1 PatchHash -> PatchHash -> Bool
forall a. Eq a => a -> a -> Bool
== PatchHash
h2
    Hopefully p wA wB
hp1 `unsafeCompare` Hopefully p wC wD
hp2 =
      Hopefully p wA wB -> SimpleHopefully p wA wB
forall (p :: * -> * -> *) wX wY.
Hopefully p wX wY -> SimpleHopefully p wX wY
getHopefully Hopefully p wA wB
hp1 SimpleHopefully p wA wB -> SimpleHopefully p wC wD -> Bool
forall wA wB wC wD.
SimpleHopefully p wA wB -> SimpleHopefully p wC wD -> Bool
forall (p :: * -> * -> *) wA wB wC wD.
Eq2 p =>
p wA wB -> p wC wD -> Bool
`unsafeCompare` Hopefully p wC wD -> SimpleHopefully p wC wD
forall (p :: * -> * -> *) wX wY.
Hopefully p wX wY -> SimpleHopefully p wX wY
getHopefully Hopefully p wC wD
hp2

instance Eq2 p => Eq2 (PatchInfoAndG p) where
    PIAP PatchInfo
i1 Hopefully p wA wB
p1 unsafeCompare :: forall wA wB wC wD.
PatchInfoAndG p wA wB -> PatchInfoAndG p wC wD -> Bool
`unsafeCompare` PIAP PatchInfo
i2 Hopefully p wC wD
p2 = PatchInfo
i1 PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfo
i2 Bool -> Bool -> Bool
&& Hopefully p wA wB
p1 Hopefully p wA wB -> Hopefully p wC wD -> Bool
forall wA wB wC wD. Hopefully p wA wB -> Hopefully p wC wD -> Bool
forall (p :: * -> * -> *) wA wB wC wD.
Eq2 p =>
p wA wB -> p wC wD -> Bool
`unsafeCompare` Hopefully p wC wD
p2

type instance PatchId (PatchInfoAndG p) = PatchInfo

instance Ident (PatchInfoAndG p) where
    ident :: forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
ident (PIAP PatchInfo
i Hopefully p wX wY
_) = PatchInfo
PatchId (PatchInfoAndG p)
i

instance PatchListFormat (PatchInfoAndG p)

instance ShowPatchBasic p => ShowPatchBasic (PatchInfoAndG p) where
    showPatch :: forall wX wY. ShowPatchFor -> PatchInfoAndG p wX wY -> Doc
showPatch ShowPatchFor
f (PIAP PatchInfo
n Hopefully p wX wY
p) =
      case Hopefully p wX wY -> Either String (p wX wY)
forall (a :: * -> * -> *) wX wY.
Hopefully a wX wY -> Either String (a wX wY)
hopefully2either Hopefully p wX wY
p of
        Right p wX wY
x -> ShowPatchFor -> p wX wY -> Doc
forall wX wY. ShowPatchFor -> p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> p wX wY -> Doc
showPatch ShowPatchFor
f p wX wY
x
        Left String
_ -> ShowPatchFor -> PatchInfo -> Doc
showPatchInfo ShowPatchFor
f PatchInfo
n

instance ShowContextPatch p => ShowContextPatch (PatchInfoAndG p) where
  showPatchWithContextAndApply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (PatchInfoAndG p)) m =>
ShowPatchFor -> PatchInfoAndG p wX wY -> m Doc
showPatchWithContextAndApply ShowPatchFor
f (PIAP PatchInfo
n Hopefully p wX wY
p) =
    case Hopefully p wX wY -> Either String (p wX wY)
forall (a :: * -> * -> *) wX wY.
Hopefully a wX wY -> Either String (a wX wY)
hopefully2either Hopefully p wX wY
p of
      Right p wX wY
x -> ShowPatchFor -> p wX wY -> m Doc
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState p) m =>
ShowPatchFor -> p wX wY -> m Doc
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(ShowContextPatch p, ApplyMonad (ApplyState p) m) =>
ShowPatchFor -> p wX wY -> m Doc
showPatchWithContextAndApply ShowPatchFor
f p wX wY
x
      Left String
_ -> Doc -> m Doc
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> m Doc) -> Doc -> m Doc
forall a b. (a -> b) -> a -> b
$ ShowPatchFor -> PatchInfo -> Doc
showPatchInfo ShowPatchFor
f PatchInfo
n

instance (Summary p, PatchListFormat p,
          ShowPatch p) => ShowPatch (PatchInfoAndG p) where
    description :: forall wX wY. PatchInfoAndG p wX wY -> Doc
description (PIAP PatchInfo
n Hopefully p wX wY
_) = PatchInfo -> Doc
displayPatchInfo PatchInfo
n
    summary :: forall wX wY. PatchInfoAndG p wX wY -> Doc
summary (PIAP PatchInfo
_ Hopefully p wX wY
p) =
      case Hopefully p wX wY -> Either String (p wX wY)
forall (a :: * -> * -> *) wX wY.
Hopefully a wX wY -> Either String (a wX wY)
hopefully2either Hopefully p wX wY
p of
        Right p wX wY
x -> p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
summary p wX wY
x
        Left String
_ -> String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
"[patch summary is unavailable]"
    summaryFL :: forall wX wY. FL (PatchInfoAndG p) wX wY -> Doc
summaryFL = [Doc] -> Doc
vcat ([Doc] -> Doc)
-> (FL (PatchInfoAndG p) wX wY -> [Doc])
-> FL (PatchInfoAndG p) wX wY
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wX wY. PatchInfoAndG p wX wY -> Doc)
-> FL (PatchInfoAndG p) wX wY -> [Doc]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL PatchInfoAndG p wW wZ -> Doc
forall wX wY. PatchInfoAndG p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
summary
    content :: forall wX wY. PatchInfoAndG p wX wY -> Doc
content (PIAP PatchInfo
_ Hopefully p wX wY
p) =
      case Hopefully p wX wY -> Either String (p wX wY)
forall (a :: * -> * -> *) wX wY.
Hopefully a wX wY -> Either String (a wX wY)
hopefully2either Hopefully p wX wY
p of
        Right p wX wY
x -> p wX wY -> Doc
forall wX wY. p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
content p wX wY
x
        Left String
_ -> String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
"[patch content is unavailable]"

instance (PatchId p ~ PatchInfo, Commute p) => Commute (PatchInfoAndG p) where
    commute :: forall wX wY.
(:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
-> Maybe ((:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY)
commute (PatchInfoAndG p wX wZ
x :> PatchInfoAndG p wZ wY
y) = do p wX wZ
y' :> p wZ wY
x' <- (:>) p p wX wY -> Maybe ((:>) p p wX wY)
forall wX wY. (:>) p p wX wY -> Maybe ((:>) p p wX wY)
forall (p :: * -> * -> *) wX wY.
Commute p =>
(:>) p p wX wY -> Maybe ((:>) p p wX wY)
commute (PatchInfoAndG p wX wZ -> p wX wZ
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully PatchInfoAndG p wX wZ
x p wX wZ -> p wZ wY -> (:>) p p wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> PatchInfoAndG p wZ wY -> p wZ wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully PatchInfoAndG p wZ wY
y)
                          (:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
-> Maybe ((:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ((:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
 -> Maybe ((:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY))
-> (:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
-> Maybe ((:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY)
forall a b. (a -> b) -> a -> b
$ (PatchInfoAndG p wZ wY -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wY
y PatchInfo -> p wX wZ -> PatchInfoAndG p wX wZ
forall (p :: * -> * -> *) wA wB.
PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
`piap` p wX wZ
y') PatchInfoAndG p wX wZ
-> PatchInfoAndG p wZ wY
-> (:>) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> (PatchInfoAndG p wX wZ -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wX wZ
x PatchInfo -> p wZ wY -> PatchInfoAndG p wZ wY
forall (p :: * -> * -> *) wA wB.
PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
`piap` p wZ wY
x')

instance (PatchId p ~ PatchInfo, CleanMerge p) =>
         CleanMerge (PatchInfoAndG p) where
    cleanMerge :: forall wX wY.
(:\/:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
-> Maybe ((:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY)
cleanMerge (PatchInfoAndG p wZ wX
x :\/: PatchInfoAndG p wZ wY
y)
      | PatchInfoAndG p wZ wX -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wX
x PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfoAndG p wZ wY -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wY
y = String -> Maybe ((:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY)
forall a. HasCallStack => String -> a
error String
"cannot cleanMerge identical PatchInfoAndG"
      | Bool
otherwise = do
          p wX wZ
y' :/\: p wY wZ
x' <- (:\/:) p p wX wY -> Maybe ((:/\:) p p wX wY)
forall wX wY. (:\/:) p p wX wY -> Maybe ((:/\:) p p wX wY)
forall (p :: * -> * -> *) wX wY.
CleanMerge p =>
(:\/:) p p wX wY -> Maybe ((:/\:) p p wX wY)
cleanMerge (PatchInfoAndG p wZ wX -> p wZ wX
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully PatchInfoAndG p wZ wX
x p wZ wX -> p wZ wY -> (:\/:) p p wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wZ wX -> a2 wZ wY -> (:\/:) a1 a2 wX wY
:\/: PatchInfoAndG p wZ wY -> p wZ wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully PatchInfoAndG p wZ wY
y)
          (:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
-> Maybe ((:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ((:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
 -> Maybe ((:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY))
-> (:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
-> Maybe ((:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY)
forall a b. (a -> b) -> a -> b
$ (PatchInfoAndG p wZ wY -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wY
y PatchInfo -> p wX wZ -> PatchInfoAndG p wX wZ
forall (p :: * -> * -> *) wA wB.
PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
`piap` p wX wZ
y') PatchInfoAndG p wX wZ
-> PatchInfoAndG p wY wZ
-> (:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: (PatchInfoAndG p wZ wX -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wX
x PatchInfo -> p wY wZ -> PatchInfoAndG p wY wZ
forall (p :: * -> * -> *) wA wB.
PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
`piap` p wY wZ
x')

instance (PatchId p ~ PatchInfo, Merge p) => Merge (PatchInfoAndG p) where
    merge :: forall wX wY.
(:\/:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
-> (:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
merge (PatchInfoAndG p wZ wX
x :\/: PatchInfoAndG p wZ wY
y)
      | PatchInfoAndG p wZ wX -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wX
x PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfoAndG p wZ wY -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wY
y = String -> (:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
forall a. HasCallStack => String -> a
error String
"cannot merge identical PatchInfoAndG"
      | Bool
otherwise =
          case (:\/:) p p wX wY -> (:/\:) p p wX wY
forall wX wY. (:\/:) p p wX wY -> (:/\:) p p wX wY
forall (p :: * -> * -> *) wX wY.
Merge p =>
(:\/:) p p wX wY -> (:/\:) p p wX wY
merge (PatchInfoAndG p wZ wX -> p wZ wX
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully PatchInfoAndG p wZ wX
x p wZ wX -> p wZ wY -> (:\/:) p p wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wZ wX -> a2 wZ wY -> (:\/:) a1 a2 wX wY
:\/: PatchInfoAndG p wZ wY -> p wZ wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully PatchInfoAndG p wZ wY
y) of
            p wX wZ
y' :/\: p wY wZ
x' -> (PatchInfoAndG p wZ wY -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wY
y PatchInfo -> p wX wZ -> PatchInfoAndG p wX wZ
forall (p :: * -> * -> *) wA wB.
PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
`piap` p wX wZ
y') PatchInfoAndG p wX wZ
-> PatchInfoAndG p wY wZ
-> (:/\:) (PatchInfoAndG p) (PatchInfoAndG p) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: (PatchInfoAndG p wZ wX -> PatchId (PatchInfoAndG p)
forall wX wY. PatchInfoAndG p wX wY -> PatchId (PatchInfoAndG p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG p wZ wX
x PatchInfo -> p wY wZ -> PatchInfoAndG p wY wZ
forall (p :: * -> * -> *) wA wB.
PatchInfo -> p wA wB -> PatchInfoAndG p wA wB
`piap` p wY wZ
x')

instance PatchInspect p => PatchInspect (PatchInfoAndG p) where
    listTouchedFiles :: forall wX wY. PatchInfoAndG p wX wY -> [AnchoredPath]
listTouchedFiles = p wX wY -> [AnchoredPath]
forall wX wY. p wX wY -> [AnchoredPath]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [AnchoredPath]
listTouchedFiles (p wX wY -> [AnchoredPath])
-> (PatchInfoAndG p wX wY -> p wX wY)
-> PatchInfoAndG p wX wY
-> [AnchoredPath]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG p wX wY -> p wX wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully
    hunkMatches :: forall wX wY. (ByteString -> Bool) -> PatchInfoAndG p wX wY -> Bool
hunkMatches ByteString -> Bool
f = (ByteString -> Bool) -> p wX wY -> Bool
forall wX wY. (ByteString -> Bool) -> p wX wY -> Bool
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
(ByteString -> Bool) -> p wX wY -> Bool
hunkMatches ByteString -> Bool
f (p wX wY -> Bool)
-> (PatchInfoAndG p wX wY -> p wX wY)
-> PatchInfoAndG p wX wY
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG p wX wY -> p wX wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully

instance Apply p => Apply (PatchInfoAndG p) where
    type ApplyState (PatchInfoAndG p) = ApplyState p
    apply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (PatchInfoAndG p)) m =>
PatchInfoAndG p wX wY -> m ()
apply = p wX wY -> m ()
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState p) m =>
p wX wY -> m ()
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(Apply p, ApplyMonad (ApplyState p) m) =>
p wX wY -> m ()
apply (p wX wY -> m ())
-> (PatchInfoAndG p wX wY -> p wX wY)
-> PatchInfoAndG p wX wY
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG p wX wY -> p wX wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully
    unapply :: forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState (PatchInfoAndG p)) m =>
PatchInfoAndG p wX wY -> m ()
unapply = p wX wY -> m ()
forall (m :: * -> *) wX wY.
ApplyMonad (ApplyState p) m =>
p wX wY -> m ()
forall (p :: * -> * -> *) (m :: * -> *) wX wY.
(Apply p, ApplyMonad (ApplyState p) m) =>
p wX wY -> m ()
unapply (p wX wY -> m ())
-> (PatchInfoAndG p wX wY -> p wX wY)
-> PatchInfoAndG p wX wY
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG p wX wY -> p wX wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully

instance ( ReadPatch p, Ident p, PatchId p ~ PatchInfo
         ) => ReadPatch (PatchInfoAndG p) where
    readPatch' :: forall wX. Parser (Sealed (PatchInfoAndG p wX))
readPatch' = (forall wX. p wX wX -> PatchInfoAndG p wX wX)
-> Sealed (p wX) -> Sealed (PatchInfoAndG p wX)
forall (a :: * -> *) (b :: * -> *).
(forall wX. a wX -> b wX) -> Sealed a -> Sealed b
mapSeal p wX wX -> PatchInfoAndG p wX wX
forall wX. p wX wX -> PatchInfoAndG p wX wX
forall (p :: * -> * -> *) wX wY.
(Ident p, PatchId p ~ PatchInfo) =>
p wX wY -> PatchInfoAndG p wX wY
n2pia (Sealed (p wX) -> Sealed (PatchInfoAndG p wX))
-> Parser ByteString (Sealed (p wX))
-> Parser ByteString (Sealed (PatchInfoAndG p wX))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString (Sealed (p wX))
forall wX. Parser (Sealed (p wX))
forall (p :: * -> * -> *) wX. ReadPatch p => Parser (Sealed (p wX))
readPatch'

instance Effect p => Effect (PatchInfoAndG p) where
    effect :: forall wX wY.
PatchInfoAndG p wX wY -> FL (PrimOf (PatchInfoAndG p)) wX wY
effect = p wX wY -> FL (PrimOf p) wX wY
forall wX wY. p wX wY -> FL (PrimOf p) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect (p wX wY -> FL (PrimOf p) wX wY)
-> (PatchInfoAndG p wX wY -> p wX wY)
-> PatchInfoAndG p wX wY
-> FL (PrimOf p) wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG p wX wY -> p wX wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully

instance IsHunk (PatchInfoAndG p) where
    isHunk :: forall wX wY.
PatchInfoAndG p wX wY
-> Maybe (FileHunk (ObjectIdOfPatch (PatchInfoAndG p)) wX wY)
isHunk PatchInfoAndG p wX wY
_ = Maybe (FileHunk (ObjectIdOf (ApplyState p)) wX wY)
Maybe (FileHunk (ObjectIdOfPatch (PatchInfoAndG p)) wX wY)
forall a. Maybe a
Nothing

instance PatchDebug p => PatchDebug (PatchInfoAndG p)

instance (Commute p, Conflict p, Summary p, PrimPatchBase p, PatchListFormat p, ShowPatch p) => Conflict (PatchInfoAnd p) where
    isConflicted :: forall wX wY. PatchInfoAnd p wX wY -> Bool
isConflicted = Named p wX wY -> Bool
forall wX wY. Named p wX wY -> Bool
forall (p :: * -> * -> *) wX wY. Conflict p => p wX wY -> Bool
isConflicted (Named p wX wY -> Bool)
-> (PatchInfoAnd p wX wY -> Named p wX wY)
-> PatchInfoAnd p wX wY
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAnd p wX wY -> Named p wX wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully
    -- Note: this relies on the laziness of 'hopefully' for efficiency
    -- and correctness in the face of lazy repositories
    resolveConflicts :: forall wO wX wY.
RL (PatchInfoAnd p) wO wX
-> RL (PatchInfoAnd p) wX wY
-> [ConflictDetails (PrimOf (PatchInfoAnd p)) wY]
resolveConflicts RL (PatchInfoAnd p) wO wX
context RL (PatchInfoAnd p) wX wY
patches =
      RL (Named p) wO wX
-> RL (Named p) wX wY -> [ConflictDetails (PrimOf (Named p)) wY]
forall wO wX wY.
RL (Named p) wO wX
-> RL (Named p) wX wY -> [ConflictDetails (PrimOf (Named p)) wY]
forall (p :: * -> * -> *) wO wX wY.
Conflict p =>
RL p wO wX -> RL p wX wY -> [ConflictDetails (PrimOf p) wY]
resolveConflicts ((forall wW wY. PatchInfoAnd p wW wY -> Named p wW wY)
-> RL (PatchInfoAnd p) wO wX -> RL (Named p) wO wX
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> RL a wX wZ -> RL b wX wZ
mapRL_RL PatchInfoAndG (Named p) wW wY -> Named p wW wY
forall wW wY. PatchInfoAnd p wW wY -> Named p wW wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully RL (PatchInfoAnd p) wO wX
context) ((forall wW wY. PatchInfoAnd p wW wY -> Named p wW wY)
-> RL (PatchInfoAnd p) wX wY -> RL (Named p) wX wY
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> RL a wX wZ -> RL b wX wZ
mapRL_RL PatchInfoAndG (Named p) wW wY -> Named p wW wY
forall wW wY. PatchInfoAnd p wW wY -> Named p wW wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully RL (PatchInfoAnd p) wX wY
patches)