{-# LANGUAGE ForeignFunctionInterface #-}
module Darcs.Repository.Job
( RepoJob(..)
, IsPrimV1(..)
, withRepoLock
, withOldRepoLock
, withRepoLockCanFail
, withRepository
, withRepositoryLocation
, checkRepoIsNoRebase
, withUMaskFlag
) where
import Darcs.Prelude
import Darcs.Patch.Apply ( ApplyState )
import Darcs.Patch.V1 ( RepoPatchV1 )
import Darcs.Patch.V2 ( RepoPatchV2 )
import Darcs.Patch.V3 ( RepoPatchV3 )
import qualified Darcs.Patch.V1.Prim as V1 ( Prim(..) )
import qualified Darcs.Patch.V2.Prim as V2 ( Prim(..) )
import Darcs.Patch ( PrimOf )
import Darcs.Patch.Prim.V1 ( Prim )
import Darcs.Patch.RepoPatch ( RepoPatch )
import Darcs.Patch.RepoType
( RepoType(..), SRepoType(..), IsRepoType
, RebaseType(..), SRebaseType(..), IsRebaseType
, singletonRepoType
)
import Darcs.Repository.Flags
( UseCache(..), UpdatePending(..), DryRun(..), UMask (..)
)
import Darcs.Repository.Format
( RepoProperty( Darcs2
, Darcs3
, RebaseInProgress
, RebaseInProgress_2_16
, HashedInventory
)
, formatHas
, writeProblem
)
import Darcs.Repository.Identify ( identifyRepository )
import Darcs.Repository.Hashed( revertRepositoryChanges )
import Darcs.Repository.InternalTypes
( Repository
, repoFormat
, repoLocation
, unsafeCoerceRepoType
, unsafeCoercePatchType
)
import Darcs.Repository.Paths ( lockPath )
import Darcs.Repository.Rebase
( startRebaseJob
, rebaseJob
, maybeDisplaySuspendedStatus
, checkOldStyleRebaseStatus
)
import Darcs.Util.Lock ( withLock, withLockCanFail )
import Darcs.Util.Progress ( debugMessage )
import Control.Monad ( when )
import Control.Exception ( bracket_, finally )
import Data.List ( intercalate )
import Foreign.C.String ( CString, withCString )
import Foreign.C.Error ( throwErrno )
import Foreign.C.Types ( CInt(..) )
import Darcs.Util.Tree ( Tree )
withUMaskFlag :: UMask -> IO a -> IO a
withUMaskFlag :: forall a. UMask -> IO a -> IO a
withUMaskFlag UMask
NoUMask = forall a. a -> a
id
withUMaskFlag (YesUMask String
umask) = forall a. String -> IO a -> IO a
withUMask String
umask
foreign import ccall unsafe "umask.h set_umask" set_umask
:: CString -> IO CInt
foreign import ccall unsafe "umask.h reset_umask" reset_umask
:: CInt -> IO CInt
withUMask :: String
-> IO a
-> IO a
withUMask :: forall a. String -> IO a -> IO a
withUMask String
umask IO a
job =
do CInt
rc <- forall a. String -> (CString -> IO a) -> IO a
withCString String
umask CString -> IO CInt
set_umask
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CInt
rc forall a. Ord a => a -> a -> Bool
< CInt
0) (forall a. String -> IO a
throwErrno String
"Couldn't set umask")
forall a b c. IO a -> IO b -> IO c -> IO c
bracket_
(forall (m :: * -> *) a. Monad m => a -> m a
return ())
(CInt -> IO CInt
reset_umask CInt
rc)
IO a
job
data RepoJob a
=
RepoJob (forall rt p wR wU . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree)
=> Repository rt p wR wU wR -> IO a)
| V1Job (forall wR wU . Repository ('RepoType 'NoRebase) (RepoPatchV1 V1.Prim) wR wU wR -> IO a)
| V2Job (forall rt wR wU . IsRepoType rt => Repository rt (RepoPatchV2 V2.Prim) wR wU wR -> IO a)
| PrimV1Job (forall rt p wR wU . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree, IsPrimV1 (PrimOf p))
=> Repository rt p wR wU wR -> IO a)
| RebaseAwareJob (forall rt p wR wU . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) => Repository rt p wR wU wR -> IO a)
| RebaseJob (forall p wR wU . (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
| OldRebaseJob (forall p wR wU . (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
| StartRebaseJob (forall p wR wU . (RepoPatch p, ApplyState p ~ Tree) => Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
onRepoJob :: RepoJob a
-> (forall rt p wR wU . (RepoPatch p, ApplyState p ~ Tree) => (Repository rt p wR wU wR -> IO a) -> Repository rt p wR wU wR -> IO a)
-> RepoJob a
onRepoJob :: forall a.
RepoJob a
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a)
-> RepoJob a
onRepoJob (RepoJob forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job) forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f = forall a.
(forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a)
-> RepoJob a
RepoJob (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job)
onRepoJob (V1Job forall wR wU.
Repository ('RepoType 'NoRebase) (RepoPatchV1 Prim) wR wU wR
-> IO a
job) forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f = forall a.
(forall wR wU.
Repository ('RepoType 'NoRebase) (RepoPatchV1 Prim) wR wU wR
-> IO a)
-> RepoJob a
V1Job (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f forall wR wU.
Repository ('RepoType 'NoRebase) (RepoPatchV1 Prim) wR wU wR
-> IO a
job)
onRepoJob (V2Job forall (rt :: RepoType) wR wU.
IsRepoType rt =>
Repository rt (RepoPatchV2 Prim) wR wU wR -> IO a
job) forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f = forall a.
(forall (rt :: RepoType) wR wU.
IsRepoType rt =>
Repository rt (RepoPatchV2 Prim) wR wU wR -> IO a)
-> RepoJob a
V2Job (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f forall (rt :: RepoType) wR wU.
IsRepoType rt =>
Repository rt (RepoPatchV2 Prim) wR wU wR -> IO a
job)
onRepoJob (PrimV1Job forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree,
IsPrimV1 (PrimOf p)) =>
Repository rt p wR wU wR -> IO a
job) forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f = forall a.
(forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree,
IsPrimV1 (PrimOf p)) =>
Repository rt p wR wU wR -> IO a)
-> RepoJob a
PrimV1Job (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree,
IsPrimV1 (PrimOf p)) =>
Repository rt p wR wU wR -> IO a
job)
onRepoJob (RebaseAwareJob forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job) forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f = forall a.
(forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a)
-> RepoJob a
RebaseAwareJob (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job)
onRepoJob (RebaseJob forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job) forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f = forall a.
(forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
-> RepoJob a
RebaseJob (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job)
onRepoJob (OldRebaseJob forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job) forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f = forall a.
(forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
-> RepoJob a
OldRebaseJob (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job)
onRepoJob (StartRebaseJob forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job) forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f = forall a.
(forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
-> RepoJob a
StartRebaseJob (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a
f forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job)
withRepository :: UseCache -> RepoJob a -> IO a
withRepository :: forall a. UseCache -> RepoJob a -> IO a
withRepository UseCache
useCache = forall a. UseCache -> String -> RepoJob a -> IO a
withRepositoryLocation UseCache
useCache String
"."
data RepoPatchType p where
RepoV1 :: RepoPatchType (RepoPatchV1 V1.Prim)
RepoV2 :: RepoPatchType (RepoPatchV2 V2.Prim)
RepoV3 :: RepoPatchType (RepoPatchV3 V2.Prim)
data IsTree p where
IsTree :: (ApplyState p ~ Tree) => IsTree p
checkTree :: RepoPatchType p -> IsTree p
checkTree :: forall (p :: * -> * -> *). RepoPatchType p -> IsTree p
checkTree RepoPatchType p
RepoV1 = forall (p :: * -> * -> *). (ApplyState p ~ Tree) => IsTree p
IsTree
checkTree RepoPatchType p
RepoV2 = forall (p :: * -> * -> *). (ApplyState p ~ Tree) => IsTree p
IsTree
checkTree RepoPatchType p
RepoV3 = forall (p :: * -> * -> *). (ApplyState p ~ Tree) => IsTree p
IsTree
class ApplyState p ~ Tree => IsPrimV1 p where
toPrimV1 :: p wX wY -> Prim wX wY
instance IsPrimV1 V1.Prim where
toPrimV1 :: forall wX wY. Prim wX wY -> Prim wX wY
toPrimV1 = forall wX wY. Prim wX wY -> Prim wX wY
V1.unPrim
instance IsPrimV1 V2.Prim where
toPrimV1 :: forall wX wY. Prim wX wY -> Prim wX wY
toPrimV1 = forall wX wY. Prim wX wY -> Prim wX wY
V2.unPrim
data UsesPrimV1 p where
UsesPrimV1 :: (ApplyState p ~ Tree, IsPrimV1 (PrimOf p)) => UsesPrimV1 p
checkPrimV1 :: RepoPatchType p -> UsesPrimV1 p
checkPrimV1 :: forall (p :: * -> * -> *). RepoPatchType p -> UsesPrimV1 p
checkPrimV1 RepoPatchType p
RepoV1 = forall (p :: * -> * -> *).
(ApplyState p ~ Tree, IsPrimV1 (PrimOf p)) =>
UsesPrimV1 p
UsesPrimV1
checkPrimV1 RepoPatchType p
RepoV2 = forall (p :: * -> * -> *).
(ApplyState p ~ Tree, IsPrimV1 (PrimOf p)) =>
UsesPrimV1 p
UsesPrimV1
checkPrimV1 RepoPatchType p
RepoV3 = forall (p :: * -> * -> *).
(ApplyState p ~ Tree, IsPrimV1 (PrimOf p)) =>
UsesPrimV1 p
UsesPrimV1
withRepositoryLocation :: UseCache -> String -> RepoJob a -> IO a
withRepositoryLocation :: forall a. UseCache -> String -> RepoJob a -> IO a
withRepositoryLocation UseCache
useCache String
url RepoJob a
repojob = do
Repository Any Any Any Any Any
repo <- forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
UseCache -> String -> IO (Repository rt p wR wU wT)
identifyRepository UseCache
useCache String
url
let
rf :: RepoFormat
rf = forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
Repository rt p wR wU wT -> RepoFormat
repoFormat Repository Any Any Any Any Any
repo
startRebase :: Bool
startRebase =
case RepoJob a
repojob of
StartRebaseJob {} -> Bool
True
RepoJob a
_ -> Bool
False
runJob1
:: IsRebaseType rebaseType
=> SRebaseType rebaseType -> Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a
runJob1 :: forall (rebaseType :: RebaseType) (rtDummy :: RepoType)
(pDummy :: * -> * -> *) wR wU a.
IsRebaseType rebaseType =>
SRebaseType rebaseType
-> Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a
runJob1 SRebaseType rebaseType
isRebase =
if RepoProperty -> RepoFormat -> Bool
formatHas RepoProperty
Darcs3 RepoFormat
rf
then forall (rt :: RepoType) (p :: * -> * -> *) (rtDummy :: RepoType)
(pDummy :: * -> * -> *) wR wU a.
(IsRepoType rt, RepoPatch p) =>
RepoPatchType p
-> SRepoType rt
-> Repository rtDummy pDummy wR wU wR
-> RepoJob a
-> IO a
runJob RepoPatchType (RepoPatchV3 PrimPatchId Prim)
RepoV3 (forall (rebaseType :: RebaseType).
SRebaseType rebaseType -> SRepoType ('RepoType rebaseType)
SRepoType SRebaseType rebaseType
isRebase)
else
if RepoProperty -> RepoFormat -> Bool
formatHas RepoProperty
Darcs2 RepoFormat
rf
then forall (rt :: RepoType) (p :: * -> * -> *) (rtDummy :: RepoType)
(pDummy :: * -> * -> *) wR wU a.
(IsRepoType rt, RepoPatch p) =>
RepoPatchType p
-> SRepoType rt
-> Repository rtDummy pDummy wR wU wR
-> RepoJob a
-> IO a
runJob RepoPatchType (RepoPatchV2 Prim)
RepoV2 (forall (rebaseType :: RebaseType).
SRebaseType rebaseType -> SRepoType ('RepoType rebaseType)
SRepoType SRebaseType rebaseType
isRebase)
else forall (rt :: RepoType) (p :: * -> * -> *) (rtDummy :: RepoType)
(pDummy :: * -> * -> *) wR wU a.
(IsRepoType rt, RepoPatch p) =>
RepoPatchType p
-> SRepoType rt
-> Repository rtDummy pDummy wR wU wR
-> RepoJob a
-> IO a
runJob RepoPatchType (RepoPatchV1 Prim)
RepoV1 (forall (rebaseType :: RebaseType).
SRebaseType rebaseType -> SRepoType ('RepoType rebaseType)
SRepoType SRebaseType rebaseType
isRebase)
runJob2 :: Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a
runJob2 :: forall (rtDummy :: RepoType) (pDummy :: * -> * -> *) wR wU a.
Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a
runJob2 =
if Bool
startRebase Bool -> Bool -> Bool
||
RepoProperty -> RepoFormat -> Bool
formatHas RepoProperty
RebaseInProgress RepoFormat
rf Bool -> Bool -> Bool
|| RepoProperty -> RepoFormat -> Bool
formatHas RepoProperty
RebaseInProgress_2_16 RepoFormat
rf
then forall (rebaseType :: RebaseType) (rtDummy :: RepoType)
(pDummy :: * -> * -> *) wR wU a.
IsRebaseType rebaseType =>
SRebaseType rebaseType
-> Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a
runJob1 SRebaseType 'IsRebase
SIsRebase
else forall (rebaseType :: RebaseType) (rtDummy :: RepoType)
(pDummy :: * -> * -> *) wR wU a.
IsRebaseType rebaseType =>
SRebaseType rebaseType
-> Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a
runJob1 SRebaseType 'NoRebase
SNoRebase
forall (rtDummy :: RepoType) (pDummy :: * -> * -> *) wR wU a.
Repository rtDummy pDummy wR wU wR -> RepoJob a -> IO a
runJob2 Repository Any Any Any Any Any
repo RepoJob a
repojob
runJob
:: forall rt p rtDummy pDummy wR wU a
. (IsRepoType rt, RepoPatch p)
=> RepoPatchType p
-> SRepoType rt
-> Repository rtDummy pDummy wR wU wR
-> RepoJob a
-> IO a
runJob :: forall (rt :: RepoType) (p :: * -> * -> *) (rtDummy :: RepoType)
(pDummy :: * -> * -> *) wR wU a.
(IsRepoType rt, RepoPatch p) =>
RepoPatchType p
-> SRepoType rt
-> Repository rtDummy pDummy wR wU wR
-> RepoJob a
-> IO a
runJob RepoPatchType p
patchType (SRepoType SRebaseType rebaseType
isRebase) Repository rtDummy pDummy wR wU wR
repo RepoJob a
repojob = do
let
therepo :: Repository rt p wR wU wR
therepo = forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT
(p' :: * -> * -> *).
Repository rt p wR wU wT -> Repository rt p' wR wU wT
unsafeCoercePatchType (forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT
(rt' :: RepoType).
Repository rt p wR wU wT -> Repository rt' p wR wU wT
unsafeCoerceRepoType Repository rtDummy pDummy wR wU wR
repo) :: Repository rt p wR wU wR
patchTypeString :: String
patchTypeString :: String
patchTypeString =
case RepoPatchType p
patchType of
RepoPatchType p
RepoV3 -> String
"darcs-3"
RepoPatchType p
RepoV2 -> String
"darcs-2"
RepoPatchType p
RepoV1 -> String
"darcs-1"
repoAttributes :: [String]
repoAttributes :: [String]
repoAttributes =
case SRebaseType rebaseType
isRebase of
SRebaseType rebaseType
SIsRebase -> [String
"rebase"]
SRebaseType rebaseType
SNoRebase -> []
repoAttributesString :: String
repoAttributesString :: String
repoAttributesString =
case [String]
repoAttributes of
[] -> String
""
[String]
_ -> String
" " forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [[a]] -> [a]
intercalate String
"+" [String]
repoAttributes
String -> IO ()
debugMessage forall a b. (a -> b) -> a -> b
$ String
"Identified " forall a. [a] -> [a] -> [a]
++ String
patchTypeString forall a. [a] -> [a] -> [a]
++ String
repoAttributesString forall a. [a] -> [a] -> [a]
++
String
" repo: " forall a. [a] -> [a] -> [a]
++ forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
Repository rt p wR wU wT -> String
repoLocation Repository rtDummy pDummy wR wU wR
repo
case RepoJob a
repojob of
RepoJob forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job ->
case forall (p :: * -> * -> *). RepoPatchType p -> IsTree p
checkTree RepoPatchType p
patchType of
IsTree p
IsTree -> do
forall (p :: * -> * -> *) (rebaseType :: RebaseType) wR wU.
RepoPatch p =>
SRebaseType rebaseType
-> Repository ('RepoType rebaseType) p wR wU wR -> IO ()
checkOldStyleRebaseStatus SRebaseType rebaseType
isRebase Repository rt p wR wU wR
therepo
forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
therepo
forall a b. IO a -> IO b -> IO a
`finally`
forall (p :: * -> * -> *) (rebaseType :: RebaseType) wR wU.
RepoPatch p =>
SRebaseType rebaseType
-> Repository ('RepoType rebaseType) p wR wU wR -> IO ()
maybeDisplaySuspendedStatus SRebaseType rebaseType
isRebase Repository rt p wR wU wR
therepo
PrimV1Job forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree,
IsPrimV1 (PrimOf p)) =>
Repository rt p wR wU wR -> IO a
job ->
case forall (p :: * -> * -> *). RepoPatchType p -> UsesPrimV1 p
checkPrimV1 RepoPatchType p
patchType of
UsesPrimV1 p
UsesPrimV1 -> do
forall (p :: * -> * -> *) (rebaseType :: RebaseType) wR wU.
RepoPatch p =>
SRebaseType rebaseType
-> Repository ('RepoType rebaseType) p wR wU wR -> IO ()
checkOldStyleRebaseStatus SRebaseType rebaseType
isRebase Repository rt p wR wU wR
therepo
forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree,
IsPrimV1 (PrimOf p)) =>
Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
therepo
forall a b. IO a -> IO b -> IO a
`finally`
forall (p :: * -> * -> *) (rebaseType :: RebaseType) wR wU.
RepoPatch p =>
SRebaseType rebaseType
-> Repository ('RepoType rebaseType) p wR wU wR -> IO ()
maybeDisplaySuspendedStatus SRebaseType rebaseType
isRebase Repository rt p wR wU wR
therepo
V2Job forall (rt :: RepoType) wR wU.
IsRepoType rt =>
Repository rt (RepoPatchV2 Prim) wR wU wR -> IO a
job ->
case (RepoPatchType p
patchType, SRebaseType rebaseType
isRebase) of
(RepoPatchType p
RepoV2, SRebaseType rebaseType
SNoRebase) -> forall (rt :: RepoType) wR wU.
IsRepoType rt =>
Repository rt (RepoPatchV2 Prim) wR wU wR -> IO a
job Repository rt p wR wU wR
therepo
(RepoPatchType p
RepoV2, SRebaseType rebaseType
SIsRebase) ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"This command is not supported while a rebase is in progress."
(RepoPatchType p
RepoV1, SRebaseType rebaseType
_ ) ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"This repository contains darcs v1 patches,"
forall a. [a] -> [a] -> [a]
++ String
" but the command requires darcs v2 patches."
(RepoPatchType p
RepoV3, SRebaseType rebaseType
_ ) ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"This repository contains darcs v3 patches,"
forall a. [a] -> [a] -> [a]
++ String
" but the command requires darcs v2 patches."
V1Job forall wR wU.
Repository ('RepoType 'NoRebase) (RepoPatchV1 Prim) wR wU wR
-> IO a
job ->
case (RepoPatchType p
patchType, SRebaseType rebaseType
isRebase) of
(RepoPatchType p
RepoV1, SRebaseType rebaseType
SNoRebase) -> forall wR wU.
Repository ('RepoType 'NoRebase) (RepoPatchV1 Prim) wR wU wR
-> IO a
job Repository rt p wR wU wR
therepo
(RepoPatchType p
RepoV1, SRebaseType rebaseType
SIsRebase) ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"This command is not supported while a rebase is in progress."
(RepoPatchType p
RepoV2, SRebaseType rebaseType
_ ) ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"This repository contains darcs v2 patches,"
forall a. [a] -> [a] -> [a]
++ String
" but the command requires darcs v1 patches."
(RepoPatchType p
RepoV3, SRebaseType rebaseType
_ ) ->
forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"This repository contains darcs v3 patches,"
forall a. [a] -> [a] -> [a]
++ String
" but the command requires darcs v1 patches."
RebaseAwareJob forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job ->
case (forall (p :: * -> * -> *). RepoPatchType p -> IsTree p
checkTree RepoPatchType p
patchType, SRebaseType rebaseType
isRebase) of
(IsTree p
IsTree, SRebaseType rebaseType
SNoRebase) -> forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
therepo
(IsTree p
IsTree, SRebaseType rebaseType
SIsRebase) -> do
forall (p :: * -> * -> *) (rebaseType :: RebaseType) wR wU.
RepoPatch p =>
SRebaseType rebaseType
-> Repository ('RepoType rebaseType) p wR wU wR -> IO ()
checkOldStyleRebaseStatus SRebaseType rebaseType
isRebase Repository rt p wR wU wR
therepo
forall (p :: * -> * -> *) wR wU a.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
-> Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
rebaseJob forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
therepo
RebaseJob forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job ->
case (forall (p :: * -> * -> *). RepoPatchType p -> IsTree p
checkTree RepoPatchType p
patchType, SRebaseType rebaseType
isRebase) of
(IsTree p
_ , SRebaseType rebaseType
SNoRebase) -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"No rebase in progress. Try 'darcs rebase suspend' first."
(IsTree p
IsTree, SRebaseType rebaseType
SIsRebase) -> do
forall (p :: * -> * -> *) (rebaseType :: RebaseType) wR wU.
RepoPatch p =>
SRebaseType rebaseType
-> Repository ('RepoType rebaseType) p wR wU wR -> IO ()
checkOldStyleRebaseStatus SRebaseType rebaseType
isRebase Repository rt p wR wU wR
therepo
forall (p :: * -> * -> *) wR wU a.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
-> Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
rebaseJob forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job Repository rt p wR wU wR
therepo
OldRebaseJob forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job ->
case (forall (p :: * -> * -> *). RepoPatchType p -> IsTree p
checkTree RepoPatchType p
patchType, SRebaseType rebaseType
isRebase) of
(IsTree p
_ , SRebaseType rebaseType
SNoRebase) -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"No rebase in progress."
(IsTree p
IsTree, SRebaseType rebaseType
SIsRebase) -> do
forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job Repository rt p wR wU wR
therepo
forall a b. IO a -> IO b -> IO a
`finally`
forall (p :: * -> * -> *) (rebaseType :: RebaseType) wR wU.
RepoPatch p =>
SRebaseType rebaseType
-> Repository ('RepoType rebaseType) p wR wU wR -> IO ()
maybeDisplaySuspendedStatus SRebaseType rebaseType
isRebase Repository rt p wR wU wR
therepo
StartRebaseJob forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job ->
case (forall (p :: * -> * -> *). RepoPatchType p -> IsTree p
checkTree RepoPatchType p
patchType, SRebaseType rebaseType
isRebase) of
(IsTree p
_ , SRebaseType rebaseType
SNoRebase) -> forall a. HasCallStack => String -> a
error String
"impossible case"
(IsTree p
IsTree, SRebaseType rebaseType
SIsRebase) -> do
forall (p :: * -> * -> *) wR wU a.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository ('RepoType 'IsRebase) p wR wU wR -> IO a)
-> Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
startRebaseJob forall (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository ('RepoType 'IsRebase) p wR wU wR -> IO a
job Repository rt p wR wU wR
therepo
withRepoLock :: DryRun -> UseCache -> UpdatePending -> UMask -> RepoJob a -> IO a
withRepoLock :: forall a.
DryRun -> UseCache -> UpdatePending -> UMask -> RepoJob a -> IO a
withRepoLock DryRun
YesDryRun UseCache
useCache UpdatePending
_ UMask
_ RepoJob a
repojob =
forall a. UseCache -> RepoJob a -> IO a
withRepository UseCache
useCache forall a b. (a -> b) -> a -> b
$ forall a.
RepoJob a
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a)
-> RepoJob a
onRepoJob RepoJob a
repojob forall a b. (a -> b) -> a -> b
$ \Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
repository -> Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
repository
withRepoLock DryRun
NoDryRun UseCache
useCache UpdatePending
upe UMask
um RepoJob a
repojob =
forall a. String -> IO a -> IO a
withLock String
lockPath forall a b. (a -> b) -> a -> b
$
forall a. UseCache -> RepoJob a -> IO a
withRepository UseCache
useCache forall a b. (a -> b) -> a -> b
$ forall a.
RepoJob a
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a)
-> RepoJob a
onRepoJob RepoJob a
repojob forall a b. (a -> b) -> a -> b
$ \Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
repository -> do
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ RepoFormat -> Maybe String
writeProblem (forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
Repository rt p wR wU wT -> RepoFormat
repoFormat Repository rt p wR wU wR
repository)
forall a. UMask -> IO a -> IO a
withUMaskFlag UMask
um forall a b. (a -> b) -> a -> b
$ forall (p :: * -> * -> *) (rt :: RepoType) wR wU wT.
RepoPatch p =>
Repository rt p wR wU wT
-> UpdatePending -> IO (Repository rt p wR wU wR)
revertRepositoryChanges Repository rt p wR wU wR
repository UpdatePending
upe forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Repository rt p wR wU wR -> IO a
job
withOldRepoLock :: RepoJob a -> IO a
withOldRepoLock :: forall a. RepoJob a -> IO a
withOldRepoLock RepoJob a
repojob =
forall a. UseCache -> RepoJob a -> IO a
withRepository UseCache
NoUseCache forall a b. (a -> b) -> a -> b
$ forall a.
RepoJob a
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a)
-> RepoJob a
onRepoJob RepoJob a
repojob forall a b. (a -> b) -> a -> b
$ \Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
repository ->
forall a. String -> IO a -> IO a
withLock String
lockPath forall a b. (a -> b) -> a -> b
$ Repository rt p wR wU wR -> IO a
job Repository rt p wR wU wR
repository
withRepoLockCanFail :: UseCache -> RepoJob () -> IO ()
withRepoLockCanFail :: UseCache -> RepoJob () -> IO ()
withRepoLockCanFail UseCache
useCache RepoJob ()
repojob = do
Either () ()
eitherDone <-
forall a. String -> IO a -> IO (Either () a)
withLockCanFail String
lockPath forall a b. (a -> b) -> a -> b
$
forall a. UseCache -> RepoJob a -> IO a
withRepository UseCache
useCache forall a b. (a -> b) -> a -> b
$ forall a.
RepoJob a
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(Repository rt p wR wU wR -> IO a)
-> Repository rt p wR wU wR -> IO a)
-> RepoJob a
onRepoJob RepoJob ()
repojob forall a b. (a -> b) -> a -> b
$ \Repository rt p wR wU wR -> IO ()
job Repository rt p wR wU wR
repository -> do
let rf :: RepoFormat
rf = forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
Repository rt p wR wU wT -> RepoFormat
repoFormat Repository rt p wR wU wR
repository
if RepoProperty -> RepoFormat -> Bool
formatHas RepoProperty
HashedInventory RepoFormat
rf then do
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ RepoFormat -> Maybe String
writeProblem RepoFormat
rf
Repository rt p wR wU wR -> IO ()
job Repository rt p wR wU wR
repository
else
String -> IO ()
debugMessage
String
"Not doing the job because this is an old-fashioned repository."
case Either () ()
eitherDone of
Left ()
_ -> String -> IO ()
debugMessage String
"Lock could not be obtained, not doing the job."
Right ()
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkRepoIsNoRebase :: forall rt p wR wU wT. IsRepoType rt
=> Repository rt p wR wU wT
-> Maybe (Repository ('RepoType 'NoRebase) p wR wU wT)
checkRepoIsNoRebase :: forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
IsRepoType rt =>
Repository rt p wR wU wT
-> Maybe (Repository ('RepoType 'NoRebase) p wR wU wT)
checkRepoIsNoRebase Repository rt p wR wU wT
repo =
case forall (rt :: RepoType). IsRepoType rt => SRepoType rt
singletonRepoType :: SRepoType rt of
SRepoType SRebaseType rebaseType
SNoRebase -> forall a. a -> Maybe a
Just Repository rt p wR wU wT
repo
SRepoType SRebaseType rebaseType
SIsRebase -> forall a. Maybe a
Nothing