--  Copyright (C) 2003-2005 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.UI.Commands.Apply
    ( apply, applyCmd
    , getPatchBundle -- used by darcsden
    ) where

import Prelude ()
import Darcs.Prelude

import System.Exit ( exitSuccess )
import Control.Monad ( when )

import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, hopefullyM, info )
import Darcs.UI.Commands
    ( DarcsCommand(..), withStdOpts
    , putVerbose
    , amInHashedRepository
    )
import Darcs.UI.Completion ( fileArgs )
import Darcs.UI.Flags
    ( DarcsFlag
    , happyForwarding, changesReverse, verbosity, useCache, dryRun
    , reorder, umask
    , fixUrl, getCc, getSendmailCmd
    , withContext, reply
    )
import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) )
import qualified Darcs.UI.Options.All as O
import Darcs.Repository.Flags ( UpdateWorking(..) )
import Darcs.Util.Path ( toFilePath, AbsolutePath )
import Darcs.Repository
    ( Repository
    , SealedPatchSet
    , withRepoLock
    , readRepo
    , filterOutConflicts
    )
import Darcs.Patch.Set ( Origin, patchSet2RL )
import Darcs.Patch ( IsRepoType, RepoPatch )
import Darcs.Patch.Apply( ApplyState )
import Darcs.Patch.Info ( PatchInfo, displayPatchInfo )
import Darcs.Patch.Witnesses.Ordered
    ( RL(..), (:\/:)(..), (:>)(..)
    , mapRL, nullFL, reverseFL )
import Darcs.Patch.Witnesses.Sealed ( Sealed(Sealed) )
import Darcs.Util.ByteString ( linesPS, unlinesPS, gzReadStdin )
import Data.List( (\\) )
import qualified Data.ByteString as B (ByteString, null, init, take, drop)
import qualified Data.ByteString.Char8 as BC (unpack, last, pack)

import Darcs.Util.Download ( Cachable(Uncachable) )
import Darcs.Util.External ( gzFetchFilePS )
import Darcs.UI.External
    ( sendEmailDoc
    , resendEmail
    , verifyPS
    )
import Darcs.UI.Email ( readEmail )
import Darcs.Patch.Depends ( findUncommon, findCommonWithThem )
import Darcs.UI.ApplyPatches ( PatchApplier(..), StandardPatchApplier(..), PatchProxy )
import Darcs.UI.SelectChanges
    ( WhichChanges(..)
    , runSelection
    , selectionContext
    )
import qualified Darcs.UI.SelectChanges as S
import Darcs.Patch.Bundle ( scanBundle )
import Darcs.Util.Printer
    ( packedString, vcat, text, empty
    , renderString
    )
import Darcs.Util.Tree( Tree )

applyDescription :: String
applyDescription :: String
applyDescription = "Apply a patch bundle created by `darcs send'."

applyHelp :: String
applyHelp :: String
applyHelp = [String] -> String
unlines
 [ "The `darcs apply` command takes a patch bundle and attempts to insert"
 , "it into the current repository.  In addition to invoking it directly"
 , "on bundles created by `darcs send`, it is used internally by `darcs"
 , "push` on the remote end of an SSH connection."
 , ""
 , "If no file is supplied, the bundle is read from standard input."
 , ""
 , "If given an email instead of a patch bundle, Darcs will look for the"
 , "bundle as a MIME attachment to that email.  Currently this will fail"
 , "if the MIME boundary is rewritten, such as in Courier and Mail.app."
 , ""
 , "If the `--reply noreply@example.net` option is used, and the bundle is"
 , "attached to an email, Darcs will send a report (indicating success or"
 , "failure) to the sender of the bundle (the `To` field).  The argument to"
 , "noreply is the address the report will appear to originate FROM."
 , ""
 , "The `--cc` option will cause the report to be CC'd to another address,"
 , "for example `--cc reports@lists.example.net,admin@lists.example.net`."
 , "Using `--cc` without `--reply` is undefined."
 , ""
 , "If you want to use a command different from the default one for sending mail,"
 , "you need to specify a command line with the `--sendmail-command` option."
 , "The command line can contain the format specifier `%t` for to"
 , "and you can add `%<` to the end of the command line if the command"
 , "expects the complete mail on standard input. For example, the command line"
 , "for msmtp looks like this:"
 , ""
 , "    msmtp -t %<"
 , ""
 , "If gpg(1) is installed, you can use `--verify pubring.gpg` to reject"
 , "bundles that aren't signed by a key in `pubring.gpg`."
 , ""
 , "If `--test` is supplied and a test is defined (see `darcs setpref`), the"
 , "bundle will be rejected if the test fails after applying it.  In that"
 , "case, the rejection email from `--reply` will include the test output."
 ]

stdindefault :: a -> [String] -> IO [String]
stdindefault :: a -> [String] -> IO [String]
stdindefault _ [] = [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return ["-"]
stdindefault _ x :: [String]
x = [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return [String]
x

apply :: DarcsCommand [DarcsFlag]
apply :: DarcsCommand [DarcsFlag]
apply = DarcsCommand :: forall parsedFlags.
String
-> String
-> String
-> String
-> Int
-> [String]
-> ((AbsolutePath, AbsolutePath)
    -> parsedFlags -> [String] -> IO ())
-> ([DarcsFlag] -> IO (Either String ()))
-> ((AbsolutePath, AbsolutePath)
    -> [DarcsFlag] -> [String] -> IO [String])
-> ([DarcsFlag] -> AbsolutePath -> [String] -> IO [String])
-> [DarcsOptDescr DarcsFlag]
-> [DarcsOptDescr DarcsFlag]
-> [DarcsFlag]
-> ([DarcsFlag] -> [String])
-> ([DarcsFlag] -> parsedFlags)
-> DarcsCommand parsedFlags
DarcsCommand
    { commandProgramName :: String
commandProgramName = "darcs"
    , commandName :: String
commandName = "apply"
    , commandHelp :: String
commandHelp = String
applyHelp String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
applyHelp'
    , commandDescription :: String
commandDescription = String
applyDescription
    , commandExtraArgs :: Int
commandExtraArgs = 1
    , commandExtraArgHelp :: [String]
commandExtraArgHelp = ["<PATCHFILE>"]
    , commandCommand :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
commandCommand = StandardPatchApplier
-> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
forall pa.
PatchApplier pa =>
pa
-> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
applyCmd StandardPatchApplier
StandardPatchApplier
    , commandPrereq :: [DarcsFlag] -> IO (Either String ())
commandPrereq = [DarcsFlag] -> IO (Either String ())
amInHashedRepository
    , commandCompleteArgs :: (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
commandCompleteArgs = (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
fileArgs
    , commandArgdefaults :: [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
commandArgdefaults = (AbsolutePath -> [String] -> IO [String])
-> [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
forall a b. a -> b -> a
const AbsolutePath -> [String] -> IO [String]
forall a. a -> [String] -> IO [String]
stdindefault
    , commandAdvancedOptions :: [DarcsOptDescr DarcsFlag]
commandAdvancedOptions = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> Any)
-> [DarcsOptDescr DarcsFlag]
forall (d :: * -> *) f a b. OptSpec d f a b -> [d f]
odesc OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> Any)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
applyAdvancedOpts
    , commandBasicOptions :: [DarcsOptDescr DarcsFlag]
commandBasicOptions = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Any)
-> [DarcsOptDescr DarcsFlag]
forall (d :: * -> *) f a b. OptSpec d f a b -> [d f]
odesc OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Any)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
applyBasicOpts
    , commandDefaults :: [DarcsFlag]
commandDefaults = OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> [DarcsFlag])
-> [DarcsFlag]
forall (d :: * -> *) f b. OptSpec d f [f] b -> [f]
defaultFlags OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> [DarcsFlag])
forall a.
DarcsOption
  a
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
applyOpts
    , commandCheckOptions :: [DarcsFlag] -> [String]
commandCheckOptions = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> Any)
-> [DarcsFlag] -> [String]
forall (d :: * -> *) f a b. OptSpec d f a b -> [f] -> [String]
ocheck OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> Any)
forall a.
DarcsOption
  a
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
applyOpts
    , commandParseOptions :: [DarcsFlag] -> [DarcsFlag]
commandParseOptions = OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> [DarcsFlag])
-> [DarcsFlag] -> [DarcsFlag]
forall (d :: * -> *) f b. OptSpec d f [f] b -> [f] -> [f]
onormalise OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> [DarcsFlag])
forall a.
DarcsOption
  a
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
applyOpts
    }
  where
    applyBasicOpts :: OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
applyBasicOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  Verify
PrimDarcsOption Verify
O.verify
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  Verify
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption Reorder
O.reorder
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe Bool)
O.interactive
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     ([MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     ([MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  ([MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
forall a. DarcsOption a (DryRun -> XmlOutput -> a)
O.dryRunXml
      OptSpec
  DarcsOptDescr
  DarcsFlag
  ([MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
MatchOption
O.matchSeveral
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (ExternalMerge
      -> RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
     (Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (ExternalMerge
      -> RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (ExternalMerge
   -> RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
  (Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe AllowConflicts)
O.conflictsNo
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (ExternalMerge
   -> RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
     (ExternalMerge
      -> RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
  (ExternalMerge
   -> RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
PrimDarcsOption ExternalMerge
O.externalMerge
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
     (RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
  (RunTest -> LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
PrimDarcsOption RunTest
O.runTest
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> DiffAlgorithm -> a)
     (LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> DiffAlgorithm -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String -> DiffAlgorithm -> a)
  (LeaveTestDir -> Maybe String -> DiffAlgorithm -> a)
PrimDarcsOption LeaveTestDir
O.leaveTestDir
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String -> DiffAlgorithm -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     (Maybe String -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (DiffAlgorithm -> a)
  (Maybe String -> DiffAlgorithm -> a)
PrimDarcsOption (Maybe String)
O.repoDir
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (DiffAlgorithm -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     a
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec DarcsOptDescr DarcsFlag a (DiffAlgorithm -> a)
PrimDarcsOption DiffAlgorithm
O.diffAlgorithm
    applyAdvancedOpts :: OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
applyAdvancedOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (Maybe String)
PrimDarcsOption (Maybe String)
O.reply
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (Maybe String)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
     (Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
PrimDarcsOption (Maybe String)
O.ccApply
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     ((Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
     (Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     ((Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  ((Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
PrimDarcsOption Bool
O.happyForwarding
      OptSpec
  DarcsOptDescr
  DarcsFlag
  ((Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
     ((Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  ((Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
PrimDarcsOption (Bool, Maybe String)
O.sendmail
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
     (UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
PrimDarcsOption UseIndex
O.useIndex
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (SetScriptsExecutable
      -> UMask -> Bool -> Bool -> WantGuiPause -> a)
     (Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (SetScriptsExecutable
      -> UMask -> Bool -> Bool -> WantGuiPause -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (SetScriptsExecutable
   -> UMask -> Bool -> Bool -> WantGuiPause -> a)
  (Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
PrimDarcsOption Compression
O.compress
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (SetScriptsExecutable
   -> UMask -> Bool -> Bool -> WantGuiPause -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UMask -> Bool -> Bool -> WantGuiPause -> a)
     (SetScriptsExecutable
      -> UMask -> Bool -> Bool -> WantGuiPause -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UMask -> Bool -> Bool -> WantGuiPause -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (UMask -> Bool -> Bool -> WantGuiPause -> a)
  (SetScriptsExecutable
   -> UMask -> Bool -> Bool -> WantGuiPause -> a)
PrimDarcsOption SetScriptsExecutable
O.setScriptsExecutable
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (UMask -> Bool -> Bool -> WantGuiPause -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> Bool -> WantGuiPause -> a)
     (UMask -> Bool -> Bool -> WantGuiPause -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> Bool -> WantGuiPause -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> Bool -> WantGuiPause -> a)
  (UMask -> Bool -> Bool -> WantGuiPause -> a)
PrimDarcsOption UMask
O.umask
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> Bool -> WantGuiPause -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> WantGuiPause -> a)
     (Bool -> Bool -> WantGuiPause -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> WantGuiPause -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> WantGuiPause -> a)
  (Bool -> Bool -> WantGuiPause -> a)
PrimDarcsOption Bool
O.restrictPaths
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> WantGuiPause -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WantGuiPause -> a)
     (Bool -> WantGuiPause -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WantGuiPause -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (WantGuiPause -> a)
  (Bool -> WantGuiPause -> a)
PrimDarcsOption Bool
O.changesReverse
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (WantGuiPause -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (WantGuiPause -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     a
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec DarcsOptDescr DarcsFlag a (WantGuiPause -> a)
PrimDarcsOption WantGuiPause
O.pauseForGui
    applyOpts :: DarcsOption
  a
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
applyOpts = OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> a)
applyBasicOpts OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
  (Verify
   -> Reorder
   -> Maybe Bool
   -> DryRun
   -> XmlOutput
   -> [MatchFlag]
   -> Maybe AllowConflicts
   -> ExternalMerge
   -> RunTest
   -> LeaveTestDir
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
-> DarcsOption
     (UseCache -> HooksConfig -> a)
     (Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> UseCache
      -> HooksConfig
      -> a)
-> DarcsOption
     a
     (Verify
      -> Reorder
      -> Maybe Bool
      -> DryRun
      -> XmlOutput
      -> [MatchFlag]
      -> Maybe AllowConflicts
      -> ExternalMerge
      -> RunTest
      -> LeaveTestDir
      -> Maybe String
      -> DiffAlgorithm
      -> Maybe StdCmdAction
      -> Bool
      -> Bool
      -> Verbosity
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Bool
      -> (Bool, Maybe String)
      -> UseIndex
      -> Compression
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> Bool
      -> WantGuiPause
      -> UseCache
      -> HooksConfig
      -> a)
forall b c a.
DarcsOption
  (Maybe StdCmdAction -> Bool -> Bool -> Verbosity -> Bool -> b) c
-> DarcsOption (UseCache -> HooksConfig -> a) b -> DarcsOption a c
`withStdOpts` DarcsOption
  (UseCache -> HooksConfig -> a)
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> UseCache
   -> HooksConfig
   -> a)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Maybe String
   -> Maybe String
   -> Bool
   -> (Bool, Maybe String)
   -> UseIndex
   -> Compression
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> Bool
   -> WantGuiPause
   -> a)
applyAdvancedOpts

applyCmd :: PatchApplier pa => pa -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
applyCmd :: pa
-> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
applyCmd _ _ _ [""] = String -> IO ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail "Empty filename argument given to apply!"
applyCmd patchApplier :: pa
patchApplier _ opts :: [DarcsFlag]
opts ["-"] =
  DryRun -> UseCache -> UpdateWorking -> UMask -> RepoJob () -> IO ()
forall a.
DryRun -> UseCache -> UpdateWorking -> UMask -> RepoJob a -> IO a
withRepoLock (PrimDarcsOption DryRun
dryRun PrimDarcsOption DryRun -> [DarcsFlag] -> DryRun
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) (PrimDarcsOption UseCache
useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) UpdateWorking
YesUpdateWorking (PrimDarcsOption UMask
umask PrimDarcsOption UMask -> [DarcsFlag] -> UMask
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) (RepoJob () -> IO ()) -> RepoJob () -> IO ()
forall a b. (a -> b) -> a -> b
$
  pa
-> [DarcsFlag]
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, ApplierRepoTypeConstraint pa rt, RepoPatch p,
     ApplyState p ~ Tree) =>
    PatchProxy p -> Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall pa.
PatchApplier pa =>
pa
-> [DarcsFlag]
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, ApplierRepoTypeConstraint pa rt, RepoPatch p,
     ApplyState p ~ Tree) =>
    PatchProxy p -> Repository rt p wR wU wR -> IO ())
-> RepoJob ()
repoJob pa
patchApplier [DarcsFlag]
opts ((forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
  (IsRepoType rt, ApplierRepoTypeConstraint pa rt, RepoPatch p,
   ApplyState p ~ Tree) =>
  PatchProxy p -> Repository rt p wR wU wR -> IO ())
 -> RepoJob ())
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, ApplierRepoTypeConstraint pa rt, RepoPatch p,
     ApplyState p ~ Tree) =>
    PatchProxy p -> Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a b. (a -> b) -> a -> b
$ \patchProxy :: PatchProxy p
patchProxy repository :: Repository rt p wR wU wR
repository -> do
    -- for darcs users who try out 'darcs apply' without any arguments
    [DarcsFlag] -> Doc -> IO ()
putVerbose [DarcsFlag]
opts (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> Doc
text "reading patch bundle from stdin..."
    ByteString
bundle <- IO ByteString
gzReadStdin
    pa
-> PatchProxy p
-> [DarcsFlag]
-> ByteString
-> Repository rt p wR wU wR
-> IO ()
forall (rt :: RepoType) pa (p :: * -> * -> *) wR wU.
(PatchApplier pa, RepoPatch p, ApplyState p ~ Tree,
 ApplierRepoTypeConstraint pa rt, IsRepoType rt) =>
pa
-> PatchProxy p
-> [DarcsFlag]
-> ByteString
-> Repository rt p wR wU wR
-> IO ()
applyCmdCommon pa
patchApplier PatchProxy p
patchProxy [DarcsFlag]
opts ByteString
bundle Repository rt p wR wU wR
repository

applyCmd patchApplier :: pa
patchApplier (_,o :: AbsolutePath
o) opts :: [DarcsFlag]
opts [unfixed_patchesfile :: String
unfixed_patchesfile] =
  DryRun -> UseCache -> UpdateWorking -> UMask -> RepoJob () -> IO ()
forall a.
DryRun -> UseCache -> UpdateWorking -> UMask -> RepoJob a -> IO a
withRepoLock (PrimDarcsOption DryRun
dryRun PrimDarcsOption DryRun -> [DarcsFlag] -> DryRun
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) (PrimDarcsOption UseCache
useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) UpdateWorking
YesUpdateWorking (PrimDarcsOption UMask
umask PrimDarcsOption UMask -> [DarcsFlag] -> UMask
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) (RepoJob () -> IO ()) -> RepoJob () -> IO ()
forall a b. (a -> b) -> a -> b
$
  pa
-> [DarcsFlag]
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, ApplierRepoTypeConstraint pa rt, RepoPatch p,
     ApplyState p ~ Tree) =>
    PatchProxy p -> Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall pa.
PatchApplier pa =>
pa
-> [DarcsFlag]
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, ApplierRepoTypeConstraint pa rt, RepoPatch p,
     ApplyState p ~ Tree) =>
    PatchProxy p -> Repository rt p wR wU wR -> IO ())
-> RepoJob ()
repoJob pa
patchApplier [DarcsFlag]
opts ((forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
  (IsRepoType rt, ApplierRepoTypeConstraint pa rt, RepoPatch p,
   ApplyState p ~ Tree) =>
  PatchProxy p -> Repository rt p wR wU wR -> IO ())
 -> RepoJob ())
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, ApplierRepoTypeConstraint pa rt, RepoPatch p,
     ApplyState p ~ Tree) =>
    PatchProxy p -> Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a b. (a -> b) -> a -> b
$ \patchProxy :: PatchProxy p
patchProxy repository :: Repository rt p wR wU wR
repository -> do
    String
patchesfile <- AbsolutePath -> String -> IO String
fixUrl AbsolutePath
o String
unfixed_patchesfile
    ByteString
bundle <- String -> Cachable -> IO ByteString
gzFetchFilePS (String -> String
forall a. FilePathLike a => a -> String
toFilePath String
patchesfile) Cachable
Uncachable
    pa
-> PatchProxy p
-> [DarcsFlag]
-> ByteString
-> Repository rt p wR wU wR
-> IO ()
forall (rt :: RepoType) pa (p :: * -> * -> *) wR wU.
(PatchApplier pa, RepoPatch p, ApplyState p ~ Tree,
 ApplierRepoTypeConstraint pa rt, IsRepoType rt) =>
pa
-> PatchProxy p
-> [DarcsFlag]
-> ByteString
-> Repository rt p wR wU wR
-> IO ()
applyCmdCommon pa
patchApplier PatchProxy p
patchProxy [DarcsFlag]
opts ByteString
bundle Repository rt p wR wU wR
repository

applyCmd _ _ _ _ = IO ()
forall a. a
impossible

applyCmdCommon
    :: forall rt pa p wR wU
     . ( PatchApplier pa, RepoPatch p, ApplyState p ~ Tree
       , ApplierRepoTypeConstraint pa rt, IsRepoType rt
       )
    => pa
    -> PatchProxy p
    -> [DarcsFlag]
    -> B.ByteString
    -> Repository rt p wR wU wR
    -> IO ()
applyCmdCommon :: pa
-> PatchProxy p
-> [DarcsFlag]
-> ByteString
-> Repository rt p wR wU wR
-> IO ()
applyCmdCommon patchApplier :: pa
patchApplier patchProxy :: PatchProxy p
patchProxy opts :: [DarcsFlag]
opts bundle :: ByteString
bundle repository :: Repository rt p wR wU wR
repository = do
  let from_whom :: String
from_whom = ByteString -> String
getFrom ByteString
bundle
  PatchSet rt p Origin wR
us <- Repository rt p wR wU wR -> IO (PatchSet rt p Origin wR)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p) =>
Repository rt p wR wU wT -> IO (PatchSet rt p Origin wR)
readRepo Repository rt p wR wU wR
repository
  Either String (SealedPatchSet rt p Origin)
either_them <- [DarcsFlag]
-> ByteString -> IO (Either String (SealedPatchSet rt p Origin))
forall (p :: * -> * -> *) (rt :: RepoType).
RepoPatch p =>
[DarcsFlag]
-> ByteString -> IO (Either String (SealedPatchSet rt p Origin))
getPatchBundle [DarcsFlag]
opts ByteString
bundle
  Sealed them :: PatchSet rt p Origin wX
them
     <- case Either String (SealedPatchSet rt p Origin)
either_them of
          Right t :: SealedPatchSet rt p Origin
t -> SealedPatchSet rt p Origin -> IO (SealedPatchSet rt p Origin)
forall (m :: * -> *) a. Monad m => a -> m a
return SealedPatchSet rt p Origin
t
          Left er :: String
er -> do Bool
forwarded <- [DarcsFlag] -> ByteString -> IO Bool
considerForwarding [DarcsFlag]
opts ByteString
bundle
                        if Bool
forwarded
                          then IO (SealedPatchSet rt p Origin)
forall a. IO a
exitSuccess
                          else String -> IO (SealedPatchSet rt p Origin)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
er
  common :: PatchSet rt p Origin wZ
common :> _ <- (:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) Origin wR
-> IO ((:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) Origin wR)
forall (m :: * -> *) a. Monad m => a -> m a
return ((:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) Origin wR
 -> IO ((:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) Origin wR))
-> (:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) Origin wR
-> IO ((:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) Origin wR)
forall a b. (a -> b) -> a -> b
$ PatchSet rt p Origin wR
-> PatchSet rt p Origin wX
-> (:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) Origin wR
forall (p :: * -> * -> *) (rt :: RepoType) wStart wX wY.
Commute p =>
PatchSet rt p wStart wX
-> PatchSet rt p wStart wY
-> (:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) wStart wX
findCommonWithThem PatchSet rt p Origin wR
us PatchSet rt p Origin wX
them

  -- all patches that are in "them" and not in "common" need to be available; check that
  let common_i :: [PatchInfo]
common_i = (forall wW wZ. PatchInfoAnd rt p wW wZ -> PatchInfo)
-> RL (PatchInfoAnd rt p) Origin wZ -> [PatchInfo]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> RL a wX wY -> [b]
mapRL forall wW wZ. PatchInfoAnd rt p wW wZ -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info (RL (PatchInfoAnd rt p) Origin wZ -> [PatchInfo])
-> RL (PatchInfoAnd rt p) Origin wZ -> [PatchInfo]
forall a b. (a -> b) -> a -> b
$ PatchSet rt p Origin wZ -> RL (PatchInfoAnd rt p) Origin wZ
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
PatchSet rt p wStart wX -> RL (PatchInfoAnd rt p) wStart wX
patchSet2RL PatchSet rt p Origin wZ
common
      them_i :: [PatchInfo]
them_i = (forall wW wZ. PatchInfoAnd rt p wW wZ -> PatchInfo)
-> RL (PatchInfoAnd rt p) Origin wX -> [PatchInfo]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> RL a wX wY -> [b]
mapRL forall wW wZ. PatchInfoAnd rt p wW wZ -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info (RL (PatchInfoAnd rt p) Origin wX -> [PatchInfo])
-> RL (PatchInfoAnd rt p) Origin wX -> [PatchInfo]
forall a b. (a -> b) -> a -> b
$ PatchSet rt p Origin wX -> RL (PatchInfoAnd rt p) Origin wX
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
PatchSet rt p wStart wX -> RL (PatchInfoAnd rt p) wStart wX
patchSet2RL PatchSet rt p Origin wX
them
      required :: [PatchInfo]
required = [PatchInfo]
them_i [PatchInfo] -> [PatchInfo] -> [PatchInfo]
forall a. Eq a => [a] -> [a] -> [a]
\\ [PatchInfo]
common_i -- FIXME quadratic?
      check :: RL (PatchInfoAnd rt p) wX wY -> [PatchInfo] -> IO ()
      check :: RL (PatchInfoAnd rt p) wX wY -> [PatchInfo] -> IO ()
check (ps' :: RL (PatchInfoAnd rt p) wX wY
ps' :<: p :: PatchInfoAnd rt p wY wY
p) bad :: [PatchInfo]
bad = case PatchInfoAnd rt p wY wY -> Maybe (WrappedNamed rt p wY wY)
forall (m :: * -> *) (rt :: RepoType) (p :: * -> * -> *) wA wB.
MonadFail m =>
PatchInfoAnd rt p wA wB -> m (WrappedNamed rt p wA wB)
hopefullyM PatchInfoAnd rt p wY wY
p of
        Nothing | PatchInfoAnd rt p wY wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wY wY
p PatchInfo -> [PatchInfo] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [PatchInfo]
required -> RL (PatchInfoAnd rt p) wX wY -> [PatchInfo] -> IO ()
forall wX wY. RL (PatchInfoAnd rt p) wX wY -> [PatchInfo] -> IO ()
check RL (PatchInfoAnd rt p) wX wY
ps' (PatchInfoAnd rt p wY wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wY wY
p PatchInfo -> [PatchInfo] -> [PatchInfo]
forall a. a -> [a] -> [a]
: [PatchInfo]
bad)
        _ -> RL (PatchInfoAnd rt p) wX wY -> [PatchInfo] -> IO ()
forall wX wY. RL (PatchInfoAnd rt p) wX wY -> [PatchInfo] -> IO ()
check RL (PatchInfoAnd rt p) wX wY
ps' [PatchInfo]
bad
      check NilRL [] = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      check NilRL bad :: [PatchInfo]
bad = String -> IO ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO ()) -> (Doc -> String) -> Doc -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> String
renderString (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (PatchInfo -> Doc) -> [PatchInfo] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map PatchInfo -> Doc
displayPatchInfo [PatchInfo]
bad [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++
                        [ String -> Doc
text "\nFATAL: Cannot apply this bundle. We are missing the above patches." ]

  RL (PatchInfoAnd rt p) Origin wX -> [PatchInfo] -> IO ()
forall wX wY. RL (PatchInfoAnd rt p) wX wY -> [PatchInfo] -> IO ()
check (PatchSet rt p Origin wX -> RL (PatchInfoAnd rt p) Origin wX
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
PatchSet rt p wStart wX -> RL (PatchInfoAnd rt p) wStart wX
patchSet2RL PatchSet rt p Origin wX
them) []

  (us' :: FL (PatchInfoAnd rt p) wZ wR
us':\/:them' :: FL (PatchInfoAnd rt p) wZ wX
them') <- (:\/:) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wR wX
-> IO
     ((:\/:) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wR wX)
forall (m :: * -> *) a. Monad m => a -> m a
return ((:\/:) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wR wX
 -> IO
      ((:\/:) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wR wX))
-> (:\/:) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wR wX
-> IO
     ((:\/:) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wR wX)
forall a b. (a -> b) -> a -> b
$ PatchSet rt p Origin wR
-> PatchSet rt p Origin wX
-> (:\/:) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wR wX
forall (p :: * -> * -> *) (rt :: RepoType) wStart wX wY.
Commute p =>
PatchSet rt p wStart wX
-> PatchSet rt p wStart wY
-> (:\/:) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wX wY
findUncommon PatchSet rt p Origin wR
us PatchSet rt p Origin wX
them
  (hadConflicts :: Bool
hadConflicts, Sealed their_ps :: FL (PatchInfoAnd rt p) wZ wX
their_ps)
    <- if PrimDarcsOption (Maybe AllowConflicts)
O.conflictsNo PrimDarcsOption (Maybe AllowConflicts)
-> [DarcsFlag] -> Maybe AllowConflicts
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts Maybe AllowConflicts -> Maybe AllowConflicts -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe AllowConflicts
forall a. Maybe a
Nothing -- skip conflicts
        then RL (PatchInfoAnd rt p) wZ wR
-> Repository rt p wR wU wR
-> FL (PatchInfoAnd rt p) wZ wX
-> IO (Bool, Sealed (FL (PatchInfoAnd rt p) wZ))
forall (p :: * -> * -> *) (rt :: RepoType) wX wT wR wU wZ.
(RepoPatch p, ApplyState p ~ Tree) =>
RL (PatchInfoAnd rt p) wX wT
-> Repository rt p wR wU wT
-> FL (PatchInfoAnd rt p) wX wZ
-> IO (Bool, Sealed (FL (PatchInfoAnd rt p) wX))
filterOutConflicts (FL (PatchInfoAnd rt p) wZ wR -> RL (PatchInfoAnd rt p) wZ wR
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL (PatchInfoAnd rt p) wZ wR
us') Repository rt p wR wU wR
repository FL (PatchInfoAnd rt p) wZ wX
them'
        else (Bool, Sealed (FL (PatchInfoAnd rt p) wZ))
-> IO (Bool, Sealed (FL (PatchInfoAnd rt p) wZ))
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
False, FL (PatchInfoAnd rt p) wZ wX -> Sealed (FL (PatchInfoAnd rt p) wZ)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed FL (PatchInfoAnd rt p) wZ wX
them')
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
hadConflicts (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> IO ()
putStrLn "Skipping some patches which would cause conflicts."
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (FL (PatchInfoAnd rt p) wZ wX -> Bool
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Bool
nullFL FL (PatchInfoAnd rt p) wZ wX
their_ps) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
       do if Bool
hadConflicts
           then String -> IO ()
putStrLn ("All new patches of the bundle cause conflicts.  " String -> String -> String
forall a. [a] -> [a] -> [a]
++
                          "Nothing to do.") IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO ()
forall a. IO a
exitSuccess
           else String -> IO ()
putStrLn ("All these patches have already been applied.  " String -> String -> String
forall a. [a] -> [a] -> [a]
++
                          "Nothing to do.") IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PrimDarcsOption Reorder
reorder PrimDarcsOption Reorder -> [DarcsFlag] -> Reorder
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts Reorder -> Reorder -> Bool
forall a. Eq a => a -> a -> Bool
/= Reorder
O.Reorder) IO ()
forall a. IO a
exitSuccess
          
  let direction :: WhichChanges
direction = if PrimDarcsOption Bool
changesReverse PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts then WhichChanges
FirstReversed else WhichChanges
First
      context :: PatchSelectionContext (PatchInfoAnd rt p)
context = WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PatchInfoAnd rt p))
-> Maybe [String]
-> PatchSelectionContext (PatchInfoAnd rt p)
forall (rt :: RepoType) (p :: * -> * -> *).
(IsRepoType rt, RepoPatch p) =>
WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PatchInfoAnd rt p))
-> Maybe [String]
-> PatchSelectionContext (PatchInfoAnd rt p)
selectionContext WhichChanges
direction "apply" ([DarcsFlag] -> PatchSelectionOptions
patchSelOpts [DarcsFlag]
opts) Maybe (Splitter (PatchInfoAnd rt p))
forall a. Maybe a
Nothing Maybe [String]
forall a. Maybe a
Nothing
  (to_be_applied :: FL (PatchInfoAnd rt p) wZ wZ
to_be_applied :> _) <- FL (PatchInfoAnd rt p) wZ wX
-> PatchSelectionContext (PatchInfoAnd rt p)
-> IO
     ((:>) (FL (PatchInfoAnd rt p)) (FL (PatchInfoAnd rt p)) wZ wX)
forall (p :: * -> * -> *) wX wY.
(Invert p, Commute p, Apply p, PatchInspect p, ShowPatch p,
 ShowContextPatch p, ApplyState p ~ Tree) =>
FL p wX wY
-> PatchSelectionContext p -> IO ((:>) (FL p) (FL p) wX wY)
runSelection FL (PatchInfoAnd rt p) wZ wX
their_ps PatchSelectionContext (PatchInfoAnd rt p)
context
  pa
-> PatchProxy p
-> String
-> [DarcsFlag]
-> String
-> Repository rt p wR wU wR
-> FL (PatchInfoAnd rt p) wZ wR
-> FL (PatchInfoAnd rt p) wZ wZ
-> IO ()
forall pa (rt :: RepoType) (p :: * -> * -> *) wR wU wT wX wZ.
(PatchApplier pa, ApplierRepoTypeConstraint pa rt, IsRepoType rt,
 RepoPatch p, ApplyState p ~ Tree) =>
pa
-> PatchProxy p
-> String
-> [DarcsFlag]
-> String
-> Repository rt p wR wU wT
-> FL (PatchInfoAnd rt p) wX wT
-> FL (PatchInfoAnd rt p) wX wZ
-> IO ()
applyPatches pa
patchApplier PatchProxy p
patchProxy "apply" [DarcsFlag]
opts String
from_whom Repository rt p wR wU wR
repository FL (PatchInfoAnd rt p) wZ wR
us' FL (PatchInfoAnd rt p) wZ wZ
to_be_applied
--    see the default (False) for the option
--    where fixed_opts = if Interactive `elem` opts
--                          then opts
--                          else All : opts

getPatchBundle :: RepoPatch p => [DarcsFlag] -> B.ByteString
                 -> IO (Either String (SealedPatchSet rt p Origin))
getPatchBundle :: [DarcsFlag]
-> ByteString -> IO (Either String (SealedPatchSet rt p Origin))
getPatchBundle opts :: [DarcsFlag]
opts fps :: ByteString
fps = do
    let opt_verify :: Verify
opt_verify = PrimDarcsOption Verify -> [DarcsFlag] -> Verify
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
parseFlags PrimDarcsOption Verify
O.verify [DarcsFlag]
opts
    Maybe ByteString
mps <- Verify -> ByteString -> IO (Maybe ByteString)
verifyPS Verify
opt_verify (ByteString -> IO (Maybe ByteString))
-> ByteString -> IO (Maybe ByteString)
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
readEmail ByteString
fps
    Maybe ByteString
mops <- Verify -> ByteString -> IO (Maybe ByteString)
verifyPS Verify
opt_verify ByteString
fps
    case (Maybe ByteString
mps, Maybe ByteString
mops) of
      (Nothing, Nothing) ->
          Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String (SealedPatchSet rt p Origin)
 -> IO (Either String (SealedPatchSet rt p Origin)))
-> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall a b. (a -> b) -> a -> b
$ String -> Either String (SealedPatchSet rt p Origin)
forall a b. a -> Either a b
Left "Patch bundle not properly signed, or gpg failed."
      (Just bundle :: ByteString
bundle, Nothing) -> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String (SealedPatchSet rt p Origin)
 -> IO (Either String (SealedPatchSet rt p Origin)))
-> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall a b. (a -> b) -> a -> b
$ ByteString -> Either String (SealedPatchSet rt p Origin)
forall (rt :: RepoType) (p :: * -> * -> *).
RepoPatch p =>
ByteString -> Either String (SealedPatchSet rt p Origin)
scanBundle ByteString
bundle
      (Nothing, Just bundle :: ByteString
bundle) -> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String (SealedPatchSet rt p Origin)
 -> IO (Either String (SealedPatchSet rt p Origin)))
-> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall a b. (a -> b) -> a -> b
$ ByteString -> Either String (SealedPatchSet rt p Origin)
forall (rt :: RepoType) (p :: * -> * -> *).
RepoPatch p =>
ByteString -> Either String (SealedPatchSet rt p Origin)
scanBundle ByteString
bundle
      -- We use careful_scan_bundle only below because in either of the two
      -- above case we know the patch was signed, so it really shouldn't
      -- need stripping of CRs.
      (Just ps1 :: ByteString
ps1, Just ps2 :: ByteString
ps2) -> case ByteString -> Either String (SealedPatchSet rt p Origin)
forall (p :: * -> * -> *) (rt :: RepoType).
RepoPatch p =>
ByteString -> Either String (SealedPatchSet rt p Origin)
careful_scan_bundle ByteString
ps1 of
                              Left _ -> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String (SealedPatchSet rt p Origin)
 -> IO (Either String (SealedPatchSet rt p Origin)))
-> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall a b. (a -> b) -> a -> b
$ ByteString -> Either String (SealedPatchSet rt p Origin)
forall (p :: * -> * -> *) (rt :: RepoType).
RepoPatch p =>
ByteString -> Either String (SealedPatchSet rt p Origin)
careful_scan_bundle ByteString
ps2
                              Right x :: SealedPatchSet rt p Origin
x -> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String (SealedPatchSet rt p Origin)
 -> IO (Either String (SealedPatchSet rt p Origin)))
-> Either String (SealedPatchSet rt p Origin)
-> IO (Either String (SealedPatchSet rt p Origin))
forall a b. (a -> b) -> a -> b
$ SealedPatchSet rt p Origin
-> Either String (SealedPatchSet rt p Origin)
forall a b. b -> Either a b
Right SealedPatchSet rt p Origin
x
          where careful_scan_bundle :: ByteString -> Either String (SealedPatchSet rt p Origin)
careful_scan_bundle bundle :: ByteString
bundle =
                    case ByteString -> Either String (SealedPatchSet rt p Origin)
forall (rt :: RepoType) (p :: * -> * -> *).
RepoPatch p =>
ByteString -> Either String (SealedPatchSet rt p Origin)
scanBundle ByteString
bundle of
                    Left e :: String
e -> case ByteString -> Either String (SealedPatchSet rt p Origin)
forall (rt :: RepoType) (p :: * -> * -> *).
RepoPatch p =>
ByteString -> Either String (SealedPatchSet rt p Origin)
scanBundle (ByteString -> Either String (SealedPatchSet rt p Origin))
-> ByteString -> Either String (SealedPatchSet rt p Origin)
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
stripCrPS ByteString
bundle of
                              Right x :: SealedPatchSet rt p Origin
x -> SealedPatchSet rt p Origin
-> Either String (SealedPatchSet rt p Origin)
forall a b. b -> Either a b
Right SealedPatchSet rt p Origin
x
                              _ -> String -> Either String (SealedPatchSet rt p Origin)
forall a b. a -> Either a b
Left String
e
                    x :: Either String (SealedPatchSet rt p Origin)
x -> Either String (SealedPatchSet rt p Origin)
x
                stripCrPS :: B.ByteString -> B.ByteString
                stripCrPS :: ByteString -> ByteString
stripCrPS bundle :: ByteString
bundle = [ByteString] -> ByteString
unlinesPS ([ByteString] -> ByteString) -> [ByteString] -> ByteString
forall a b. (a -> b) -> a -> b
$ (ByteString -> ByteString) -> [ByteString] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map ByteString -> ByteString
stripline ([ByteString] -> [ByteString]) -> [ByteString] -> [ByteString]
forall a b. (a -> b) -> a -> b
$ ByteString -> [ByteString]
linesPS ByteString
bundle
                stripline :: ByteString -> ByteString
stripline p :: ByteString
p | ByteString -> Bool
B.null ByteString
p = ByteString
p
                            | ByteString -> Char
BC.last ByteString
p Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\r' = ByteString -> ByteString
B.init ByteString
p
                            | Bool
otherwise = ByteString
p

applyHelp' :: String
applyHelp' :: String
applyHelp' =
 "A patch bundle may introduce unresolved conflicts with existing\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "patches or with the working tree.  By default, Darcs will add conflict\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "markers (see `darcs mark-conflicts`).\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "The `--external-merge` option lets you resolve these conflicts\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "using an external merge tool.  In the option, `%a` is replaced with\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "the common ancestor (merge base), `%1` with the first version, `%2`\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "with the second version, and `%o` with the path where your resolved\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "content should go.  For example, to use the xxdiff visual merge tool\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "you'd specify: `--external-merge='xxdiff -m -O -M %o %1 %a %2'`\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "The `--allow-conflicts` option will skip conflict marking; this is\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "useful when you want to treat a repository as just a bunch of patches,\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "such as using `darcs pull --union` to download of your co-workers\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "patches before going offline.\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "This can mess up unrecorded changes in the working tree, forcing you\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "to resolve the conflict immediately.  To simply reject bundles that\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "introduce unresolved conflicts, using the `--dont-allow-conflicts`\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "option.  Making this the default in push-based workflows is strongly\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "recommended.\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "Unlike most Darcs commands, `darcs apply` defaults to `--all`.  Use the\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
 "`--interactive` option to pick which patches to apply from a bundle.\n"

getFrom :: B.ByteString -> String
getFrom :: ByteString -> String
getFrom bundle :: ByteString
bundle = [ByteString] -> String
readFrom ([ByteString] -> String) -> [ByteString] -> String
forall a b. (a -> b) -> a -> b
$ ByteString -> [ByteString]
linesPS ByteString
bundle
    where readFrom :: [ByteString] -> String
readFrom [] = ""
          readFrom (x :: ByteString
x:xs :: [ByteString]
xs)
           | Int -> ByteString -> ByteString
B.take 5 ByteString
x ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString
fromStart = ByteString -> String
BC.unpack (ByteString -> String) -> ByteString -> String
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> ByteString
B.drop 5 ByteString
x
           | Bool
otherwise = [ByteString] -> String
readFrom [ByteString]
xs

forwardingMessage :: B.ByteString
forwardingMessage :: ByteString
forwardingMessage = String -> ByteString
BC.pack (String -> ByteString) -> String -> ByteString
forall a b. (a -> b) -> a -> b
$
    "The following patch was either unsigned, or signed by a non-allowed\n"String -> String -> String
forall a. [a] -> [a] -> [a]
++
    "key, or there was a GPG failure.\n"

considerForwarding :: [DarcsFlag] -> B.ByteString -> IO Bool
considerForwarding :: [DarcsFlag] -> ByteString -> IO Bool
considerForwarding opts :: [DarcsFlag]
opts bundle :: ByteString
bundle = case PrimDarcsOption (Maybe String)
reply PrimDarcsOption (Maybe String) -> [DarcsFlag] -> Maybe String
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts of
  Nothing -> Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
  Just from :: String
from -> case (ByteString -> Bool)
-> [ByteString] -> ([ByteString], [ByteString])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break ByteString -> Bool
is_from (ByteString -> [ByteString]
linesPS ByteString
bundle) of
    (m1 :: [ByteString]
m1, f :: ByteString
f:m2 :: [ByteString]
m2) ->
        let m_lines :: [ByteString]
m_lines = ByteString
forwardingMessageByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[ByteString]
m1 [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
m2
            m' :: ByteString
m' = [ByteString] -> ByteString
unlinesPS [ByteString]
m_lines
            f' :: String
f' = ByteString -> String
BC.unpack (Int -> ByteString -> ByteString
B.drop 5 ByteString
f) in
            if String
from String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
f' Bool -> Bool -> Bool
|| String
from String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String -> String
forall a. [a] -> [a]
init String
f'
            then Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False -- Refuse possible email loop.
            else do
              String
scmd <- [DarcsFlag] -> IO String
getSendmailCmd [DarcsFlag]
opts
              if PrimDarcsOption Bool
happyForwarding PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts
               then String -> String -> ByteString -> IO ()
resendEmail String
from String
scmd ByteString
bundle
               else String
-> String
-> String
-> String
-> String
-> Maybe (Doc, Doc)
-> Doc
-> IO ()
sendEmailDoc String
f' String
from "A forwarded darcs patch" String
cc
                                 String
scmd ((Doc, Doc) -> Maybe (Doc, Doc)
forall a. a -> Maybe a
Just (Doc
empty,Doc
empty))
                                 (ByteString -> Doc
packedString ByteString
m')
              Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
    _ -> Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False -- Don't forward emails lacking headers!
  where
    cc :: String
cc = [DarcsFlag] -> String
getCc [DarcsFlag]
opts
    is_from :: ByteString -> Bool
is_from l :: ByteString
l = Int -> ByteString -> ByteString
B.take 5 ByteString
l ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString
fromStart

fromStart :: B.ByteString
fromStart :: ByteString
fromStart = String -> ByteString
BC.pack "From:"

patchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions
patchSelOpts :: [DarcsFlag] -> PatchSelectionOptions
patchSelOpts flags :: [DarcsFlag]
flags = PatchSelectionOptions :: Verbosity
-> [MatchFlag]
-> Bool
-> SelectDeps
-> Summary
-> WithContext
-> PatchSelectionOptions
S.PatchSelectionOptions
    { verbosity :: Verbosity
S.verbosity = PrimDarcsOption Verbosity
verbosity PrimDarcsOption Verbosity -> [DarcsFlag] -> Verbosity
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
flags
    , matchFlags :: [MatchFlag]
S.matchFlags = MatchOption -> [DarcsFlag] -> [MatchFlag]
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
parseFlags MatchOption
O.matchSeveral [DarcsFlag]
flags
    , interactive :: Bool
S.interactive = [DarcsFlag] -> Bool
maybeIsInteractive [DarcsFlag]
flags
    , selectDeps :: SelectDeps
S.selectDeps = SelectDeps
O.PromptDeps -- option not supported, use default
    , summary :: Summary
S.summary = Summary
O.NoSummary -- option not supported, use default
    , withContext :: WithContext
S.withContext = PrimDarcsOption WithContext
withContext PrimDarcsOption WithContext -> [DarcsFlag] -> WithContext
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
flags
    }

maybeIsInteractive :: [DarcsFlag] -> Bool
maybeIsInteractive :: [DarcsFlag] -> Bool
maybeIsInteractive = Bool -> (Bool -> Bool) -> Maybe Bool -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False Bool -> Bool
forall a. a -> a
id (Maybe Bool -> Bool)
-> ([DarcsFlag] -> Maybe Bool) -> [DarcsFlag] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimDarcsOption (Maybe Bool) -> [DarcsFlag] -> Maybe Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
parseFlags PrimDarcsOption (Maybe Bool)
O.interactive