-- 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
    , WPatchInfo
    , unWPatchInfo
    , compareWPatchInfo
    , piap
    , n2pia
    , patchInfoAndPatch
    , fmapPIAP
    , fmapFLPIAP
    , conscientiously
    , hopefully
    , info
    , winfo
    , 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.Util.SignalHandler ( catchNonSignal )
import Darcs.Util.Printer ( Doc, ($$), renderString, text, vcat )
import Darcs.Patch.Ident ( Ident(..), PatchId, IdEq2(..) )
import Darcs.Patch.Info ( PatchInfo, showPatchInfo, displayPatchInfo, justName )
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.Merge ( CleanMerge(..), Merge(..) )
import Darcs.Patch.Named ( Named, fmapFL_Named )
import Darcs.Patch.Apply ( Apply(..) )
import Darcs.Patch.Commute ( Commute(..) )
import Darcs.Patch.Inspect ( PatchInspect(..) )
import Darcs.Patch.FromPrim ( PrimPatchBase(..) )
import Darcs.Patch.Read ( ReadPatch(..) )
import Darcs.Patch.Show ( ShowPatch(..) )
import Darcs.Patch.Repair ( Repair(..), RepairToFL )
import Darcs.Patch.RepoType ( RepoType(..) )
import Darcs.Patch.Show ( ShowPatchBasic(..), ShowContextPatch(..) )
import Darcs.Patch.Summary ( Summary )
import Darcs.Patch.Witnesses.Eq ( Eq2(..), EqCheck(..) )
import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP )
import Darcs.Patch.Witnesses.Ordered
  ( (:/\:)(..)
  , (:>)(..)
  , (:\/:)(..)
  , FL
  , mapFL
  , mapRL_RL
  )
import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed), seal, mapSeal )
import Darcs.Patch.Witnesses.Show ( Show1, Show2 )
import Darcs.Util.Exception ( prettyException )

-- | @'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 String (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
showList :: [Hopefully a wX wY] -> ShowS
$cshowList :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
[Hopefully a wX wY] -> ShowS
show :: Hopefully a wX wY -> String
$cshow :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Hopefully a wX wY -> String
showsPrec :: Int -> Hopefully a wX wY -> ShowS
$cshowsPrec :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Int -> 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
showList :: [SimpleHopefully a wX wY] -> ShowS
$cshowList :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
[SimpleHopefully a wX wY] -> ShowS
show :: SimpleHopefully a wX wY -> String
$cshow :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
SimpleHopefully a wX wY -> String
showsPrec :: Int -> SimpleHopefully a wX wY -> ShowS
$cshowsPrec :: forall (a :: * -> * -> *) wX wY.
Show (a wX wY) =>
Int -> SimpleHopefully a wX wY -> ShowS
Show

type PatchInfoAnd rt p = PatchInfoAndG rt (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 (rt :: RepoType) p wA wB =
  PIAP !PatchInfo
       (Hopefully p wA wB)
  deriving (Int -> PatchInfoAndG rt p wA wB -> ShowS
[PatchInfoAndG rt p wA wB] -> ShowS
PatchInfoAndG rt p wA wB -> String
(Int -> PatchInfoAndG rt p wA wB -> ShowS)
-> (PatchInfoAndG rt p wA wB -> String)
-> ([PatchInfoAndG rt p wA wB] -> ShowS)
-> Show (PatchInfoAndG rt p wA wB)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
Int -> PatchInfoAndG rt p wA wB -> ShowS
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
[PatchInfoAndG rt p wA wB] -> ShowS
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
PatchInfoAndG rt p wA wB -> String
showList :: [PatchInfoAndG rt p wA wB] -> ShowS
$cshowList :: forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
[PatchInfoAndG rt p wA wB] -> ShowS
show :: PatchInfoAndG rt p wA wB -> String
$cshow :: forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
PatchInfoAndG rt p wA wB -> String
showsPrec :: Int -> PatchInfoAndG rt p wA wB -> ShowS
$cshowsPrec :: forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
Show (p wA wB) =>
Int -> PatchInfoAndG rt p wA wB -> ShowS
Show)

-- | @'WPatchInfo' wA wB@ represents the info of a patch, marked with
-- the patch's witnesses.
newtype WPatchInfo wA wB = WPatchInfo { WPatchInfo wA wB -> PatchInfo
unWPatchInfo :: PatchInfo }

-- This is actually unsafe if we ever commute patches and then compare them
-- using this function. TODO: consider adding an extra existential to WPatchInfo
-- (as with LabelledPatch in Darcs.Patch.Choices)
compareWPatchInfo :: WPatchInfo wA wB -> WPatchInfo wC wD -> EqCheck (wA, wB) (wC, wD)
compareWPatchInfo :: WPatchInfo wA wB -> WPatchInfo wC wD -> EqCheck (wA, wB) (wC, wD)
compareWPatchInfo (WPatchInfo PatchInfo
x) (WPatchInfo PatchInfo
y) = if PatchInfo
x PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfo
y then EqCheck Any Any -> EqCheck (wA, wB) (wC, wD)
forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP EqCheck Any Any
forall wA. EqCheck wA wA
IsEq else EqCheck (wA, wB) (wC, wD)
forall wA wB. EqCheck wA wB
NotEq

instance Eq2 WPatchInfo where
   WPatchInfo PatchInfo
x unsafeCompare :: WPatchInfo wA wB -> WPatchInfo wC wD -> Bool
`unsafeCompare` WPatchInfo PatchInfo
y = PatchInfo
x PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfo
y

fmapH :: (a wX wY -> b wW wZ) -> Hopefully a wX wY -> Hopefully b wW wZ
fmapH :: (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 String
h SimpleHopefully a wX wY
sh) = String -> SimpleHopefully b wW wZ -> Hopefully b wW wZ
forall (a :: * -> * -> *) wX wY.
String -> SimpleHopefully a wX wY -> Hopefully a wX wY
Hashed String
h (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 rt p wA wB -> PatchInfo
info :: PatchInfoAndG rt p wA wB -> PatchInfo
info (PIAP PatchInfo
i Hopefully p wA wB
_) = PatchInfo
i

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

winfo :: PatchInfoAnd rt p wA wB -> WPatchInfo wA wB
winfo :: PatchInfoAnd rt p wA wB -> WPatchInfo wA wB
winfo (PIAP PatchInfo
i Hopefully (Named p) wA wB
_) = PatchInfo -> WPatchInfo wA wB
forall wA wB. PatchInfo -> WPatchInfo wA wB
WPatchInfo PatchInfo
i

-- | @'piap' i p@ creates a PatchInfoAnd containing p with info i.
piap :: PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
piap :: PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
piap PatchInfo
i p wA wB
p = PatchInfo -> Hopefully p wA wB -> PatchInfoAndG rt p wA wB
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfo -> Hopefully p wA wB -> PatchInfoAndG rt 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 rt p wX wY
n2pia :: p wX wY -> PatchInfoAndG rt p wX wY
n2pia p wX wY
x = 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 rt p wX wY
forall (p :: * -> * -> *) wA wB (rt :: RepoType).
PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
`piap` p wX wY
x

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

fmapFLPIAP :: (FL p wX wY -> FL q wX wY)
           -> PatchInfoAnd rt p wX wY -> PatchInfoAnd rt q wX wY
fmapFLPIAP :: (FL p wX wY -> FL q wX wY)
-> PatchInfoAnd rt p wX wY -> PatchInfoAnd rt 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 -> PatchInfoAnd rt q wX wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfo -> Hopefully p wA wB -> PatchInfoAndG rt 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 rt p wX wY -> PatchInfoAndG rt q wX wY
fmapPIAP :: (p wX wY -> q wX wY)
-> PatchInfoAndG rt p wX wY -> PatchInfoAndG rt 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 rt q wX wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfo -> Hopefully p wA wB -> PatchInfoAndG rt 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 rt p wA wB -> p wA wB
hopefully :: PatchInfoAndG rt p wA wB -> p wA wB
hopefully = (Doc -> Doc) -> PatchInfoAndG rt p wA wB -> p wA wB
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
(Doc -> Doc) -> PatchInfoAndG rt p wA wB -> p wA wB
conscientiously ((Doc -> Doc) -> PatchInfoAndG rt p wA wB -> p wA wB)
-> (Doc -> Doc) -> PatchInfoAndG rt 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 rt p wA wB -> p wA wB
conscientiously :: (Doc -> Doc) -> PatchInfoAndG rt 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)

-- | @hopefullyM@ is a version of @hopefully@ which calls @fail@ in a
-- monad instead of erroring.
hopefullyM :: PatchInfoAndG rt p wA wB -> Maybe (p wA wB)
hopefullyM :: PatchInfoAndG rt 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 (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 :: 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 String
_ (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 String
_ (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 :: 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 :: String -> (String -> IO (Sealed (a wX))) -> IO (Sealed (Hopefully a wX))
createHashed :: String
-> (String -> IO (Sealed (a wX))) -> IO (Sealed (Hopefully a wX))
createHashed String
h String -> 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 (String -> SimpleHopefully a wX wX -> Hopefully a wX wX
forall (a :: * -> * -> *) wX wY.
String -> SimpleHopefully a wX wY -> Hopefully a wX wY
Hashed String
h) (Sealed (SimpleHopefully a wX) -> Sealed (Hopefully a wX))
-> IO (Sealed (SimpleHopefully a wX))
-> IO (Sealed (Hopefully a wX))
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 <- String -> IO (Sealed (a wX))
f String
h
          Sealed (SimpleHopefully a wX) -> IO (Sealed (SimpleHopefully a wX))
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 (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 rt p wA wB -> Either (p wA wB) String
extractHash :: PatchInfoAndG rt p wA wB -> Either (p wA wB) String
extractHash (PIAP PatchInfo
_ (Hashed String
s SimpleHopefully p wA wB
_)) = String -> Either (p wA wB) String
forall a b. b -> Either a b
Right String
s
extractHash PatchInfoAndG rt p wA wB
hp = p wA wB -> Either (p wA wB) String
forall a b. a -> Either a b
Left (p wA wB -> Either (p wA wB) String)
-> p wA wB -> Either (p wA wB) String
forall a b. (a -> b) -> a -> b
$ (Doc -> Doc) -> PatchInfoAndG rt p wA wB -> p wA wB
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
(Doc -> Doc) -> PatchInfoAndG rt p wA wB -> p wA wB
conscientiously (\Doc
e -> String -> Doc
text String
"unable to read patch:" Doc -> Doc -> Doc
$$ Doc
e) PatchInfoAndG rt p wA wB
hp

unavailable :: String -> Hopefully a wX wY
unavailable :: 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 rt p wX)

instance Show2 p => Show2 (PatchInfoAnd rt p)

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

-- * Instances defined for PatchInfoAndG

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

-- Equality on PatchInfoAndG is solely determined by the PatchInfo
-- It is a global invariant of darcs that once a patch is recorded,
-- it should always have the same representation in the same context.
instance Eq2 (PatchInfoAndG rt p) where
    unsafeCompare :: PatchInfoAndG rt p wA wB -> PatchInfoAndG rt p wC wD -> Bool
unsafeCompare (PIAP PatchInfo
i Hopefully p wA wB
_) (PIAP PatchInfo
i2 Hopefully p wC wD
_) = PatchInfo
i PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfo
i2

type instance PatchId (PatchInfoAndG rt p) = PatchInfo

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

instance IdEq2 (PatchInfoAndG rt p)

instance PatchListFormat (PatchInfoAndG rt p)

instance ShowPatchBasic p => ShowPatchBasic (PatchInfoAndG rt p) where
    showPatch :: ShowPatchFor -> PatchInfoAndG rt 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 (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 rt p) where
  showContextPatch :: ShowPatchFor -> PatchInfoAndG rt p wX wY -> m Doc
showContextPatch 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 (p :: * -> * -> *) (m :: * -> *) wX wY.
(ShowContextPatch p, ApplyMonad (ApplyState p) m) =>
ShowPatchFor -> p wX wY -> m Doc
showContextPatch ShowPatchFor
f p wX wY
x
      Left String
_ -> Doc -> m Doc
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 rt p) where
    description :: PatchInfoAndG rt p wX wY -> Doc
description (PIAP PatchInfo
n Hopefully p wX wY
_) = PatchInfo -> Doc
displayPatchInfo PatchInfo
n
    summary :: PatchInfoAndG rt 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 (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 :: FL (PatchInfoAndG rt p) wX wY -> Doc
summaryFL = [Doc] -> Doc
vcat ([Doc] -> Doc)
-> (FL (PatchInfoAndG rt p) wX wY -> [Doc])
-> FL (PatchInfoAndG rt p) wX wY
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wX wY. PatchInfoAndG rt p wX wY -> Doc)
-> FL (PatchInfoAndG rt p) wX wY -> [Doc]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL forall wX wY. PatchInfoAndG rt p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
summary
    content :: PatchInfoAndG rt 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 (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 rt p) where
    commute :: (:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
-> Maybe ((:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY)
commute (PatchInfoAndG rt p wX wZ
x :> PatchInfoAndG rt p wZ wY
y) = do p wX wZ
y' :> p wZ wY
x' <- (:>) 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 rt p wX wZ -> p wX wZ
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully PatchInfoAndG rt 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 rt p wZ wY -> p wZ wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully PatchInfoAndG rt p wZ wY
y)
                          (:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
-> Maybe ((:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY)
forall (m :: * -> *) a. Monad m => a -> m a
return ((:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
 -> Maybe ((:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY))
-> (:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
-> Maybe ((:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY)
forall a b. (a -> b) -> a -> b
$ (PatchInfoAndG rt p wZ wY -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wY
y PatchInfo -> p wX wZ -> PatchInfoAndG rt p wX wZ
forall (p :: * -> * -> *) wA wB (rt :: RepoType).
PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
`piap` p wX wZ
y') PatchInfoAndG rt p wX wZ
-> PatchInfoAndG rt p wZ wY
-> (:>) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
forall (a1 :: * -> * -> *) (a2 :: * -> * -> *) wX wY wZ.
a1 wX wZ -> a2 wZ wY -> (:>) a1 a2 wX wY
:> (PatchInfoAndG rt p wX wZ -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wX wZ
x PatchInfo -> p wZ wY -> PatchInfoAndG rt p wZ wY
forall (p :: * -> * -> *) wA wB (rt :: RepoType).
PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
`piap` p wZ wY
x')

instance (PatchId p ~ PatchInfo, CleanMerge p) =>
         CleanMerge (PatchInfoAndG rt p) where
    cleanMerge :: (:\/:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
-> Maybe ((:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY)
cleanMerge (PatchInfoAndG rt p wZ wX
x :\/: PatchInfoAndG rt p wZ wY
y)
      | PatchInfoAndG rt p wZ wX -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wX
x PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfoAndG rt p wZ wY -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wY
y = String
-> Maybe ((:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt 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 (p :: * -> * -> *) wX wY.
CleanMerge p =>
(:\/:) p p wX wY -> Maybe ((:/\:) p p wX wY)
cleanMerge (PatchInfoAndG rt p wZ wX -> p wZ wX
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully PatchInfoAndG rt 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 rt p wZ wY -> p wZ wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully PatchInfoAndG rt p wZ wY
y)
          (:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
-> Maybe ((:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY)
forall (m :: * -> *) a. Monad m => a -> m a
return ((:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
 -> Maybe ((:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY))
-> (:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
-> Maybe ((:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY)
forall a b. (a -> b) -> a -> b
$ (PatchInfoAndG rt p wZ wY -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wY
y PatchInfo -> p wX wZ -> PatchInfoAndG rt p wX wZ
forall (p :: * -> * -> *) wA wB (rt :: RepoType).
PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
`piap` p wX wZ
y') PatchInfoAndG rt p wX wZ
-> PatchInfoAndG rt p wY wZ
-> (:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: (PatchInfoAndG rt p wZ wX -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wX
x PatchInfo -> p wY wZ -> PatchInfoAndG rt p wY wZ
forall (p :: * -> * -> *) wA wB (rt :: RepoType).
PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
`piap` p wY wZ
x')

instance (PatchId p ~ PatchInfo, Merge p) => Merge (PatchInfoAndG rt p) where
    merge :: (:\/:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
-> (:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
merge (PatchInfoAndG rt p wZ wX
x :\/: PatchInfoAndG rt p wZ wY
y)
      | PatchInfoAndG rt p wZ wX -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wX
x PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfoAndG rt p wZ wY -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wY
y = String -> (:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt 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 (p :: * -> * -> *) wX wY.
Merge p =>
(:\/:) p p wX wY -> (:/\:) p p wX wY
merge (PatchInfoAndG rt p wZ wX -> p wZ wX
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully PatchInfoAndG rt 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 rt p wZ wY -> p wZ wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully PatchInfoAndG rt p wZ wY
y) of
            p wX wZ
y' :/\: p wY wZ
x' -> (PatchInfoAndG rt p wZ wY -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wY
y PatchInfo -> p wX wZ -> PatchInfoAndG rt p wX wZ
forall (p :: * -> * -> *) wA wB (rt :: RepoType).
PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
`piap` p wX wZ
y') PatchInfoAndG rt p wX wZ
-> PatchInfoAndG rt p wY wZ
-> (:/\:) (PatchInfoAndG rt p) (PatchInfoAndG rt p) wX wY
forall (a3 :: * -> * -> *) (a4 :: * -> * -> *) wX wY wZ.
a3 wX wZ -> a4 wY wZ -> (:/\:) a3 a4 wX wY
:/\: (PatchInfoAndG rt p wZ wX -> PatchId (PatchInfoAndG rt p)
forall (p :: * -> * -> *) wX wY. Ident p => p wX wY -> PatchId p
ident PatchInfoAndG rt p wZ wX
x PatchInfo -> p wY wZ -> PatchInfoAndG rt p wY wZ
forall (p :: * -> * -> *) wA wB (rt :: RepoType).
PatchInfo -> p wA wB -> PatchInfoAndG rt p wA wB
`piap` p wY wZ
x')

instance PatchInspect p => PatchInspect (PatchInfoAndG rt p) where
    listTouchedFiles :: PatchInfoAndG rt p wX wY -> [AnchoredPath]
listTouchedFiles = p wX wY -> [AnchoredPath]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [AnchoredPath]
listTouchedFiles (p wX wY -> [AnchoredPath])
-> (PatchInfoAndG rt p wX wY -> p wX wY)
-> PatchInfoAndG rt p wX wY
-> [AnchoredPath]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG rt p wX wY -> p wX wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully
    hunkMatches :: (ByteString -> Bool) -> PatchInfoAndG rt p wX wY -> Bool
hunkMatches ByteString -> Bool
f = (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 rt p wX wY -> p wX wY)
-> PatchInfoAndG rt p wX wY
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG rt p wX wY -> p wX wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully

instance Apply p => Apply (PatchInfoAndG rt p) where
    type ApplyState (PatchInfoAndG rt p) = ApplyState p
    apply :: PatchInfoAndG rt p wX wY -> m ()
apply = 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 rt p wX wY -> p wX wY)
-> PatchInfoAndG rt p wX wY
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG rt p wX wY -> p wX wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully
    unapply :: PatchInfoAndG rt p wX wY -> m ()
unapply = 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 rt p wX wY -> p wX wY)
-> PatchInfoAndG rt p wX wY
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
.PatchInfoAndG rt p wX wY -> p wX wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully

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

instance Effect p => Effect (PatchInfoAndG rt p) where
    effect :: PatchInfoAndG rt p wX wY -> FL (PrimOf (PatchInfoAndG rt p)) wX wY
effect = 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 rt p wX wY -> p wX wY)
-> PatchInfoAndG rt p wX wY
-> FL (PrimOf p) wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAndG rt p wX wY -> p wX wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully

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

instance PatchDebug p => PatchDebug (PatchInfoAndG rt p)

instance (Commute p, Conflict p) => Conflict (PatchInfoAnd rt p) where
    -- Note: this relies on the laziness of 'hopefully' for efficiency
    -- and correctness in the face of lazy repositories
    resolveConflicts :: RL (PatchInfoAnd rt p) wO wX
-> RL (PatchInfoAnd rt p) wX wY
-> [ConflictDetails (PrimOf (PatchInfoAnd rt p)) wY]
resolveConflicts RL (PatchInfoAnd rt p) wO wX
context RL (PatchInfoAnd rt p) wX wY
patches =
      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 rt p wW wY -> Named p wW wY)
-> RL (PatchInfoAnd rt 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 forall wW wY. PatchInfoAnd rt p wW wY -> Named p wW wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully RL (PatchInfoAnd rt p) wO wX
context) ((forall wW wY. PatchInfoAnd rt p wW wY -> Named p wW wY)
-> RL (PatchInfoAnd rt 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 forall wW wY. PatchInfoAnd rt p wW wY -> Named p wW wY
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully RL (PatchInfoAnd rt p) wX wY
patches)