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

-- |
-- Copyright   : 2004, 2007 David Roundy
-- License     : GPL
-- Maintainer  : darcs-devel@darcs.net
-- Stability   : experimental
-- Portability : portable

{-# LANGUAGE OverloadedStrings #-}
module Darcs.UI.Commands.Amend
    (
      amend
    , amendrecord
    ) where

import Darcs.Prelude

import Control.Monad ( unless )
import Data.Maybe ( isNothing, isJust )

import Darcs.UI.Commands
    ( DarcsCommand(..), withStdOpts
    , commandAlias
    , nodefaults
    , setEnvDarcsFiles
    , setEnvDarcsPatches
    , amInHashedRepository
    )
import Darcs.UI.Commands.Util
    ( announceFiles
    , historyEditHelp
    , testTentativeAndMaybeExit
    )
import Darcs.UI.Completion ( modifiedFileArgs, knownFileArgs )
import Darcs.UI.Flags ( diffingOpts, pathSetFromArgs )
import Darcs.UI.Options ( Config, (?), (^) )
import qualified Darcs.UI.Options.All as O
import Darcs.UI.PatchHeader
    ( AskAboutDeps(..)
    , HijackOptions(..)
    , patchHeaderConfig
    , runHijackT
    , updatePatchHeader
    )

import Darcs.Repository.Flags ( UpdatePending(..) )
import Darcs.Patch ( RepoPatch, description, PrimOf
                   , effect, invert, invertFL, canonizeFL
                   )
import Darcs.Patch.Apply ( ApplyState )
import Darcs.Patch.Depends ( contextPatches, patchSetUnion, findCommonWithThem )
import Darcs.Patch.Info ( isTag )
import Darcs.Patch.Named ( fmapFL_Named )
import Darcs.Patch.PatchInfoAnd ( hopefully )
import Darcs.Patch.Set ( Origin, PatchSet )
import Darcs.Patch.Split ( primSplitter )
import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, patchDesc )
import Darcs.Patch.Rebase.Fixup ( RebaseFixup(..) )
import Darcs.Patch.Rebase.Name ( RebaseName(..) )
import Darcs.Util.Path ( AnchoredPath )
import Darcs.Repository
    ( Repository
    , AccessType(..)
    , withRepoLock
    , RepoJob(..)
    , identifyRepositoryFor
    , ReadingOrWriting(Reading)
    , tentativelyRemovePatches
    , tentativelyAddPatch
    , withManualRebaseUpdate
    , finalizeRepositoryChanges
    , readPendingAndWorking
    , readPristine
    , readPatches
    , tentativelyRemoveFromPW
    )
import Darcs.Repository.Pending ( readTentativePending, writeTentativePending )
import Darcs.Repository.Prefs ( getDefaultRepo )
import Darcs.UI.SelectChanges
    ( WhichChanges(..)
    , selectionConfigPrim
    , runInvertibleSelection
    , withSelectedPatchFromList
    )
import qualified Darcs.UI.SelectChanges as S
    ( PatchSelectionOptions(..)
    )
import Darcs.Util.Exception ( clarifyErrors )
import Darcs.Patch.Witnesses.Ordered
    ( FL(..), RL, (:>)(..), (+>+)
    , nullFL, reverseRL, reverseFL, mapFL_FL
    )
import Darcs.Patch.Witnesses.Sealed ( Sealed(..) )

import Darcs.Util.English ( anyOfClause, itemizeVertical )
import Darcs.Util.Printer ( Doc, formatWords, putDocLn, text, (<+>), ($$), ($+$) )
import Darcs.Util.Printer.Color ( ePutDocLn )
import Darcs.Util.Tree( Tree )


amendDescription :: String
amendDescription :: String
amendDescription = String
"Improve a patch before it leaves your repository."


amendHelp :: Doc
amendHelp :: Doc
amendHelp =
  [String] -> Doc
formatWords
  [ String
"Amend updates a \"draft\" patch with additions or improvements,"
  , String
"resulting in a single \"finished\" patch."
  ]
  Doc -> Doc -> Doc
$+$ [String] -> Doc
formatWords
  [ String
"By default `amend` proposes you to record additional changes."
  , String
"If instead you want to remove changes, use the flag `--unrecord`."
  ]
  Doc -> Doc -> Doc
$+$ [String] -> Doc
formatWords
  [ String
"When recording a draft patch, it is a good idea to start the name with"
  , String
"`DRAFT:`. When done, remove it with `darcs amend --edit-long-comment`."
  , String
"Alternatively, to change the patch name without starting an editor, "
  , String
"use the `--name`/`-m` flag:"
  ]
  Doc -> Doc -> Doc
$+$ String -> Doc
text
    String
"    darcs amend --match 'name \"DRAFT: foo\"' --name 'foo2'"
  Doc -> Doc -> Doc
$+$ [String] -> Doc
formatWords
  [ String
"Like `darcs record`, if you call amend with files as arguments,"
  , String
"you will only be asked about changes to those files.  So to amend a"
  , String
"patch to foo.c with improvements in bar.c, you would run:"
  ]
  Doc -> Doc -> Doc
$+$ String -> Doc
text
    String
"    darcs amend --match 'touch foo.c' bar.c"
  Doc -> Doc -> Doc
$+$ Doc
historyEditHelp

amend :: DarcsCommand
amend :: DarcsCommand
amend = DarcsCommand
    {
      commandProgramName :: String
commandProgramName          = String
"darcs"
    , commandName :: String
commandName                 = String
"amend"
    , commandHelp :: Doc
commandHelp                 = Doc
amendHelp
    , commandDescription :: String
commandDescription          = String
amendDescription
    , commandExtraArgs :: Int
commandExtraArgs            = -Int
1
    , commandExtraArgHelp :: [String]
commandExtraArgHelp         = [String
"[FILE or DIRECTORY]..."]
    , commandCommand :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
commandCommand              = (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
amendCmd
    , 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          = [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
nodefaults
    , commandOptions :: CommandOptions
commandOptions              = CommandOptions
allOpts
    }
  where
    fileArgs :: (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
fileArgs (AbsolutePath, AbsolutePath)
fps [DarcsFlag]
flags [String]
args =
      if (PrimOptSpec DarcsOptDescr DarcsFlag a Bool
PrimDarcsOption Bool
O.amendUnrecord PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
flags)
        then (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
knownFileArgs (AbsolutePath, AbsolutePath)
fps [DarcsFlag]
flags [String]
args
        else (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
modifiedFileArgs (AbsolutePath, AbsolutePath)
fps [DarcsFlag]
flags [String]
args
    basicOpts :: OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
basicOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  ([NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  Bool
PrimDarcsOption Bool
O.amendUnrecord
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  ([NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  Bool
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     ([MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     ([NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     ([MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  ([NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption [NotInRemote]
O.notInRemote
      OptSpec
  DarcsOptDescr
  DarcsFlag
  ([MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
  (TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
MatchOption
O.matchOneNontag
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption TestChanges
O.testChanges
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe Bool)
O.interactive --True
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
  (Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe String)
O.author
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption Bool
O.selectAuthor
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
  (Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe String)
O.patchname
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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 AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption Bool
O.askDeps
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
  (Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe AskLongComment)
O.askLongComment
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
  (LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption Bool
O.keepDate
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LookForReplaces
      -> LookForMoves -> Maybe String -> DiffAlgorithm -> a)
     (LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> Maybe String
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LookForReplaces
      -> LookForMoves -> Maybe String -> DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
  (LookForReplaces
   -> LookForMoves -> Maybe String -> DiffAlgorithm -> a)
  (LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
PrimDarcsOption LookForAdds
O.lookforadds
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (LookForReplaces
   -> LookForMoves -> Maybe String -> DiffAlgorithm -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LookForMoves -> Maybe String -> DiffAlgorithm -> a)
     (LookForReplaces
      -> LookForMoves -> Maybe String -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LookForMoves -> Maybe String -> DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
  (LookForMoves -> Maybe String -> DiffAlgorithm -> a)
  (LookForReplaces
   -> LookForMoves -> Maybe String -> DiffAlgorithm -> a)
PrimDarcsOption LookForReplaces
O.lookforreplaces
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (LookForMoves -> Maybe String -> DiffAlgorithm -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> DiffAlgorithm -> a)
     (LookForMoves -> Maybe String -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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)
  (LookForMoves -> Maybe String -> DiffAlgorithm -> a)
PrimDarcsOption LookForMoves
O.lookformoves
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String -> DiffAlgorithm -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     (Maybe String -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     a
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookForAdds
      -> LookForReplaces
      -> LookForMoves
      -> 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
    advancedOpts :: OptSpec
  DarcsOptDescr DarcsFlag a (UMask -> SetScriptsExecutable -> a)
advancedOpts
      = PrimOptSpec
  DarcsOptDescr DarcsFlag (SetScriptsExecutable -> a) UMask
PrimDarcsOption UMask
O.umask
      PrimOptSpec
  DarcsOptDescr DarcsFlag (SetScriptsExecutable -> a) UMask
-> OptSpec DarcsOptDescr DarcsFlag a (SetScriptsExecutable -> a)
-> OptSpec
     DarcsOptDescr DarcsFlag a (UMask -> SetScriptsExecutable -> 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 (SetScriptsExecutable -> a)
PrimDarcsOption SetScriptsExecutable
O.setScriptsExecutable
    allOpts :: CommandOptions
allOpts = DarcsOption
  (Maybe StdCmdAction
   -> Verbosity
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
-> DarcsOption
     (UseCache
      -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
     (UMask
      -> SetScriptsExecutable
      -> UseCache
      -> UseIndex
      -> HooksConfig
      -> Bool
      -> Bool
      -> [DarcsFlag])
-> CommandOptions
forall b c.
DarcsOption (Maybe StdCmdAction -> Verbosity -> b) c
-> DarcsOption
     (UseCache
      -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
     b
-> CommandOptions
withStdOpts DarcsOption
  (Maybe StdCmdAction
   -> Verbosity
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
forall {a}.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookForAdds
   -> LookForReplaces
   -> LookForMoves
   -> Maybe String
   -> DiffAlgorithm
   -> a)
basicOpts DarcsOption
  (UseCache
   -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
  (UMask
   -> SetScriptsExecutable
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
forall {a}.
OptSpec
  DarcsOptDescr DarcsFlag a (UMask -> SetScriptsExecutable -> a)
advancedOpts
    amendCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
amendCmd (AbsolutePath, AbsolutePath)
fps [DarcsFlag]
flags [String]
args = (AbsolutePath, AbsolutePath)
-> [String] -> IO (Maybe [AnchoredPath])
pathSetFromArgs (AbsolutePath, AbsolutePath)
fps [String]
args IO (Maybe [AnchoredPath])
-> (Maybe [AnchoredPath] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [DarcsFlag] -> Maybe [AnchoredPath] -> IO ()
doAmend [DarcsFlag]
flags

amendrecord :: DarcsCommand
amendrecord :: DarcsCommand
amendrecord = String -> Maybe DarcsCommand -> DarcsCommand -> DarcsCommand
commandAlias String
"amend-record" Maybe DarcsCommand
forall a. Maybe a
Nothing DarcsCommand
amend

doAmend :: Config -> Maybe [AnchoredPath] -> IO ()
doAmend :: [DarcsFlag] -> Maybe [AnchoredPath] -> IO ()
doAmend [DarcsFlag]
cfg Maybe [AnchoredPath]
files =
  UseCache -> UMask -> RepoJob 'RW () -> IO ()
forall a. UseCache -> UMask -> RepoJob 'RW a -> IO a
withRepoLock (PrimOptSpec DarcsOptDescr DarcsFlag a UseCache
PrimDarcsOption UseCache
O.useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg) (PrimOptSpec DarcsOptDescr DarcsFlag a UMask
PrimDarcsOption UMask
O.umask PrimDarcsOption UMask -> [DarcsFlag] -> UMask
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg) (RepoJob 'RW () -> IO ()) -> RepoJob 'RW () -> IO ()
forall a b. (a -> b) -> a -> b
$
      TreePatchJob 'RW () -> RepoJob 'RW ()
forall (rt :: AccessType) a. TreePatchJob rt a -> RepoJob rt a
RepoJob (TreePatchJob 'RW () -> RepoJob 'RW ())
-> TreePatchJob 'RW () -> RepoJob 'RW ()
forall a b. (a -> b) -> a -> b
$ \(Repository 'RW p wU wR
repository :: Repository 'RW p wU wR) -> do
    patchSet <- Repository 'RW p wU wR -> IO (PatchSet p Origin wR)
forall (p :: * -> * -> *) (rt :: AccessType) wU wR.
RepoPatch p =>
Repository rt p wU wR -> IO (PatchSet p Origin wR)
readPatches Repository 'RW p wU wR
repository
    _ :> candidates <- filterNotInRemote cfg repository patchSet
    withSelectedPatchFromList "amend" candidates (patchSelOpts cfg) $
     \(RL (PatchInfoAnd p) wZ wZ
kept :> PatchInfoAnd p wZ wR
oldp) -> do
      Verbosity -> Maybe [AnchoredPath] -> String -> IO ()
announceFiles (PrimOptSpec DarcsOptDescr DarcsFlag a Verbosity
PrimDarcsOption Verbosity
O.verbosity PrimDarcsOption Verbosity -> [DarcsFlag] -> Verbosity
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg) Maybe [AnchoredPath]
files String
"Amending changes in"
      pending :> working <-
        DiffOpts
-> Repository 'RW p wU wR
-> Maybe [AnchoredPath]
-> IO ((:>) (FL (PrimOf p)) (FL (PrimOf p)) wR wU)
forall (p :: * -> * -> *) (rt :: AccessType) wU wR.
(RepoPatch p, ApplyState p ~ Tree) =>
DiffOpts
-> Repository rt p wU wR
-> Maybe [AnchoredPath]
-> IO ((:>) (FL (PrimOf p)) (FL (PrimOf p)) wR wU)
readPendingAndWorking ([DarcsFlag] -> DiffOpts
diffingOpts [DarcsFlag]
cfg) Repository 'RW p wU wR
repository Maybe [AnchoredPath]
files
      -- auxiliary function needed because the witness types differ for the
      -- isTag case
      let go :: FL (PrimOf p) wR wU1 -> IO ()
          go FL (PrimOf p) wR wU1
NilFL | Bool -> Bool
not ([DarcsFlag] -> Bool
hasEditMetadata [DarcsFlag]
cfg) = [DarcsFlag] -> Doc -> IO ()
putInfo [DarcsFlag]
cfg Doc
"No changes!"
          go FL (PrimOf p) wR wU1
ch = do
            let selection_config :: SelectionConfig (PrimOf p)
selection_config =
                   WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PrimOf p))
-> Maybe [AnchoredPath]
-> SelectionConfig (PrimOf p)
forall (prim :: * -> * -> *).
WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter prim)
-> Maybe [AnchoredPath]
-> SelectionConfig prim
selectionConfigPrim WhichChanges
First String
"record"
                       ([DarcsFlag] -> PatchSelectionOptions
patchSelOpts [DarcsFlag]
cfg)
                       (Splitter (PrimOf p) -> Maybe (Splitter (PrimOf p))
forall a. a -> Maybe a
Just (DiffAlgorithm -> Splitter (PrimOf p)
forall (p :: * -> * -> *).
PrimPatch p =>
DiffAlgorithm -> Splitter p
primSplitter (PrimOptSpec DarcsOptDescr DarcsFlag a DiffAlgorithm
PrimDarcsOption DiffAlgorithm
O.diffAlgorithm PrimDarcsOption DiffAlgorithm -> [DarcsFlag] -> DiffAlgorithm
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg)))
                       Maybe [AnchoredPath]
files
            (chosenPatches :> _) <- FL (PrimOf p) wR wU1
-> SelectionConfig (PrimOf p)
-> IO ((:>) (FL (PrimOf p)) (FL (PrimOf p)) wR wU1)
forall (p :: * -> * -> *) wX wY.
(Invert p, MatchableRP p, ShowPatch p, ShowContextPatch p,
 ApplyState p ~ Tree) =>
FL p wX wY -> SelectionConfig p -> IO ((:>) (FL p) (FL p) wX wY)
runInvertibleSelection FL (PrimOf p) wR wU1
ch SelectionConfig (PrimOf p)
selection_config
            addChangesToPatch cfg repository kept oldp chosenPatches pending working
      if not (isTag (info oldp))
        -- amending a normal patch
        then
          if O.amendUnrecord ? cfg
            then do
              let selection_config =
                    WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PrimOf p))
-> Maybe [AnchoredPath]
-> SelectionConfig (PrimOf p)
forall (prim :: * -> * -> *).
WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter prim)
-> Maybe [AnchoredPath]
-> SelectionConfig prim
selectionConfigPrim WhichChanges
Last String
"unrecord" ([DarcsFlag] -> PatchSelectionOptions
patchSelOpts [DarcsFlag]
cfg)
                      (Splitter (PrimOf p) -> Maybe (Splitter (PrimOf p))
forall a. a -> Maybe a
Just (DiffAlgorithm -> Splitter (PrimOf p)
forall (p :: * -> * -> *).
PrimPatch p =>
DiffAlgorithm -> Splitter p
primSplitter (PrimOptSpec DarcsOptDescr DarcsFlag a DiffAlgorithm
PrimDarcsOption DiffAlgorithm
O.diffAlgorithm PrimDarcsOption DiffAlgorithm -> [DarcsFlag] -> DiffAlgorithm
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg)))
                      Maybe [AnchoredPath]
files
              (_ :> chosenPrims) <-
                runInvertibleSelection (effect oldp) selection_config
              let invPrims = RL (PrimOf p) wR wZ -> FL (PrimOf p) wR wZ
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL (FL (PrimOf p) wZ wR -> RL (PrimOf p) wR wZ
forall (p :: * -> * -> *) wX wY.
Invert p =>
FL p wX wY -> RL p wY wX
invertFL FL (PrimOf p) wZ wR
chosenPrims)
              addChangesToPatch cfg repository kept oldp invPrims pending working
            else
              go (canonizeFL (O.diffAlgorithm ? cfg) (pending +>+ working))
        -- amending a tag
        else
          if hasEditMetadata cfg && isNothing files
            -- the user is not trying to add new changes to the tag so there is
            -- no reason to warn.
            then go NilFL
            -- the user is trying to add new changes to a tag.
            else do
              if hasEditMetadata cfg
                -- the user already knows that it is possible to edit tag metadata,
                -- note that s/he is providing editing options!
                then ePutDocLn "You cannot add new changes to a tag."
                -- the user may not be aware that s/he can edit tag metadata.
                else
                  ePutDocLn
                    "You cannot add new changes to a tag, but you are allowed to edit tag's metadata (see darcs help amend)."
              go NilFL


addChangesToPatch
  :: (RepoPatch p, ApplyState p ~ Tree)
  => Config
  -> Repository 'RW p wU wR
  -> RL (PatchInfoAnd p) wC wX  -- ^ candidates for --ask-deps
  -> PatchInfoAnd p wX wR       -- ^ original patch
  -> FL (PrimOf p) wR wY        -- ^ changes to add
  -> FL (PrimOf p) wR wP        -- ^ pending
  -> FL (PrimOf p) wP wU        -- ^ working
  -> IO ()
addChangesToPatch :: forall (p :: * -> * -> *) wU wR wC wX wY wP.
(RepoPatch p, ApplyState p ~ Tree) =>
[DarcsFlag]
-> Repository 'RW p wU wR
-> RL (PatchInfoAnd p) wC wX
-> PatchInfoAnd p wX wR
-> FL (PrimOf p) wR wY
-> FL (PrimOf p) wR wP
-> FL (PrimOf p) wP wU
-> IO ()
addChangesToPatch [DarcsFlag]
cfg Repository 'RW p wU wR
_repository RL (PatchInfoAnd p) wC wX
context PatchInfoAnd p wX wR
oldp FL (PrimOf p) wR wY
chs FL (PrimOf p) wR wP
pending FL (PrimOf p) wP wU
working =
  if FL (PrimOf p) wR wY -> Bool
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Bool
nullFL FL (PrimOf p) wR wY
chs Bool -> Bool -> Bool
&& Bool -> Bool
not ([DarcsFlag] -> Bool
hasEditMetadata [DarcsFlag]
cfg)
    then [DarcsFlag] -> Doc -> IO ()
putInfo [DarcsFlag]
cfg Doc
"You don't want to record anything!"
    else do
      -- remember the old pending for the amend --unrecord case, see below
      Sealed old_pending <- Repository 'RW p wU wR -> IO (Sealed (FL (PrimOf p) wR))
forall (p :: * -> * -> *) wU wR.
RepoPatch p =>
Repository 'RW p wU wR -> IO (Sealed (FL (PrimOf p) wR))
readTentativePending Repository 'RW p wU wR
_repository
      -- If a rebase is in progress, we want to manually update the rebase
      -- state, using the amendments directly as rebase fixups. This is
      -- necessary because otherwise we will first remove the original patch
      -- then add the amended patch,
      -- and this can lead to more conflicts than using the amendment as a fixup
      -- directly. For example, if a rename operation is amended in, the rename
      -- can be propagated to any edits to the file in the rebase state, whereas
      -- a delete then add would just cause a conflict.
      -- 
      -- We can also signal that any explicit dependencies of the old patch
      -- should be rewritten for the new patch using a 'NameFixup'.
      (_repository, (mlogf, newp)) <-
        withManualRebaseUpdate _repository $ \Repository 'RW p wU wR
_repository -> do
          -- Note we pass NoUpdatePending here and below when re-adding the
          -- amended patch, and instead fix pending explicitly further below.
          _repository <-
            Repository 'RW p wU wR
-> UpdatePending
-> FL (PatchInfoAnd p) wX wR
-> IO (Repository 'RW p wU wX)
forall (p :: * -> * -> *) wU wR wX.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository 'RW p wU wR
-> UpdatePending
-> FL (PatchInfoAnd p) wX wR
-> IO (Repository 'RW p wU wX)
tentativelyRemovePatches
              Repository 'RW p wU wR
_repository
              UpdatePending
NoUpdatePending
              (PatchInfoAnd p wX wR
oldp PatchInfoAnd p wX wR
-> FL (PatchInfoAnd p) wR wR -> FL (PatchInfoAnd p) wX wR
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (PatchInfoAnd p) wR wR
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL)
          (mlogf, newp) <-
            runHijackT AlwaysRequestHijackPermission $
            updatePatchHeader
              "amend"
              (if O.askDeps ? cfg
                 then AskAboutDeps context
                 else NoAskAboutDeps)
              (patchSelOpts cfg)
              (patchHeaderConfig cfg)
              (fmapFL_Named effect (hopefully oldp))
              chs
          let fixups =
                (forall wW wY. PrimOf p wW wY -> RebaseFixup (PrimOf p) wW wY)
-> FL (PrimOf p) wY wR -> FL (RebaseFixup (PrimOf p)) wY wR
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL PrimOf p wW wY -> RebaseFixup (PrimOf p) wW wY
forall wW wY. PrimOf p wW wY -> RebaseFixup (PrimOf p) wW wY
forall (prim :: * -> * -> *) wX wY.
prim wX wY -> RebaseFixup prim wX wY
PrimFixup (FL (PrimOf p) wR wY -> FL (PrimOf p) wY wR
forall wX wY. FL (PrimOf p) wX wY -> FL (PrimOf p) wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL (PrimOf p) wR wY
chs) FL (RebaseFixup (PrimOf p)) wY wR
-> FL (RebaseFixup (PrimOf p)) wR wZ
-> FL (RebaseFixup (PrimOf p)) wY wZ
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+
                RebaseName wR wZ -> RebaseFixup (PrimOf p) wR wZ
forall wX wY (prim :: * -> * -> *).
RebaseName wX wY -> RebaseFixup prim wX wY
NameFixup (PatchInfo -> PatchInfo -> RebaseName wR wZ
forall wX wY. PatchInfo -> PatchInfo -> RebaseName wX wY
Rename (PatchInfoAnd p wX wY -> PatchInfo
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> PatchInfo
info PatchInfoAnd p wX wY
newp) (PatchInfoAnd p wX wR -> PatchInfo
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> PatchInfo
info PatchInfoAnd p wX wR
oldp)) RebaseFixup (PrimOf p) wR wZ
-> FL (RebaseFixup (PrimOf p)) wZ wZ
-> FL (RebaseFixup (PrimOf p)) wR wZ
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>:
                FL (RebaseFixup (PrimOf p)) wZ wZ
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
          setEnvDarcsFiles newp
          _repository <-
            tentativelyAddPatch _repository NoUpdatePending newp
          return (_repository, fixups, (mlogf, newp))
      let failmsg = String -> (String -> String) -> Maybe String -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe String
"" (\String
lf -> String
"\nLogfile left in " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lf String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
".") Maybe String
mlogf
      tp <- readPristine _repository
      testTentativeAndMaybeExit tp cfg
        ("you have a bad patch: '" ++ patchDesc newp ++ "'")
        "amend it"
        (Just failmsg)
      if O.amendUnrecord ? cfg then
        writeTentativePending _repository $ invert chs +>+ old_pending
      else
        tentativelyRemoveFromPW _repository chs pending working
      _repository <-
        finalizeRepositoryChanges _repository (O.dryRun ? cfg)
          `clarifyErrors` failmsg
      case O.verbosity ? cfg of
        Verbosity
O.NormalVerbosity -> Doc -> IO ()
putDocLn Doc
"Finished amending patch."
        Verbosity
O.Verbose -> Doc -> IO ()
putDocLn (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ Doc
"Finished amending patch:" Doc -> Doc -> Doc
$$ PatchInfoAnd p wX wY -> Doc
forall wX wY. PatchInfoAndG (Named p) wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description PatchInfoAnd p wX wY
newp
        Verbosity
_ -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      setEnvDarcsPatches (newp :>: NilFL)

filterNotInRemote :: RepoPatch p
                  => Config
                  -> Repository 'RW p wU wR
                  -> PatchSet p Origin wR
                  -> IO ((PatchSet p :> RL (PatchInfoAnd p)) Origin wR)
filterNotInRemote :: forall (p :: * -> * -> *) wU wR.
RepoPatch p =>
[DarcsFlag]
-> Repository 'RW p wU wR
-> PatchSet p Origin wR
-> IO ((:>) (PatchSet p) (RL (PatchInfoAnd p)) Origin wR)
filterNotInRemote [DarcsFlag]
cfg Repository 'RW p wU wR
repository PatchSet p Origin wR
patchSet = do
    nirs <- (NotInRemote -> IO String) -> [NotInRemote] -> IO [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM NotInRemote -> IO String
getNotInRemotePath (PrimOptSpec DarcsOptDescr DarcsFlag a [NotInRemote]
PrimDarcsOption [NotInRemote]
O.notInRemote PrimDarcsOption [NotInRemote] -> [DarcsFlag] -> [NotInRemote]
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg)
    if null nirs
      then
        -- We call contextPatches here because
        -- (a) selecting patches beyond the latest clean tag is impossible anyway
        -- (b) makes it easier to reconstruct a PatchSet w/o the selected patch
        -- (c) avoids listing the complete list of patches in the repo when user
        --     rejects the last selectable patch
        return (contextPatches patchSet)
      else do
        putInfo cfg $
          "Determining patches not in" <+> anyOfClause nirs $$ itemizeVertical 2 nirs
        Sealed thems <- patchSetUnion `fmap` mapM readNir nirs
        in_remote :> only_ours <- return $ findCommonWithThem patchSet thems
        return (in_remote :> reverseFL only_ours)
  where
    readNir :: String -> IO (Sealed (PatchSet p Origin))
readNir String
loc = do
      repo <- ReadingOrWriting
-> Repository 'RW p wU wR
-> UseCache
-> String
-> IO (Repository 'RO p (ZonkAny 0) (ZonkAny 1))
forall (rt :: AccessType) (p :: * -> * -> *) wU wR vR vU.
ReadingOrWriting
-> Repository rt p wU wR
-> UseCache
-> String
-> IO (Repository 'RO p vR vU)
identifyRepositoryFor ReadingOrWriting
Reading Repository 'RW p wU wR
repository (PrimOptSpec DarcsOptDescr DarcsFlag a UseCache
PrimDarcsOption UseCache
O.useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg) String
loc
      rps <- readPatches repo
      return (Sealed rps)
    getNotInRemotePath :: NotInRemote -> IO String
getNotInRemotePath (O.NotInRemotePath String
p) = String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
p
    getNotInRemotePath NotInRemote
O.NotInDefaultRepo = do
        defaultRepo <- IO (Maybe String)
getDefaultRepo
        let err = String -> IO a
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO a) -> String -> IO a
forall a b. (a -> b) -> a -> b
$ String
"No default push/pull repo configured, please pass a "
                         String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"repo name to --" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
O.notInRemoteFlagName
        maybe err return defaultRepo

hasEditMetadata :: Config -> Bool
hasEditMetadata :: [DarcsFlag] -> Bool
hasEditMetadata [DarcsFlag]
cfg = Maybe String -> Bool
forall a. Maybe a -> Bool
isJust (PrimOptSpec DarcsOptDescr DarcsFlag a (Maybe String)
PrimDarcsOption (Maybe String)
O.author PrimDarcsOption (Maybe String) -> [DarcsFlag] -> Maybe String
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg)
                    Bool -> Bool -> Bool
|| PrimOptSpec DarcsOptDescr DarcsFlag a Bool
PrimDarcsOption Bool
O.selectAuthor PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg
                    Bool -> Bool -> Bool
|| Maybe String -> Bool
forall a. Maybe a -> Bool
isJust (PrimOptSpec DarcsOptDescr DarcsFlag a (Maybe String)
PrimDarcsOption (Maybe String)
O.patchname PrimDarcsOption (Maybe String) -> [DarcsFlag] -> Maybe String
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg)
                    Bool -> Bool -> Bool
|| PrimOptSpec DarcsOptDescr DarcsFlag a (Maybe AskLongComment)
PrimDarcsOption (Maybe AskLongComment)
O.askLongComment PrimDarcsOption (Maybe AskLongComment)
-> [DarcsFlag] -> Maybe AskLongComment
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg Maybe AskLongComment -> Maybe AskLongComment -> Bool
forall a. Eq a => a -> a -> Bool
== AskLongComment -> Maybe AskLongComment
forall a. a -> Maybe a
Just AskLongComment
O.YesEditLongComment
                    Bool -> Bool -> Bool
|| PrimOptSpec DarcsOptDescr DarcsFlag a (Maybe AskLongComment)
PrimDarcsOption (Maybe AskLongComment)
O.askLongComment PrimDarcsOption (Maybe AskLongComment)
-> [DarcsFlag] -> Maybe AskLongComment
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg Maybe AskLongComment -> Maybe AskLongComment -> Bool
forall a. Eq a => a -> a -> Bool
== AskLongComment -> Maybe AskLongComment
forall a. a -> Maybe a
Just AskLongComment
O.PromptLongComment
                    Bool -> Bool -> Bool
|| PrimOptSpec DarcsOptDescr DarcsFlag a Bool
PrimDarcsOption Bool
O.askDeps PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg

patchSelOpts :: Config -> S.PatchSelectionOptions
patchSelOpts :: [DarcsFlag] -> PatchSelectionOptions
patchSelOpts [DarcsFlag]
cfg = S.PatchSelectionOptions
    { verbosity :: Verbosity
S.verbosity = PrimOptSpec DarcsOptDescr DarcsFlag a Verbosity
PrimDarcsOption Verbosity
O.verbosity PrimDarcsOption Verbosity -> [DarcsFlag] -> Verbosity
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg
    , matchFlags :: [MatchFlag]
S.matchFlags = PrimOptSpec DarcsOptDescr DarcsFlag a [MatchFlag]
MatchOption
O.matchOneNontag MatchOption -> [DarcsFlag] -> [MatchFlag]
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg
    , interactive :: Bool
S.interactive = [DarcsFlag] -> Bool
isInteractive [DarcsFlag]
cfg
    , selectDeps :: SelectDeps
S.selectDeps = SelectDeps
O.PromptDeps -- option not supported, use default
    , withSummary :: WithSummary
S.withSummary = WithSummary
O.NoSummary -- option not supported, use default
    }

isInteractive :: Config -> Bool
isInteractive :: [DarcsFlag] -> Bool
isInteractive [DarcsFlag]
cfg = Bool -> (Bool -> Bool) -> Maybe Bool -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True Bool -> Bool
forall a. a -> a
id (PrimOptSpec DarcsOptDescr DarcsFlag a (Maybe Bool)
PrimDarcsOption (Maybe Bool)
O.interactive PrimDarcsOption (Maybe Bool) -> [DarcsFlag] -> Maybe Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg)

putInfo :: Config -> Doc -> IO ()
putInfo :: [DarcsFlag] -> Doc -> IO ()
putInfo [DarcsFlag]
cfg Doc
what = Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (PrimOptSpec DarcsOptDescr DarcsFlag a Verbosity
PrimDarcsOption Verbosity
O.verbosity PrimDarcsOption Verbosity -> [DarcsFlag] -> Verbosity
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
cfg Verbosity -> Verbosity -> Bool
forall a. Eq a => a -> a -> Bool
== Verbosity
O.Quiet) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Doc -> IO ()
putDocLn Doc
what