--  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 ( diffOpts, pathSetFromArgs )
import Darcs.UI.Options ( (^), oparse, odesc, ocheck, defaultFlags, (?) )
import qualified Darcs.UI.Options.All as O
import Darcs.UI.PatchHeader ( updatePatchHeader, AskAboutDeps(..)
                            , HijackOptions(..)
                            , runHijackT )

import Darcs.Repository.Flags ( UpdatePending(..), DryRun(NoDryRun) )
import Darcs.Patch ( IsRepoType, RepoPatch, description, PrimOf
                   , effect, invert, invertFL, sortCoalesceFL
                   )
import Darcs.Patch.Apply ( ApplyState )
import Darcs.Patch.Depends ( patchSetUnion, findCommonWithThem )
import Darcs.Patch.Info ( isTag )
import Darcs.Patch.Named ( fmapFL_Named )
import Darcs.Patch.PatchInfoAnd ( hopefully )
import Darcs.Patch.Set ( Origin, PatchSet, patchSet2RL )
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
    , withRepoLock
    , RepoJob(..)
    , identifyRepositoryFor
    , ReadingOrWriting(Reading)
    , tentativelyRemovePatches
    , tentativelyAddPatch
    , withManualRebaseUpdate
    , finalizeRepositoryChanges
    , invalidateIndex
    , readPendingAndWorking
    , readRecorded
    , readRepo
    )
import Darcs.Repository.Pending ( tentativelyRemoveFromPW )
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(..), FlippedSeal(..) )

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

data AmendConfig = AmendConfig
    { AmendConfig -> Bool
amendUnrecord :: Bool
    , AmendConfig -> [NotInRemote]
notInRemote :: [O.NotInRemote]
    , AmendConfig -> [MatchFlag]
matchFlags :: [O.MatchFlag]
    , AmendConfig -> TestChanges
testChanges :: O.TestChanges
    , AmendConfig -> Maybe Bool
interactive :: Maybe Bool
    , AmendConfig -> Maybe String
author :: Maybe String
    , AmendConfig -> Bool
selectAuthor :: Bool
    , AmendConfig -> Maybe String
patchname :: Maybe String
    , AmendConfig -> Bool
askDeps :: Bool
    , AmendConfig -> Maybe AskLongComment
askLongComment :: Maybe O.AskLongComment
    , AmendConfig -> Bool
keepDate :: Bool
    , AmendConfig -> LookFor
lookfor :: O.LookFor
    , AmendConfig -> Maybe String
_workingRepoDir :: Maybe String
    , AmendConfig -> WithContext
withContext :: O.WithContext
    , AmendConfig -> DiffAlgorithm
diffAlgorithm :: O.DiffAlgorithm
    , AmendConfig -> Verbosity
verbosity :: O.Verbosity
    , AmendConfig -> Compression
compress :: O.Compression
    , AmendConfig -> UseIndex
useIndex :: O.UseIndex
    , AmendConfig -> UMask
umask :: O.UMask
    , AmendConfig -> SetScriptsExecutable
sse :: O.SetScriptsExecutable
    , AmendConfig -> UseCache
useCache :: O.UseCache
    }

amend :: DarcsCommand
amend :: DarcsCommand
amend = DarcsCommand :: String
-> String
-> Doc
-> String
-> Int
-> [String]
-> ((AbsolutePath, AbsolutePath)
    -> [DarcsFlag] -> [String] -> IO ())
-> ([DarcsFlag] -> IO (Either String ()))
-> ((AbsolutePath, AbsolutePath)
    -> [DarcsFlag] -> [String] -> IO [String])
-> ([DarcsFlag] -> AbsolutePath -> [String] -> IO [String])
-> [DarcsOptDescr DarcsFlag]
-> [DarcsOptDescr DarcsFlag]
-> [DarcsFlag]
-> ([DarcsFlag] -> [String])
-> DarcsCommand
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
    , commandAdvancedOptions :: [DarcsOptDescr DarcsFlag]
commandAdvancedOptions      = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Compression -> UseIndex -> UMask -> SetScriptsExecutable -> Any)
-> [DarcsOptDescr DarcsFlag]
forall (d :: * -> *) f a b. OptSpec d f a b -> [d f]
odesc OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Compression -> UseIndex -> UMask -> SetScriptsExecutable -> Any)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Compression -> UseIndex -> UMask -> SetScriptsExecutable -> a)
advancedOpts
    , commandBasicOptions :: [DarcsOptDescr DarcsFlag]
commandBasicOptions         = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Any)
-> [DarcsOptDescr DarcsFlag]
forall (d :: * -> *) f a b. OptSpec d f a b -> [d f]
odesc OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Any)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
basicOpts
    , commandDefaults :: [DarcsFlag]
commandDefaults             = OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> [DarcsFlag])
-> [DarcsFlag]
forall (d :: * -> *) f b. OptSpec d f [f] b -> [f]
defaultFlags OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> [DarcsFlag])
forall a.
DarcsOption
  a
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> a)
allOpts
    , commandCheckOptions :: [DarcsFlag] -> [String]
commandCheckOptions         = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> Any)
-> [DarcsFlag] -> [String]
forall (d :: * -> *) f a b. OptSpec d f a b -> [f] -> [String]
ocheck OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> Any)
forall a.
DarcsOption
  a
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> a)
allOpts
    }
  where
    fileArgs :: (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
fileArgs (AbsolutePath, AbsolutePath)
fps [DarcsFlag]
flags [String]
args =
      if (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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
basicOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  ([NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  Bool
PrimDarcsOption Bool
O.amendUnrecord
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  ([NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  Bool
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     ([MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     ([NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     ([MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  ([NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
PrimDarcsOption [NotInRemote]
O.notInRemote
      OptSpec
  DarcsOptDescr
  DarcsFlag
  ([MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
MatchOption
O.matchOneNontag
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
PrimDarcsOption TestChanges
O.testChanges
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe Bool)
O.interactive --True
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe String)
O.author
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
PrimDarcsOption Bool
O.selectAuthor
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe String)
O.patchname
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
PrimDarcsOption Bool
O.askDeps
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
     (Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
   -> LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
  (Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe AskLongComment)
O.askLongComment
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
     (Bool
      -> LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
  (LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
  (Bool
   -> LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
PrimDarcsOption Bool
O.keepDate
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> WithContext -> DiffAlgorithm -> a)
     (LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> WithContext -> DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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 -> WithContext -> DiffAlgorithm -> a)
  (LookFor -> Maybe String -> WithContext -> DiffAlgorithm -> a)
PrimDarcsOption LookFor
O.lookfor
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String -> WithContext -> DiffAlgorithm -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WithContext -> DiffAlgorithm -> a)
     (Maybe String -> WithContext -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WithContext -> DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
  (WithContext -> DiffAlgorithm -> a)
  (Maybe String -> WithContext -> DiffAlgorithm -> a)
PrimDarcsOption (Maybe String)
O.repoDir
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (WithContext -> DiffAlgorithm -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     (WithContext -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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)
  (WithContext -> DiffAlgorithm -> a)
PrimDarcsOption WithContext
O.withContext
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (DiffAlgorithm -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> 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
      -> LookFor
      -> Maybe String
      -> WithContext
      -> 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
  (Compression -> UseIndex -> UMask -> SetScriptsExecutable -> a)
advancedOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (UseIndex -> UMask -> SetScriptsExecutable -> a)
  Compression
PrimDarcsOption Compression
O.compress
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (UseIndex -> UMask -> SetScriptsExecutable -> a)
  Compression
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UMask -> SetScriptsExecutable -> a)
     (UseIndex -> UMask -> SetScriptsExecutable -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UMask -> SetScriptsExecutable -> a)
     (Compression -> UseIndex -> 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
  (UMask -> SetScriptsExecutable -> a)
  (UseIndex -> UMask -> SetScriptsExecutable -> a)
PrimDarcsOption UseIndex
O.useIndex
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (UMask -> SetScriptsExecutable -> a)
  (Compression -> UseIndex -> UMask -> SetScriptsExecutable -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (SetScriptsExecutable -> a)
     (UMask -> SetScriptsExecutable -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (SetScriptsExecutable -> a)
     (Compression -> UseIndex -> 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
  (SetScriptsExecutable -> a)
  (UMask -> SetScriptsExecutable -> a)
PrimDarcsOption UMask
O.umask
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (SetScriptsExecutable -> a)
  (Compression -> UseIndex -> UMask -> SetScriptsExecutable -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (SetScriptsExecutable -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     a
     (Compression -> UseIndex -> 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 :: DarcsOption
  a
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> a)
allOpts = DarcsOption
  (Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> a)
-> DarcsOption
     (UseCache -> HooksConfig -> Bool -> Bool -> Bool -> a)
     (Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> HooksConfig
      -> Bool
      -> Bool
      -> Bool
      -> a)
-> DarcsOption
     a
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> Maybe StdCmdAction
      -> Verbosity
      -> Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> HooksConfig
      -> Bool
      -> Bool
      -> Bool
      -> a)
forall b c a.
DarcsOption (Maybe StdCmdAction -> Verbosity -> b) c
-> DarcsOption
     (UseCache -> HooksConfig -> Bool -> Bool -> Bool -> a) b
-> DarcsOption a c
withStdOpts DarcsOption
  (Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> a)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> a)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
basicOpts DarcsOption
  (UseCache -> HooksConfig -> Bool -> Bool -> Bool -> a)
  (Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> HooksConfig
   -> Bool
   -> Bool
   -> Bool
   -> a)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Compression -> UseIndex -> UMask -> SetScriptsExecutable -> a)
advancedOpts
    config :: [DarcsFlag] -> AmendConfig
config = OptSpec
  DarcsOptDescr
  DarcsFlag
  AmendConfig
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
-> (Bool
    -> [NotInRemote]
    -> [MatchFlag]
    -> TestChanges
    -> Maybe Bool
    -> Maybe String
    -> Bool
    -> Maybe String
    -> Bool
    -> Maybe AskLongComment
    -> Bool
    -> LookFor
    -> Maybe String
    -> WithContext
    -> DiffAlgorithm
    -> Verbosity
    -> Compression
    -> UseIndex
    -> UMask
    -> SetScriptsExecutable
    -> UseCache
    -> AmendConfig)
-> [DarcsFlag]
-> AmendConfig
forall (d :: * -> *) f a b. OptSpec d f a b -> b -> [f] -> a
oparse (OptSpec
  DarcsOptDescr
  DarcsFlag
  (Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> a)
basicOpts OptSpec
  DarcsOptDescr
  DarcsFlag
  (Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> AmendConfig)
     (Verbosity
      -> Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> AmendConfig)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> AmendConfig)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> Verbosity
      -> Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> AmendConfig)
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
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
  (Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
PrimDarcsOption Verbosity
O.verbosity OptSpec
  DarcsOptDescr
  DarcsFlag
  (Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UseCache -> AmendConfig)
     (Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> AmendConfig)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UseCache -> AmendConfig)
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> Verbosity
      -> Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> AmendConfig)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (UseCache -> AmendConfig)
  (Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (Compression -> UseIndex -> UMask -> SetScriptsExecutable -> a)
advancedOpts OptSpec
  DarcsOptDescr
  DarcsFlag
  (UseCache -> AmendConfig)
  (Bool
   -> [NotInRemote]
   -> [MatchFlag]
   -> TestChanges
   -> Maybe Bool
   -> Maybe String
   -> Bool
   -> Maybe String
   -> Bool
   -> Maybe AskLongComment
   -> Bool
   -> LookFor
   -> Maybe String
   -> WithContext
   -> DiffAlgorithm
   -> Verbosity
   -> Compression
   -> UseIndex
   -> UMask
   -> SetScriptsExecutable
   -> UseCache
   -> AmendConfig)
-> OptSpec
     DarcsOptDescr DarcsFlag AmendConfig (UseCache -> AmendConfig)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     AmendConfig
     (Bool
      -> [NotInRemote]
      -> [MatchFlag]
      -> TestChanges
      -> Maybe Bool
      -> Maybe String
      -> Bool
      -> Maybe String
      -> Bool
      -> Maybe AskLongComment
      -> Bool
      -> LookFor
      -> Maybe String
      -> WithContext
      -> DiffAlgorithm
      -> Verbosity
      -> Compression
      -> UseIndex
      -> UMask
      -> SetScriptsExecutable
      -> UseCache
      -> AmendConfig)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr DarcsFlag AmendConfig (UseCache -> AmendConfig)
PrimDarcsOption UseCache
O.useCache) Bool
-> [NotInRemote]
-> [MatchFlag]
-> TestChanges
-> Maybe Bool
-> Maybe String
-> Bool
-> Maybe String
-> Bool
-> Maybe AskLongComment
-> Bool
-> LookFor
-> Maybe String
-> WithContext
-> DiffAlgorithm
-> Verbosity
-> Compression
-> UseIndex
-> UMask
-> SetScriptsExecutable
-> UseCache
-> AmendConfig
AmendConfig
    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 (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= AmendConfig -> Maybe [AnchoredPath] -> IO ()
doAmend ([DarcsFlag] -> AmendConfig
config [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 :: AmendConfig -> Maybe [AnchoredPath] -> IO ()
doAmend :: AmendConfig -> Maybe [AnchoredPath] -> IO ()
doAmend AmendConfig
cfg Maybe [AnchoredPath]
files =
  DryRun -> UseCache -> UpdatePending -> UMask -> RepoJob () -> IO ()
forall a.
DryRun -> UseCache -> UpdatePending -> UMask -> RepoJob a -> IO a
withRepoLock DryRun
NoDryRun (AmendConfig -> UseCache
useCache AmendConfig
cfg) UpdatePending
YesUpdatePending (AmendConfig -> UMask
umask AmendConfig
cfg) (RepoJob () -> IO ()) -> RepoJob () -> IO ()
forall a b. (a -> b) -> a -> b
$
      (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
 (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
 Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a.
(forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
 (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
 Repository rt p wR wU wR -> IO a)
-> RepoJob a
RebaseAwareJob ((forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
  (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
  Repository rt p wR wU wR -> IO ())
 -> RepoJob ())
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
    Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a b. (a -> b) -> a -> b
$ \(Repository rt p wR wU wR
repository :: Repository rt p wR wU wR) -> do
    PatchSet rt p Origin wR
patchSet <- 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
    FlippedSeal RL (PatchInfoAnd rt p) wX wR
patches <- AmendConfig
-> Repository rt p wR wU wR
-> PatchSet rt p Origin wR
-> IO (FlippedSeal (RL (PatchInfoAnd rt p)) wR)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p) =>
AmendConfig
-> Repository rt p wR wU wT
-> PatchSet rt p Origin wR
-> IO (FlippedSeal (RL (PatchInfoAnd rt p)) wR)
filterNotInRemote AmendConfig
cfg Repository rt p wR wU wR
repository PatchSet rt p Origin wR
patchSet
    String
-> RL (PatchInfoAnd rt p) wX wR
-> PatchSelectionOptions
-> (forall wA.
    (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wA wR -> IO ())
-> IO ()
forall (p :: * -> * -> *) wO wR.
(Commute p, Matchable p, ShowPatch p, ShowContextPatch p,
 ApplyState p ~ Tree) =>
String
-> RL p wO wR
-> PatchSelectionOptions
-> (forall wA. (:>) (FL p) p wA wR -> IO ())
-> IO ()
withSelectedPatchFromList String
"amend" RL (PatchInfoAnd rt p) wX wR
patches (AmendConfig -> PatchSelectionOptions
patchSelOpts AmendConfig
cfg) ((forall wA.
  (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wA wR -> IO ())
 -> IO ())
-> (forall wA.
    (:>) (FL (PatchInfoAnd rt p)) (PatchInfoAnd rt p) wA wR -> IO ())
-> IO ()
forall a b. (a -> b) -> a -> b
$ \ (FL (PatchInfoAnd rt p) wA wZ
_ :> PatchInfoAnd rt p wZ wR
oldp) -> do
        Verbosity -> Maybe [AnchoredPath] -> String -> IO ()
announceFiles (AmendConfig -> Verbosity
verbosity AmendConfig
cfg) Maybe [AnchoredPath]
files String
"Amending changes in"
        -- auxiliary function needed because the witness types differ for the isTag case
        Tree IO
pristine <- Repository rt p wR wU wR -> IO (Tree IO)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
Repository rt p wR wU wT -> IO (Tree IO)
readRecorded Repository rt p wR wU wR
repository
        FL (PrimOf p) wR wZ
pending :> FL (PrimOf p) wZ wU
working <-
          (UseIndex, ScanKnown, DiffAlgorithm)
-> LookForMoves
-> LookForReplaces
-> Repository rt p wR wU wR
-> Maybe [AnchoredPath]
-> IO ((:>) (FL (PrimOf p)) (FL (PrimOf p)) wR wU)
forall (p :: * -> * -> *) (rt :: RepoType) wR wU.
(RepoPatch p, ApplyState p ~ Tree) =>
(UseIndex, ScanKnown, DiffAlgorithm)
-> LookForMoves
-> LookForReplaces
-> Repository rt p wR wU wR
-> Maybe [AnchoredPath]
-> IO ((:>) (FL (PrimOf p)) (FL (PrimOf p)) wR wU)
readPendingAndWorking
            (AmendConfig -> (UseIndex, ScanKnown, DiffAlgorithm)
diffingOpts AmendConfig
cfg)
            (LookFor -> LookForMoves
O.moves (AmendConfig -> LookFor
lookfor AmendConfig
cfg))
            (LookFor -> LookForReplaces
O.replaces (AmendConfig -> LookFor
lookfor AmendConfig
cfg))
            Repository rt p wR wU wR
repository
            Maybe [AnchoredPath]
files
        let go :: forall wU1 . FL (PrimOf p) wR wU1 -> IO ()
            go :: FL (PrimOf p) wR wU1 -> IO ()
go FL (PrimOf p) wR wU1
NilFL | Bool -> Bool
not (AmendConfig -> Bool
hasEditMetadata AmendConfig
cfg) =
              AmendConfig -> Doc -> IO ()
putInfo AmendConfig
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]
-> Maybe (Tree IO)
-> SelectionConfig (PrimOf p)
forall (prim :: * -> * -> *).
WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter prim)
-> Maybe [AnchoredPath]
-> Maybe (Tree IO)
-> SelectionConfig prim
selectionConfigPrim WhichChanges
First String
"record"
                            (AmendConfig -> PatchSelectionOptions
patchSelOpts AmendConfig
cfg)
                            --([All,Unified] `intersect` opts)
                            (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 (AmendConfig -> DiffAlgorithm
diffAlgorithm AmendConfig
cfg)))
                            Maybe [AnchoredPath]
files
                            (Tree IO -> Maybe (Tree IO)
forall a. a -> Maybe a
Just Tree IO
pristine)
                 (FL (PrimOf p) wR wZ
chosenPatches :> FL (PrimOf p) wZ wU1
_) <- 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
                 AmendConfig
-> Repository rt p wR wU wR
-> PatchInfoAnd rt p wZ wR
-> FL (PrimOf p) wR wZ
-> FL (PrimOf p) wR wZ
-> FL (PrimOf p) wZ wU
-> IO ()
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT wX wY wP.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
AmendConfig
-> Repository rt p wR wU wT
-> PatchInfoAnd rt p wX wT
-> FL (PrimOf p) wT wY
-> FL (PrimOf p) wT wP
-> FL (PrimOf p) wP wU
-> IO ()
addChangesToPatch AmendConfig
cfg Repository rt p wR wU wR
repository PatchInfoAnd rt p wZ wR
oldp FL (PrimOf p) wR wZ
chosenPatches FL (PrimOf p) wR wZ
pending FL (PrimOf p) wZ wU
working
        if Bool -> Bool
not (PatchInfo -> Bool
isTag (PatchInfoAnd rt p wZ wR -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wZ wR
oldp))
              -- amending a normal patch
           then if AmendConfig -> Bool
amendUnrecord AmendConfig
cfg
                   then do let selection_config :: SelectionConfig (PrimOf p)
selection_config =
                                  WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PrimOf p))
-> Maybe [AnchoredPath]
-> Maybe (Tree IO)
-> SelectionConfig (PrimOf p)
forall (prim :: * -> * -> *).
WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter prim)
-> Maybe [AnchoredPath]
-> Maybe (Tree IO)
-> SelectionConfig prim
selectionConfigPrim WhichChanges
Last String
"unrecord"
                                      (AmendConfig -> PatchSelectionOptions
patchSelOpts AmendConfig
cfg)
                                      -- ([All,Unified] `intersect` opts)
                                      (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 (AmendConfig -> DiffAlgorithm
diffAlgorithm AmendConfig
cfg)))
                                      Maybe [AnchoredPath]
files
                                      (Tree IO -> Maybe (Tree IO)
forall a. a -> Maybe a
Just Tree IO
pristine)
                           (FL (PrimOf p) wZ wZ
_ :> FL (PrimOf p) wZ wR
chosenPrims) <- FL (PrimOf p) wZ wR
-> SelectionConfig (PrimOf p)
-> IO ((:>) (FL (PrimOf p)) (FL (PrimOf p)) wZ wR)
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 (PatchInfoAnd rt p wZ wR -> FL (PrimOf (PatchInfoAnd rt p)) wZ wR
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect PatchInfoAnd rt p wZ wR
oldp) SelectionConfig (PrimOf p)
selection_config
                           let invPrims :: FL (PrimOf p) wR wZ
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)
                           AmendConfig
-> Repository rt p wR wU wR
-> PatchInfoAnd rt p wZ wR
-> FL (PrimOf p) wR wZ
-> FL (PrimOf p) wR wZ
-> FL (PrimOf p) wZ wU
-> IO ()
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT wX wY wP.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
AmendConfig
-> Repository rt p wR wU wT
-> PatchInfoAnd rt p wX wT
-> FL (PrimOf p) wT wY
-> FL (PrimOf p) wT wP
-> FL (PrimOf p) wP wU
-> IO ()
addChangesToPatch AmendConfig
cfg Repository rt p wR wU wR
repository PatchInfoAnd rt p wZ wR
oldp FL (PrimOf p) wR wZ
invPrims FL (PrimOf p) wR wZ
pending FL (PrimOf p) wZ wU
working
                   else FL (PrimOf p) wR wU -> IO ()
forall wU1. FL (PrimOf p) wR wU1 -> IO ()
go (FL (PrimOf p) wR wU -> FL (PrimOf p) wR wU
forall (prim :: * -> * -> *) wX wY.
PrimCanonize prim =>
FL prim wX wY -> FL prim wX wY
sortCoalesceFL (FL (PrimOf p) wR wZ
pending FL (PrimOf p) wR wZ -> FL (PrimOf p) wZ wU -> FL (PrimOf p) wR wU
forall (a :: * -> * -> *) wX wY wZ.
FL a wX wY -> FL a wY wZ -> FL a wX wZ
+>+ FL (PrimOf p) wZ wU
working))
              -- amending a tag
           else if AmendConfig -> Bool
hasEditMetadata AmendConfig
cfg Bool -> Bool -> Bool
&& Maybe [AnchoredPath] -> Bool
forall a. Maybe a -> Bool
isNothing Maybe [AnchoredPath]
files
                        -- the user is not trying to add new changes to the tag so there is
                        -- no reason to warn.
                   then FL (PrimOf p) wR wR -> IO ()
forall wU1. FL (PrimOf p) wR wU1 -> IO ()
go FL (PrimOf p) wR wR
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
                        -- the user is trying to add new changes to a tag.
                   else do if AmendConfig -> Bool
hasEditMetadata AmendConfig
cfg
                                -- the user already knows that it is possible to edit tag metadata,
                                -- note that s/he is providing editing options!
                             then Doc -> IO ()
ePutDocLn Doc
"You cannot add new changes to a tag."
                                -- the user may not be aware that s/he can edit tag metadata.
                             else Doc -> IO ()
ePutDocLn Doc
"You cannot add new changes to a tag, but you are allowed to edit tag's metadata (see darcs help amend)."
                           FL (PrimOf p) wR wR -> IO ()
forall wU1. FL (PrimOf p) wR wU1 -> IO ()
go FL (PrimOf p) wR wR
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL


addChangesToPatch :: forall rt p wR wU wT wX wY wP
                   . (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree)
                  => AmendConfig
                  -> Repository rt p wR wU wT
                  -> PatchInfoAnd rt p wX wT
                  -> FL (PrimOf p) wT wY
                  -> FL (PrimOf p) wT wP
                  -> FL (PrimOf p) wP wU
                  -> IO ()
addChangesToPatch :: AmendConfig
-> Repository rt p wR wU wT
-> PatchInfoAnd rt p wX wT
-> FL (PrimOf p) wT wY
-> FL (PrimOf p) wT wP
-> FL (PrimOf p) wP wU
-> IO ()
addChangesToPatch AmendConfig
cfg Repository rt p wR wU wT
_repository PatchInfoAnd rt p wX wT
oldp FL (PrimOf p) wT wY
chs FL (PrimOf p) wT wP
pending FL (PrimOf p) wP wU
working =
  if FL (PrimOf p) wT wY -> Bool
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> Bool
nullFL FL (PrimOf p) wT wY
chs Bool -> Bool -> Bool
&& Bool -> Bool
not (AmendConfig -> Bool
hasEditMetadata AmendConfig
cfg)
    then AmendConfig -> Doc -> IO ()
putInfo AmendConfig
cfg Doc
"You don't want to record anything!"
    else do
      Repository rt p wR wU wT -> IO ()
forall t. t -> IO ()
invalidateIndex Repository rt p wR wU wT
_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 the normal commute rules for the rebase
      -- state 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 rt p wR wU wY
_repository, (Maybe String
mlogf, PatchInfoAnd rt p wX wY
newp)) <-
        Repository rt p wR wU wT
-> (Repository rt p wR wU wT
    -> IO
         (Repository rt p wR wU wY, FL (RebaseFixup (PrimOf p)) wY wT,
          (Maybe String, PatchInfoAnd rt p wX wY)))
-> IO
     (Repository rt p wR wU wY, (Maybe String, PatchInfoAnd rt p wX wY))
forall (rt :: RepoType) (p :: * -> * -> *) x wR wU wT1 wT2.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wT1
-> (Repository rt p wR wU wT1
    -> IO
         (Repository rt p wR wU wT2, FL (RebaseFixup (PrimOf p)) wT2 wT1,
          x))
-> IO (Repository rt p wR wU wT2, x)
withManualRebaseUpdate Repository rt p wR wU wT
_repository ((Repository rt p wR wU wT
  -> IO
       (Repository rt p wR wU wY, FL (RebaseFixup (PrimOf p)) wY wT,
        (Maybe String, PatchInfoAnd rt p wX wY)))
 -> IO
      (Repository rt p wR wU wY,
       (Maybe String, PatchInfoAnd rt p wX wY)))
-> (Repository rt p wR wU wT
    -> IO
         (Repository rt p wR wU wY, FL (RebaseFixup (PrimOf p)) wY wT,
          (Maybe String, PatchInfoAnd rt p wX wY)))
-> IO
     (Repository rt p wR wU wY, (Maybe String, PatchInfoAnd rt p wX wY))
forall a b. (a -> b) -> a -> b
$ \Repository rt p wR wU wT
_repository -> do
          -- Note we pass NoUpdatePending here and below when re-adding the
          -- amended patch, and instead fix pending explicitly further below.
          Repository rt p wR wU wX
_repository <-
            Repository rt p wR wU wT
-> Compression
-> UpdatePending
-> FL (PatchInfoAnd rt p) wX wT
-> IO (Repository rt p wR wU wX)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT wX.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wT
-> Compression
-> UpdatePending
-> FL (PatchInfoAnd rt p) wX wT
-> IO (Repository rt p wR wU wX)
tentativelyRemovePatches
              Repository rt p wR wU wT
_repository
              (AmendConfig -> Compression
compress AmendConfig
cfg)
              UpdatePending
NoUpdatePending
              (PatchInfoAnd rt p wX wT
oldp PatchInfoAnd rt p wX wT
-> FL (PatchInfoAnd rt p) wT wT -> FL (PatchInfoAnd rt p) wX wT
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (PatchInfoAnd rt p) wT wT
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL)
          (Maybe String
mlogf, PatchInfoAnd rt p wX wY
newp) <-
            HijackOptions
-> HijackT IO (Maybe String, PatchInfoAnd rt p wX wY)
-> IO (Maybe String, PatchInfoAnd rt p wX wY)
forall (m :: * -> *) a.
Monad m =>
HijackOptions -> HijackT m a -> m a
runHijackT HijackOptions
AlwaysRequestHijackPermission (HijackT IO (Maybe String, PatchInfoAnd rt p wX wY)
 -> IO (Maybe String, PatchInfoAnd rt p wX wY))
-> HijackT IO (Maybe String, PatchInfoAnd rt p wX wY)
-> IO (Maybe String, PatchInfoAnd rt p wX wY)
forall a b. (a -> b) -> a -> b
$
            String
-> AskAboutDeps rt p wR wU wX
-> PatchSelectionOptions
-> DiffAlgorithm
-> Bool
-> Bool
-> Maybe String
-> Maybe String
-> Maybe AskLongComment
-> Named (PrimOf p) wX wT
-> FL (PrimOf p) wT wY
-> HijackT IO (Maybe String, PatchInfoAnd rt p wX wY)
forall (rt :: RepoType) (p :: * -> * -> *) wX wY wR wU wT.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
String
-> AskAboutDeps rt p wR wU wT
-> PatchSelectionOptions
-> DiffAlgorithm
-> Bool
-> Bool
-> Maybe String
-> Maybe String
-> Maybe AskLongComment
-> Named (PrimOf p) wT wX
-> FL (PrimOf p) wX wY
-> HijackT IO (Maybe String, PatchInfoAnd rt p wT wY)
updatePatchHeader
              String
"amend"
              (if AmendConfig -> Bool
askDeps AmendConfig
cfg
                 then Repository rt p wR wU wX -> AskAboutDeps rt p wR wU wX
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
Repository rt p wR wU wT -> AskAboutDeps rt p wR wU wT
AskAboutDeps Repository rt p wR wU wX
_repository
                 else AskAboutDeps rt p wR wU wX
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
AskAboutDeps rt p wR wU wT
NoAskAboutDeps)
              (AmendConfig -> PatchSelectionOptions
patchSelOpts AmendConfig
cfg)
              (AmendConfig -> DiffAlgorithm
diffAlgorithm AmendConfig
cfg)
              (AmendConfig -> Bool
keepDate AmendConfig
cfg)
              (AmendConfig -> Bool
selectAuthor AmendConfig
cfg)
              (AmendConfig -> Maybe String
author AmendConfig
cfg)
              (AmendConfig -> Maybe String
patchname AmendConfig
cfg)
              (AmendConfig -> Maybe AskLongComment
askLongComment AmendConfig
cfg)
              ((FL p wX wT -> FL (PrimOf p) wX wT)
-> Named p wX wT -> Named (PrimOf p) wX wT
forall (p :: * -> * -> *) wA wB (q :: * -> * -> *) wC wD.
(FL p wA wB -> FL q wC wD) -> Named p wA wB -> Named q wC wD
fmapFL_Named FL p wX wT -> FL (PrimOf p) wX wT
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect (PatchInfoAnd rt p wX wT -> Named p wX wT
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> p wA wB
hopefully PatchInfoAnd rt p wX wT
oldp))
              FL (PrimOf p) wT wY
chs
          let fixups :: FL (RebaseFixup (PrimOf p)) wY wZ
fixups =
                (forall wW wY. PrimOf p wW wY -> RebaseFixup (PrimOf p) wW wY)
-> FL (PrimOf p) wY wT -> FL (RebaseFixup (PrimOf p)) wY wT
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL 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) wT wY -> FL (PrimOf p) wY wT
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL (PrimOf p) wT wY
chs) FL (RebaseFixup (PrimOf p)) wY wT
-> FL (RebaseFixup (PrimOf p)) wT 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 wT wZ -> RebaseFixup (PrimOf p) wT wZ
forall wX wY (prim :: * -> * -> *).
RebaseName wX wY -> RebaseFixup prim wX wY
NameFixup (PatchInfo -> PatchInfo -> RebaseName wT wZ
forall wX wY. PatchInfo -> PatchInfo -> RebaseName wX wY
Rename (PatchInfoAnd rt p wX wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wX wY
newp) (PatchInfoAnd rt p wX wT -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAndG rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wX wT
oldp)) RebaseFixup (PrimOf p) wT wZ
-> FL (RebaseFixup (PrimOf p)) wZ wZ
-> FL (RebaseFixup (PrimOf p)) wT 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
          PatchInfoAnd rt p wX wY -> IO ()
forall (p :: * -> * -> *) wX wY. PatchInspect p => p wX wY -> IO ()
setEnvDarcsFiles PatchInfoAnd rt p wX wY
newp
          Repository rt p wR wU wY
_repository <-
            Repository rt p wR wU wX
-> Compression
-> Verbosity
-> UpdatePending
-> PatchInfoAnd rt p wX wY
-> IO (Repository rt p wR wU wY)
forall (p :: * -> * -> *) (rt :: RepoType) wR wU wT wY.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wT
-> Compression
-> Verbosity
-> UpdatePending
-> PatchInfoAnd rt p wT wY
-> IO (Repository rt p wR wU wY)
tentativelyAddPatch
              Repository rt p wR wU wX
_repository
              (AmendConfig -> Compression
compress AmendConfig
cfg)
              (AmendConfig -> Verbosity
verbosity AmendConfig
cfg)
              UpdatePending
NoUpdatePending
              PatchInfoAnd rt p wX wY
newp
          (Repository rt p wR wU wY, FL (RebaseFixup (PrimOf p)) wY wT,
 (Maybe String, PatchInfoAnd rt p wX wY))
-> IO
     (Repository rt p wR wU wY, FL (RebaseFixup (PrimOf p)) wY wT,
      (Maybe String, PatchInfoAnd rt p wX wY))
forall (m :: * -> *) a. Monad m => a -> m a
return (Repository rt p wR wU wY
_repository, FL (RebaseFixup (PrimOf p)) wY wT
forall wZ. FL (RebaseFixup (PrimOf p)) wY wZ
fixups, (Maybe String
mlogf, PatchInfoAnd rt p wX wY
newp))
      let failmsg :: String
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
      Repository rt p wR wU wY
-> Verbosity
-> TestChanges
-> SetScriptsExecutable
-> Bool
-> String
-> String
-> Maybe String
-> IO ()
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
Repository rt p wR wU wT
-> Verbosity
-> TestChanges
-> SetScriptsExecutable
-> Bool
-> String
-> String
-> Maybe String
-> IO ()
testTentativeAndMaybeExit
        Repository rt p wR wU wY
_repository
        (AmendConfig -> Verbosity
verbosity AmendConfig
cfg)
        (AmendConfig -> TestChanges
testChanges AmendConfig
cfg)
        (AmendConfig -> SetScriptsExecutable
sse AmendConfig
cfg)
        (AmendConfig -> Bool
isInteractive AmendConfig
cfg)
        (String
"you have a bad patch: '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ PatchInfoAnd rt p wX wY -> String
forall (rt :: RepoType) (p :: * -> * -> *) wX wY.
PatchInfoAnd rt p wX wY -> String
patchDesc PatchInfoAnd rt p wX wY
newp String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'")
        String
"amend it"
        (String -> Maybe String
forall a. a -> Maybe a
Just String
failmsg)
      Repository rt p wR wU wY
-> FL (PrimOf p) wT wY
-> FL (PrimOf p) wT wP
-> FL (PrimOf p) wP wU
-> IO ()
forall (rt :: RepoType) (p :: * -> * -> *) wR wO wT wP wU.
RepoPatch p =>
Repository rt p wR wU wT
-> FL (PrimOf p) wO wT
-> FL (PrimOf p) wO wP
-> FL (PrimOf p) wP wU
-> IO ()
tentativelyRemoveFromPW Repository rt p wR wU wY
_repository FL (PrimOf p) wT wY
chs FL (PrimOf p) wT wP
pending FL (PrimOf p) wP wU
working
      Repository rt p wY wU wY
_repository <-
        Repository rt p wR wU wY
-> UpdatePending -> Compression -> IO (Repository rt p wY wU wY)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wT
-> UpdatePending -> Compression -> IO (Repository rt p wT wU wT)
finalizeRepositoryChanges Repository rt p wR wU wY
_repository UpdatePending
YesUpdatePending (AmendConfig -> Compression
compress AmendConfig
cfg)
          IO (Repository rt p wY wU wY)
-> String -> IO (Repository rt p wY wU wY)
forall a. IO a -> String -> IO a
`clarifyErrors` String
failmsg
      case AmendConfig -> Verbosity
verbosity AmendConfig
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 rt p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description PatchInfoAnd rt p wX wY
newp
        Verbosity
_ -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      FL (PatchInfoAnd rt p) wX wY -> IO ()
forall (p :: * -> * -> *) (rt :: RepoType) wX wY.
RepoPatch p =>
FL (PatchInfoAnd rt p) wX wY -> IO ()
setEnvDarcsPatches (PatchInfoAnd rt p wX wY
newp PatchInfoAnd rt p wX wY
-> FL (PatchInfoAnd rt p) wY wY -> FL (PatchInfoAnd rt p) wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL (PatchInfoAnd rt p) wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL)

filterNotInRemote :: (IsRepoType rt, RepoPatch p)
                  => AmendConfig
                  -> Repository rt p wR wU wT
                  -> PatchSet rt p Origin wR
                  -> IO (FlippedSeal (RL (PatchInfoAnd rt p)) wR)
filterNotInRemote :: AmendConfig
-> Repository rt p wR wU wT
-> PatchSet rt p Origin wR
-> IO (FlippedSeal (RL (PatchInfoAnd rt p)) wR)
filterNotInRemote AmendConfig
cfg Repository rt p wR wU wT
repository PatchSet rt p Origin wR
patchSet = do
    [String]
nirs <- (NotInRemote -> IO String) -> [NotInRemote] -> IO [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM NotInRemote -> IO String
getNotInRemotePath (AmendConfig -> [NotInRemote]
notInRemote AmendConfig
cfg)
    if [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
nirs
      then
        FlippedSeal (RL (PatchInfoAnd rt p)) wR
-> IO (FlippedSeal (RL (PatchInfoAnd rt p)) wR)
forall (m :: * -> *) a. Monad m => a -> m a
return (RL (PatchInfoAnd rt p) Origin wR
-> FlippedSeal (RL (PatchInfoAnd rt p)) wR
forall (a :: * -> * -> *) wX wY. a wX wY -> FlippedSeal a wY
FlippedSeal (PatchSet rt p Origin wR -> RL (PatchInfoAnd rt p) Origin wR
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
PatchSet rt p wStart wX -> RL (PatchInfoAnd rt p) wStart wX
patchSet2RL PatchSet rt p Origin wR
patchSet))
      else do
        AmendConfig -> Doc -> IO ()
putInfo AmendConfig
cfg (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$
          Doc
"Determining patches not in" Doc -> Doc -> Doc
<+> [String] -> Doc
anyOfClause [String]
nirs Doc -> Doc -> Doc
$$ Int -> [String] -> Doc
itemizeVertical Int
2 [String]
nirs
        Sealed PatchSet rt p Origin wX
thems <- [Sealed (PatchSet rt p Origin)] -> Sealed (PatchSet rt p Origin)
forall (p :: * -> * -> *) (rt :: RepoType).
(Commute p, Merge p, Eq2 p) =>
[SealedPatchSet rt p Origin] -> SealedPatchSet rt p Origin
patchSetUnion ([Sealed (PatchSet rt p Origin)] -> Sealed (PatchSet rt p Origin))
-> IO [Sealed (PatchSet rt p Origin)]
-> IO (Sealed (PatchSet rt p Origin))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` (String -> IO (Sealed (PatchSet rt p Origin)))
-> [String] -> IO [Sealed (PatchSet rt p Origin)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> IO (Sealed (PatchSet rt p Origin))
readNir [String]
nirs
        PatchSet rt p Origin wZ
_ :> FL (PatchInfoAnd rt p) wZ wR
only_ours <- (:>) (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) wX wY.
Commute p =>
PatchSet rt p Origin wX
-> PatchSet rt p Origin wY
-> (:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) Origin wX
findCommonWithThem PatchSet rt p Origin wR
patchSet PatchSet rt p Origin wX
thems
        FlippedSeal (RL (PatchInfoAnd rt p)) wR
-> IO (FlippedSeal (RL (PatchInfoAnd rt p)) wR)
forall (m :: * -> *) a. Monad m => a -> m a
return (RL (PatchInfoAnd rt p) wZ wR
-> FlippedSeal (RL (PatchInfoAnd rt p)) wR
forall (a :: * -> * -> *) wX wY. a wX wY -> FlippedSeal a wY
FlippedSeal (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
only_ours))
  where
    readNir :: String -> IO (Sealed (PatchSet rt p Origin))
readNir String
loc = do
      Repository rt p Any Any Any
repo <- ReadingOrWriting
-> Repository rt p wR wU wT
-> UseCache
-> String
-> IO (Repository rt p Any Any Any)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT vR vU vT.
ReadingOrWriting
-> Repository rt p wR wU wT
-> UseCache
-> String
-> IO (Repository rt p vR vU vT)
identifyRepositoryFor ReadingOrWriting
Reading Repository rt p wR wU wT
repository (AmendConfig -> UseCache
useCache AmendConfig
cfg) String
loc
      PatchSet rt p Origin Any
rps <- Repository rt p Any Any Any -> IO (PatchSet rt p Origin Any)
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 Any Any Any
repo
      Sealed (PatchSet rt p Origin) -> IO (Sealed (PatchSet rt p Origin))
forall (m :: * -> *) a. Monad m => a -> m a
return (PatchSet rt p Origin Any -> Sealed (PatchSet rt p Origin)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed PatchSet rt p Origin Any
rps)
    getNotInRemotePath :: NotInRemote -> IO String
getNotInRemotePath (O.NotInRemotePath String
p) = String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
p
    getNotInRemotePath NotInRemote
O.NotInDefaultRepo = do
        Maybe String
defaultRepo <- IO (Maybe String)
getDefaultRepo
        let err :: IO a
err = 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
        IO String -> (String -> IO String) -> Maybe String -> IO String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO String
forall a. IO a
err String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
defaultRepo

hasEditMetadata :: AmendConfig -> Bool
hasEditMetadata :: AmendConfig -> Bool
hasEditMetadata AmendConfig
cfg = Maybe String -> Bool
forall a. Maybe a -> Bool
isJust (AmendConfig -> Maybe String
author AmendConfig
cfg)
                    Bool -> Bool -> Bool
|| AmendConfig -> Bool
selectAuthor AmendConfig
cfg
                    Bool -> Bool -> Bool
|| Maybe String -> Bool
forall a. Maybe a -> Bool
isJust (AmendConfig -> Maybe String
patchname AmendConfig
cfg)
                    Bool -> Bool -> Bool
|| AmendConfig -> Maybe AskLongComment
askLongComment AmendConfig
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
|| AmendConfig -> Maybe AskLongComment
askLongComment AmendConfig
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
|| AmendConfig -> Bool
askDeps AmendConfig
cfg

-- hasEditMetadata []                    = False
-- hasEditMetadata (Author _:_)          = True
-- hasEditMetadata (SelectAuthor:_)      = True
-- hasEditMetadata (LogFile _:_)         = True -- ??? not listed as an option for amend
-- hasEditMetadata (PatchName _:_)       = True
-- hasEditMetadata (EditLongComment:_)   = True
-- hasEditMetadata (PromptLongComment:_) = True
-- hasEditMetadata (AskDeps:_)           = True
-- hasEditMetadata (_:fs)                = hasEditMetadata fs


patchSelOpts :: AmendConfig -> S.PatchSelectionOptions
patchSelOpts :: AmendConfig -> PatchSelectionOptions
patchSelOpts AmendConfig
cfg = PatchSelectionOptions :: Verbosity
-> [MatchFlag]
-> Bool
-> SelectDeps
-> WithSummary
-> WithContext
-> PatchSelectionOptions
S.PatchSelectionOptions
    { verbosity :: Verbosity
S.verbosity = AmendConfig -> Verbosity
verbosity AmendConfig
cfg
    , matchFlags :: [MatchFlag]
S.matchFlags = AmendConfig -> [MatchFlag]
matchFlags AmendConfig
cfg
    , interactive :: Bool
S.interactive = AmendConfig -> Bool
isInteractive AmendConfig
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
    , withContext :: WithContext
S.withContext = AmendConfig -> WithContext
withContext AmendConfig
cfg
    }

diffingOpts :: AmendConfig -> (O.UseIndex, O.ScanKnown, O.DiffAlgorithm)
diffingOpts :: AmendConfig -> (UseIndex, ScanKnown, DiffAlgorithm)
diffingOpts AmendConfig
cfg = UseIndex
-> LookForAdds
-> IncludeBoring
-> DiffAlgorithm
-> (UseIndex, ScanKnown, DiffAlgorithm)
diffOpts (AmendConfig -> UseIndex
useIndex AmendConfig
cfg) (LookFor -> LookForAdds
O.adds (AmendConfig -> LookFor
lookfor AmendConfig
cfg)) IncludeBoring
O.NoIncludeBoring (AmendConfig -> DiffAlgorithm
diffAlgorithm AmendConfig
cfg)

isInteractive :: AmendConfig -> Bool
isInteractive :: AmendConfig -> Bool
isInteractive = 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 (Maybe Bool -> Bool)
-> (AmendConfig -> Maybe Bool) -> AmendConfig -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AmendConfig -> Maybe Bool
interactive

putInfo :: AmendConfig -> Doc -> IO ()
putInfo :: AmendConfig -> Doc -> IO ()
putInfo AmendConfig
cfg Doc
what = Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (AmendConfig -> Verbosity
verbosity AmendConfig
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