1 %  Copyright (C) 2002-2004 David Roundy
    2 %
    3 %  This program is free software; you can redistribute it and/or modify
    4 %  it under the terms of the GNU General Public License as published by
    5 %  the Free Software Foundation; either version 2, or (at your option)
    6 %  any later version.
    7 %
    8 %  This program is distributed in the hope that it will be useful,
    9 %  but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 %  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11 %  GNU General Public License for more details.
   12 %
   13 %  You should have received a copy of the GNU General Public License
   14 %  along with this program; see the file COPYING.  If not, write to
   15 %  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   16 %  Boston, MA 02110-1301, USA.
   17 
   18 \begin{code}
   19 {-# OPTIONS_GHC -cpp #-}
   20 {-# LANGUAGE CPP #-}
   21 
   22 #include "gadts.h"
   23 
   24 module Darcs.Arguments ( DarcsFlag( .. ), flagToString,
   25                          maxCount,
   26                          isin, arein,
   27                          definePatches, defineChanges,
   28                          fixFilePathOrStd, fixUrl,
   29                          fixSubPaths, areFileArgs,
   30                          DarcsOption( .. ), option_from_darcsoption,
   31                          help, list_options, list_files,
   32                          any_verbosity, disable, restrict_paths,
   33                          notest, test, working_repo_dir,
   34                          testByDefault,
   35                          remote_repo,
   36                          leave_test_dir,
   37                          possibly_remote_repo_dir, get_repourl,
   38                          list_registered_files, list_unregistered_files,
   39                          author, get_author, get_easy_author, get_sendmail_cmd,
   40                          patchname_option, distname_option,
   41                          logfile, rmlogfile, from_opt, subject, get_subject,
   42                          in_reply_to, get_in_reply_to,
   43                          target, cc, get_cc, output, output_auto_name,
   44                          recursive, inventory_choices, get_inventory_choices,
   45                          askdeps, ignoretimes, lookforadds,
   46                          ask_long_comment, sendmail_cmd,
   47                          environmentHelpSendmail,
   48                          sign, verify, edit_description,
   49                          reponame, creatorhash,
   50                          apply_conflict_options, reply,
   51                          pull_conflict_options, use_external_merge,
   52                          deps_sel, nocompress,
   53                          uncompress_nocompress, repo_combinator,
   54                          options_latex, reorder_patches,
   55                          noskip_boring, allow_problematic_filenames,
   56                          applyas, human_readable,
   57                          changes_reverse, only_to_files,
   58                          changes_format, match_one_context, match_one_nontag,
   59                          match_maxcount,
   60                          send_to_context,
   61                          get_context,
   62                          pipe_interactive, all_interactive,
   63                          all_pipe_interactive,
   64                          summary, unified, tokens,
   65                          partial, partial_check,
   66                          diff_cmd_flag, diffflags, unidiff, xmloutput,
   67                          force_replace, dry_run, dry_run_noxml,
   68                          print_dry_run_message_and_exit, showFriendly,
   69                          match_one, match_several, match_range,
   70                          match_several_or_range, happy_forwarding,
   71                          match_several_or_last,
   72                          set_default,
   73                          fancy_move_add,
   74                          set_scripts_executable,
   75                          sibling, flagsToSiblings, relink, relink_pristine, nolinks,
   76                          files, directories, pending,
   77                          posthook_cmd, posthook_prompt,
   78                          get_posthook_cmd,
   79                          prehook_cmd, prehook_prompt,
   80                          get_prehook_cmd, nullFlag,
   81                          umask_option,
   82                          store_in_memory,
   83                          patch_select_flag,
   84                          network_options, no_cache,
   85                          allow_unrelated_repos,
   86                          check_or_repair, just_this_repo
   87                       ) where
   88 import System.Console.GetOpt
   89 import System.Directory ( doesDirectoryExist )
   90 import Data.List ( (\\), nub )
   91 import Data.Maybe ( fromMaybe, listToMaybe )
   92 import System.Exit ( ExitCode(ExitSuccess), exitWith )
   93 import Data.Maybe ( catMaybes )
   94 import Control.Monad ( when, unless )
   95 import Data.Char ( isDigit )
   96 #ifndef WIN32
   97 import Printer ( renderString )
   98 import System.Posix.Env ( setEnv )
   99 import Darcs.Patch ( list_touched_files )
  100 import Progress ( beginTedious, endTedious, tediousSize, finishedOneIO )
  101 #endif
  102 
  103 import Darcs.Hopefully ( PatchInfoAnd, info, hopefullyM )
  104 import Darcs.Patch ( RepoPatch, Patchy, showNicely, description, xml_summary )
  105 import Darcs.Patch.Info ( to_xml )
  106 import Darcs.Ordered ( FL, mapFL )
  107 import qualified Darcs.Patch ( summary )
  108 import Darcs.Utils ( askUser, maybeGetEnv, firstNotBlank, firstJustIO,
  109                      withCurrentDirectory )
  110 import Darcs.Repository.Prefs ( boring_file_filter, get_preflist, get_global )
  111 import Darcs.URL ( is_file )
  112 import Darcs.RepoPath ( AbsolutePath, AbsolutePathOrStd, SubPath, toFilePath,
  113                         makeSubPathOf, simpleSubPath,
  114                         ioAbsolute, ioAbsoluteOrStd,
  115                         makeAbsolute, makeAbsoluteOrStd, rootDirectory )
  116 import Darcs.Patch.MatchData ( patch_match )
  117 import Darcs.Flags ( DarcsFlag(..), maxCount )
  118 import Darcs.Repository ( slurp_pending, withRepository, ($-) )
  119 import Darcs.Repository.HashedRepo ( slurp_all_but_darcs )
  120 import Darcs.SlurpDirectory ( list_slurpy )
  121 import Darcs.Global ( darcsdir )
  122 import Printer ( Doc, putDocLn, text, vsep, ($$), vcat, insert_before_lastline,
  123                  prefix )
  124 import URL ( pipeliningEnabledByDefault )
  125 #include "impossible.h"
  126 
  127 data FlagContent = NoContent | AbsoluteContent AbsolutePath | AbsoluteOrStdContent AbsolutePathOrStd | StringContent String
  128                    deriving (Eq, Show, Ord)
  129 
  130 -- getContent is very tedious to write, but this is the only way (that
  131 -- I know of) to guarantee that it works for all flags (which then
  132 -- guarantees that isAnAbsolute, isa, flagToString, etc also work
  133 -- properly)
  134 
  135 -- | 'get_content' returns the content of a flag, if any.
  136 -- For instance, the content of @Author \"Louis Aragon\"@ is @StringContent
  137 -- \"Louis Aragon\"@, while the content of @Pipe@ is @NoContent@
  138 getContent :: DarcsFlag -> FlagContent
  139 getContent (PatchName s) = StringContent s
  140 getContent (Output s) = AbsoluteOrStdContent s
  141 getContent Verbose = NoContent
  142 getContent Help = NoContent
  143 getContent ListOptions = NoContent
  144 getContent Test = NoContent
  145 getContent NoTest = NoContent
  146 getContent OnlyChangesToFiles = NoContent
  147 getContent LeaveTestDir = NoContent
  148 getContent NoLeaveTestDir = NoContent
  149 getContent Timings = NoContent
  150 getContent Debug = NoContent
  151 getContent DebugVerbose = NoContent
  152 getContent DebugHTTP = NoContent
  153 getContent NormalVerbosity = NoContent
  154 getContent Quiet = NoContent
  155 getContent (Target s) = StringContent s
  156 getContent (Cc s) = StringContent s
  157 getContent (Subject s) = StringContent s
  158 getContent (InReplyTo s) = StringContent s
  159 getContent (SendmailCmd s) = StringContent s
  160 getContent (Author s) = StringContent s
  161 getContent (OnePatch s) = StringContent s
  162 getContent (SeveralPatch s) = StringContent s
  163 getContent (AfterPatch s) = StringContent s
  164 getContent (UpToPatch s) = StringContent s
  165 getContent (TagName s) = StringContent s
  166 getContent (LastN s) = StringContent (show s)
  167 getContent (MaxCount s) = StringContent (show s)
  168 getContent (OneTag s) = StringContent s
  169 getContent (AfterTag s) = StringContent s
  170 getContent (UpToTag s) = StringContent s
  171 getContent (Context s) = AbsoluteContent s
  172 getContent (LogFile s) = AbsoluteContent s
  173 getContent (OutputAutoName s) = AbsoluteContent s
  174 getContent NumberPatches = NoContent
  175 getContent (PatchIndexRange _ _) = NoContent -- FIXME this doesn't fit into a neat category
  176 getContent Count = NoContent
  177 getContent All = NoContent
  178 getContent Recursive = NoContent
  179 getContent NoRecursive = NoContent
  180 getContent Reorder = NoContent
  181 getContent RestrictPaths = NoContent
  182 getContent DontRestrictPaths = NoContent
  183 getContent AskDeps = NoContent
  184 getContent NoAskDeps = NoContent
  185 getContent RmLogFile = NoContent
  186 getContent (DistName s) = StringContent s
  187 getContent (CreatorHash s) = StringContent s
  188 getContent (SignAs s) = StringContent s
  189 getContent (SignSSL s) = StringContent s
  190 getContent (Verify s) = AbsoluteContent s
  191 getContent (VerifySSL s) = AbsoluteContent s
  192 getContent IgnoreTimes = NoContent
  193 getContent LookForAdds = NoContent
  194 getContent NoLookForAdds = NoContent
  195 getContent AnyOrder = NoContent
  196 getContent Intersection = NoContent
  197 getContent Unified = NoContent
  198 getContent Union = NoContent
  199 getContent Complement = NoContent
  200 getContent Sign = NoContent
  201 getContent NoSign = NoContent
  202 getContent HappyForwarding = NoContent
  203 getContent SSHControlMaster = NoContent
  204 getContent NoSSHControlMaster = NoContent
  205 getContent (Toks s) = StringContent s
  206 getContent (WorkRepoDir s) = StringContent s
  207 getContent (WorkRepoUrl s) = StringContent s
  208 getContent (RemoteRepo s) = StringContent s
  209 getContent (NewRepo s) = StringContent s
  210 getContent (Reply s) = StringContent s
  211 getContent EditDescription = NoContent
  212 getContent NoEditDescription = NoContent
  213 getContent EditLongComment = NoContent
  214 getContent NoEditLongComment = NoContent
  215 getContent PromptLongComment = NoContent
  216 getContent AllowConflicts = NoContent
  217 getContent MarkConflicts = NoContent
  218 getContent NoAllowConflicts = NoContent
  219 getContent Boring = NoContent
  220 getContent AllowCaseOnly = NoContent
  221 getContent AllowWindowsReserved = NoContent
  222 getContent DontGrabDeps = NoContent
  223 getContent DontPromptForDependencies = NoContent
  224 getContent PromptForDependencies = NoContent
  225 getContent Compress = NoContent
  226 getContent NoCompress = NoContent
  227 getContent UnCompress = NoContent
  228 getContent MachineReadable = NoContent
  229 getContent HumanReadable = NoContent
  230 getContent Pipe = NoContent
  231 getContent Interactive = NoContent
  232 getContent Summary = NoContent
  233 getContent NoSummary = NoContent
  234 getContent (ApplyAs s) = StringContent s
  235 getContent (DiffCmd s) = StringContent s
  236 getContent (ExternalMerge s) = StringContent s
  237 getContent (DiffFlags s) = StringContent s
  238 getContent (OnePattern _) = NoContent -- FIXME!!!
  239 getContent (SeveralPattern _) = NoContent -- FIXME!!!
  240 getContent (UpToPattern _) = NoContent -- FIXME!!!
  241 getContent (AfterPattern _) = NoContent -- FIXME!!!
  242 getContent Reverse = NoContent
  243 getContent Partial = NoContent
  244 getContent Complete = NoContent
  245 getContent Lazy = NoContent
  246 getContent Ephemeral = NoContent
  247 getContent (FixFilePath _ _) = NoContent -- FIXME!!!
  248 getContent XMLOutput = NoContent
  249 getContent ForceReplace = NoContent
  250 getContent NonApply = NoContent
  251 getContent NonVerify = NoContent
  252 getContent NonForce = NoContent
  253 getContent DryRun = NoContent
  254 getContent SetDefault = NoContent
  255 getContent NoSetDefault = NoContent
  256 getContent FancyMoveAdd = NoContent
  257 getContent NoFancyMoveAdd = NoContent
  258 getContent Disable = NoContent
  259 getContent SetScriptsExecutable = NoContent
  260 getContent DontSetScriptsExecutable = NoContent
  261 getContent UseHashedInventory = NoContent
  262 getContent UseOldFashionedInventory = NoContent
  263 getContent UseFormat2 = NoContent
  264 getContent PristinePlain = NoContent
  265 getContent PristineNone = NoContent
  266 getContent NoUpdateWorking = NoContent
  267 getContent Relink = NoContent
  268 getContent RelinkPristine = NoContent
  269 getContent NoLinks = NoContent
  270 getContent Files = NoContent
  271 getContent NoFiles = NoContent
  272 getContent Directories = NoContent
  273 getContent NoDirectories = NoContent
  274 getContent Pending = NoContent
  275 getContent NoPending = NoContent
  276 getContent NoPosthook = NoContent
  277 getContent AskPosthook = NoContent
  278 getContent (Sibling s) = AbsoluteContent s
  279 getContent (PosthookCmd s) = StringContent s
  280 getContent RunPosthook = NoContent
  281 getContent NoPrehook = NoContent
  282 getContent RunPrehook = NoContent
  283 getContent AskPrehook = NoContent
  284 getContent StoreInMemory = NoContent
  285 getContent HTTPPipelining = NoContent
  286 getContent NoHTTPPipelining = NoContent
  287 getContent NoCache = NoContent
  288 getContent NullFlag = NoContent
  289 getContent (PrehookCmd s) = StringContent s
  290 getContent (UMask s) = StringContent s
  291 getContent AllowUnrelatedRepos = NoContent
  292 getContent Check = NoContent
  293 getContent Repair = NoContent
  294 getContent JustThisRepo = NoContent
  295 
  296 get_content :: DarcsFlag -> Maybe String
  297 get_content f = do StringContent s <- Just $ getContent f
  298                    return s
  299 
  300 -- | @a `'isa'` b@ tests whether @a@ is flag @b@ with a string argument.
  301 -- @b@ typically is a Flag constructor expecting a string
  302 -- For example, @(Author \"Ted Hughes\") `isa` Author@ returns true.
  303 isa :: DarcsFlag -> (String -> DarcsFlag) -> Bool
  304 a `isa` b = case get_content a of
  305             Nothing -> False
  306             Just s -> a == b s
  307 
  308 -- | @a `'isAnAbsolute'` b@ tests whether @a@ is flag @b@ with an absolute path argument.
  309 -- @b@ typically is a Flag constructor expecting an absolute path argument
  310 -- For example, @(Context contextfile) `isAnAbsolute` Context@ returns true.
  311 isAnAbsolute :: DarcsFlag -> (AbsolutePath -> DarcsFlag) -> Bool
  312 isAnAbsolute f x = case getContent f of
  313                   AbsoluteContent s -> f == x s
  314                   _ -> False
  315 
  316 -- | @a `'isAnAbsoluteOrStd'` b@ tests whether @a@ is flag @b@ with a path argument.
  317 -- @b@ typically is a Flag constructor expecting a path argument
  318 -- For example, @(Output o) `isAnAbsoluteOrStd` @ returns true.
  319 isAnAbsoluteOrStd :: DarcsFlag -> (AbsolutePathOrStd -> DarcsFlag) -> Bool
  320 isAnAbsoluteOrStd f x = case getContent f of
  321                           AbsoluteOrStdContent s -> f == x s
  322                           _ -> False
  323 
  324 isin :: (String->DarcsFlag) -> [DarcsFlag] -> Bool
  325 f `isin` fs = any (`isa` f) fs
  326 
  327 arein :: [DarcsOption] -> [DarcsFlag] -> Bool
  328 (DarcsNoArgOption _ _ f _ : dos') `arein` fs
  329     = f `elem` fs || dos' `arein` fs
  330 (DarcsArgOption _ _ f _ _ : dos') `arein` fs
  331     = f `isin` fs || dos' `arein` fs
  332 (DarcsAbsPathOption _ _ f _ _ : dos') `arein` fs
  333     = any (`isAnAbsolute` f) fs || dos' `arein` fs
  334 (DarcsAbsPathOrStdOption _ _ f _ _ : dos') `arein` fs
  335     = any (`isAnAbsoluteOrStd` f) fs || dos' `arein` fs
  336 (DarcsOptAbsPathOption _ _ _ f _ _ : dos') `arein` fs
  337     = any (`isAnAbsolute` f) fs || dos' `arein` fs
  338 (DarcsMultipleChoiceOption os: dos') `arein` fs
  339     = os `arein` fs || dos' `arein` fs
  340 [] `arein` _ = False
  341 
  342 -- | A type for darcs' options. The value contains the command line
  343 -- switch(es) for the option, a help string, and a function to build a
  344 -- @DarcsFlag@ from the command line arguments.  for each constructor,
  345 -- 'shortSwitches' represents the list of short command line switches
  346 -- which invoke the option, longSwitches the list of long command line
  347 -- switches, optDescr the description of the option, and argDescr the description
  348 -- of its argument, if any. mkFlag is a function which makes a @DarcsFlag@ from
  349 -- the arguments of the option.
  350 data DarcsOption
  351     = DarcsArgOption [Char] [String] (String->DarcsFlag) String String
  352     -- ^ @DarcsArgOption shortSwitches longSwitches mkFlag ArgDescr OptDescr@
  353     -- The constructor for options with a string argument, such as
  354     -- @--tag@
  355 
  356     | DarcsAbsPathOption [Char] [String] (AbsolutePath -> DarcsFlag) String String
  357     -- ^ @DarcsAbsPathOption shortSwitches longSwitches mkFlag ArgDescr OptDescr@
  358     -- The constructor for options with an absolute path argument, such as
  359     -- @--sibling@
  360 
  361     | DarcsAbsPathOrStdOption [Char] [String] (AbsolutePathOrStd -> DarcsFlag) String String
  362     -- ^ @DarcsAbsPathOrStdOption shortSwitches longSwitches mkFlag ArgDescr OptDescr@
  363     -- The constructor for options with a path argument, such as @-o@
  364 
  365     | DarcsOptAbsPathOption [Char] [String] String (AbsolutePath -> DarcsFlag) String String
  366     -- ^ @DarcsOptAbsPathOrStdOption shortSwitches longSwitches defaultPath
  367     -- mkFlag ArgDescr OptDescr@ where defaultPath is a default value
  368     -- for the Path, as a string to be parsed as if it had been given
  369     -- on the command line.
  370     -- The constructor for options with an optional path argument, such as @-O@
  371 
  372     | DarcsNoArgOption [Char] [String] DarcsFlag String
  373     -- ^ @DarcsNoArgOption shortSwitches longSwitches mkFlag optDescr@
  374     -- The constructon fon options with no arguments.
  375 
  376     | DarcsMultipleChoiceOption [DarcsOption]
  377     -- ^ A constructor for grouping related options together, such as
  378     -- @--hashed@, @--darcs-2@ and @--old-fashioned-inventory@.
  379 
  380 option_from_darcsoption :: AbsolutePath -> DarcsOption -> [OptDescr DarcsFlag]
  381 option_from_darcsoption _ (DarcsNoArgOption a b c h) = [Option a b (NoArg c) h]
  382 option_from_darcsoption _ (DarcsArgOption a b c n h) = [Option a b (ReqArg c n) h]
  383 option_from_darcsoption wd (DarcsMultipleChoiceOption os) = concatMap (option_from_darcsoption wd) os
  384 option_from_darcsoption wd (DarcsAbsPathOrStdOption a b c n h) = [Option a b (ReqArg (c . makeAbsoluteOrStd wd) n) h]
  385 option_from_darcsoption wd (DarcsAbsPathOption a b c n h) = [Option a b (ReqArg (c . makeAbsolute wd) n) h]
  386 option_from_darcsoption wd (DarcsOptAbsPathOption a b d c n h) = [Option a b (OptArg (c . makeAbsolute wd . fromMaybe d) n) h]
  387 
  388 -- | 'concat_option' creates a DarcsMultipleChoiceOption from a list of
  389 -- option, flattening any DarcsMultipleChoiceOption in the list.
  390 concat_options :: [DarcsOption] -> DarcsOption
  391 concat_options os = DarcsMultipleChoiceOption $ concatMap from_option os
  392  where
  393   from_option (DarcsMultipleChoiceOption xs) = xs
  394   from_option x = [x]
  395 
  396 extract_fix_path :: [DarcsFlag] -> Maybe (AbsolutePath, AbsolutePath)
  397 extract_fix_path [] = Nothing
  398 extract_fix_path ((FixFilePath repo orig):_)  = Just (repo, orig)
  399 extract_fix_path (_:fs) = extract_fix_path fs
  400 
  401 fixFilePath :: [DarcsFlag] -> FilePath -> IO AbsolutePath
  402 fixFilePath opts f = case extract_fix_path opts of
  403                        Nothing -> bug "Can't fix path in fixFilePath"                                                                                                    
  404                        Just (_,o) -> withCurrentDirectory o $ ioAbsolute f
  405 
  406 fixFilePathOrStd :: [DarcsFlag] -> FilePath -> IO AbsolutePathOrStd
  407 fixFilePathOrStd opts f =
  408     case extract_fix_path opts of
  409       Nothing -> bug "Can't fix path in fixFilePathOrStd"                                                                                                    
  410       Just (_,o) -> withCurrentDirectory o $ ioAbsoluteOrStd f
  411 
  412 fixUrl :: [DarcsFlag] -> String -> IO String
  413 fixUrl opts f = if is_file f
  414                 then toFilePath `fmap` fixFilePath opts f
  415                 else return f
  416 
  417 fixSubPaths :: [DarcsFlag] -> [FilePath] -> IO [SubPath]
  418 fixSubPaths flags fs =
  419     withCurrentDirectory o $
  420     do fixedfs <- mapM fixit $ filter (not.null) fs
  421        let (good, bad) = partitionEither fixedfs
  422        unless (null bad) $
  423               putStrLn $ "Ignoring non-repository paths: " ++ unwords bad
  424        return $ nub good
  425  where
  426     (r,o) = case extract_fix_path flags of
  427             Just xxx -> xxx
  428             Nothing -> bug "Can't fix path in fixSubPaths"                                                                                                    
  429     fixit p = do ap <- ioAbsolute p
  430                  case makeSubPathOf r ap of
  431                    Just sp -> return $ Right sp
  432                    Nothing -> return $ maybe (Left p) Right $ simpleSubPath p
  433 
  434 partitionEither :: [Either a b] -> ([b],[a])
  435 partitionEither es = ( [b | Right b <- es]
  436                      , [a | Left  a <- es] )
  437 
  438 -- as opposed to just '.'
  439 areFileArgs :: [SubPath] -> Bool
  440 areFileArgs rps = concatMap toFilePath rps /= ""
  441 
  442 -- | 'list_option' is an option which lists the command's arguments
  443 list_options :: DarcsOption
  444 list_options = DarcsNoArgOption [] ["list-options"] ListOptions
  445                "simply list the command's arguments"
  446 
  447 flagToString :: [DarcsOption] -> DarcsFlag -> Maybe String
  448 flagToString x f = maybeHead $ catMaybes $ map f2o x
  449     where f2o (DarcsArgOption _ (s:_) c _ _) = do arg <- get_content f
  450                                                   if c arg == f
  451                                                       then return $ unwords [('-':'-':s), arg]
  452                                                       else Nothing
  453           f2o (DarcsNoArgOption _ (s:_) f' _) | f == f' = Just ('-':'-':s)
  454           f2o (DarcsMultipleChoiceOption xs) = maybeHead $ catMaybes $ map f2o xs
  455           f2o _ = Nothing
  456           maybeHead (a:_) = Just a
  457           maybeHead [] = Nothing
  458 
  459 reponame :: DarcsOption
  460 deps_sel :: DarcsOption
  461 partial :: DarcsOption
  462 partial_check :: DarcsOption
  463 tokens :: DarcsOption
  464 working_repo_dir :: DarcsOption
  465 possibly_remote_repo_dir :: DarcsOption
  466 disable :: DarcsOption
  467 restrict_paths :: DarcsOption
  468 
  469 pipe_interactive, all_pipe_interactive, all_interactive, all_patches, interactive, pipe,
  470   human_readable, diffflags, allow_problematic_filenames, noskip_boring,
  471   ask_long_comment, match_one_nontag, changes_reverse, creatorhash,
  472   changes_format, match_one_context, happy_forwarding, send_to_context,
  473   diff_cmd_flag, store_in_memory, use_external_merge,
  474   pull_conflict_options, target, cc, apply_conflict_options, reply, xmloutput,
  475   distname_option, patchname_option, edit_description,
  476   output, output_auto_name, unidiff, repo_combinator,
  477   unified, summary, uncompress_nocompress, subject, in_reply_to,
  478   nocompress, match_several_or_range, match_several_or_last,
  479   author, askdeps, lookforadds, ignoretimes, test, notest, help, force_replace,
  480   allow_unrelated_repos,
  481   match_one, match_range, match_several, fancy_move_add, sendmail_cmd,
  482   logfile, rmlogfile, leave_test_dir, from_opt, set_default
  483 
  484       :: DarcsOption
  485 
  486 recursive :: String -> DarcsOption
  487 
  488 sign, applyas, verify :: DarcsOption
  489 \end{code}
  490 
  491 \section{Common options to darcs commands}
  492 
  493 \begin{options}
  494 --help
  495 \end{options}
  496 Every \verb|COMMAND| accepts \verb!--help! as an argument, which tells it to
  497 provide a bit of help.  Among other things, this help always provides an
  498 accurate listing of the options available with that command, and is
  499 guaranteed never to be out of sync with the version of darcs you actually
  500 have installed (unlike this manual, which could be for an entirely
  501 different version of darcs).
  502 \begin{verbatim}
  503 % darcs COMMAND --help
  504 \end{verbatim}
  505 \begin{code}
  506 help = DarcsNoArgOption ['h'] ["help"] Help
  507        "shows brief description of command and its arguments"
  508 \end{code}
  509 
  510 \begin{options}
  511 --disable
  512 \end{options}
  513 Every {\tt COMMAND} accepts the \verb!--disable! option, which can be used in
  514 \verb!_darcs/prefs/defaults! to disable some commands in the repository. This
  515 can be helpful if you want to protect the repository from accidental use of
  516 advanced commands like obliterate, unpull, unrecord or amend-record.
  517 \begin{code}
  518 disable = DarcsNoArgOption [] ["disable"] Disable
  519         "disable this command"
  520 \end{code}
  521 
  522 \begin{options}
  523 --verbose, --quiet, --normal-verbosity
  524 \end{options}
  525 Most commands also accept the \verb!--verbose! option, which tells darcs to
  526 provide additional output.  The amount of verbosity varies from command to
  527 command.  Commands that accept \verb!--verbose\verb! also accept \verb!--quiet\verb!,
  528 which surpresses non-error output, and \verb!--normal-verbosity\verb! which can be
  529 used to restore the default verbosity if \verb!--verbose! or \verb!--quiet! is in
  530 the defaults file.
  531 
  532 \begin{options}
  533 --debug, --debug-http
  534 \end{options}
  535 Many commands also accept the \verb!--debug! option, which causes darcs to generate
  536 additional output that may be useful for debugging its behavior, but which otherwise
  537 would not be interesting. Option \verb!--debug-http! makes darcs output debugging
  538 info for libcurl.
  539 \begin{code}
  540 any_verbosity :: [DarcsOption]
  541 any_verbosity =[DarcsMultipleChoiceOption
  542                 [DarcsNoArgOption [] ["debug"] Debug
  543                  "give only debug output",
  544                  DarcsNoArgOption [] ["debug-verbose"] DebugVerbose
  545                  "give debug and verbose output",
  546                  DarcsNoArgOption [] ["debug-http"] DebugHTTP
  547                  "give debug output for libcurl",
  548                  DarcsNoArgOption ['v'] ["verbose"] Verbose
  549                  "give verbose output",
  550                  DarcsNoArgOption ['q'] ["quiet"] Quiet
  551                  "suppress informational output",
  552                  DarcsNoArgOption [] ["standard-verbosity"] NormalVerbosity
  553                  "neither verbose nor quiet output"],
  554                  DarcsNoArgOption [] ["timings"] Timings "provide debugging timings information"]
  555 \end{code}
  556 
  557 \begin{options}
  558 --repodir
  559 \end{options}
  560 Another common option is the \verb!--repodir! option, which allows you to
  561 specify the directory of the repository in which to perform the command.
  562 This option is used with commands, such as whatsnew, that ordinarily would
  563 be performed within a repository directory, and allows you to use those
  564 commands without actually being in the repository directory when calling the
  565 command.  This is useful when running darcs in a pipe, as might be the case
  566 when running \verb'apply' from a mailer.
  567 
  568 \begin{code}
  569 working_repo_dir = DarcsArgOption [] ["repodir"] WorkRepoDir "DIRECTORY"
  570              "specify the repository directory in which to run"
  571 possibly_remote_repo_dir = DarcsArgOption [] ["repo"] WorkRepoUrl "URL"
  572              "specify the repository URL"
  573 
  574 -- | 'get_repourl' takes a list of flags and returns the url of the
  575 -- repository specified by @Repodir \"directory\"@ in that list of flags, if any.
  576 -- This flag is present if darcs was invoked with @--repodir=DIRECTORY@
  577 get_repourl :: [DarcsFlag] -> Maybe String
  578 get_repourl [] = Nothing
  579 get_repourl (WorkRepoUrl d:_) | not (is_file d) = Just d
  580 get_repourl (_:fs) = get_repourl fs
  581 \end{code}
  582 
  583 \begin{options}
  584 --remote-repo
  585 \end{options}
  586 
  587 Some commands, such as \verb'pull' require a remote repository to be specified,
  588 either from the command line or as a default.  The \verb!--remote-repo!
  589 provides an alternative way to supply this remote repository path.  This flag
  590 can be seen as temporarily ``replacing'' the default repository. Setting it
  591 causes the command to ignore the default repository (it also does not affect,
  592 i.e. overwrite the default repository).  On the other hand, if any other
  593 repositories are supplied as command line arguments, this flag will be ignored
  594 (and the default repository may be overwritten).
  595 
  596 \begin{code}
  597 -- | 'remote_repo' is the option used to specify the URL of the remote
  598 -- repository to work with
  599 remote_repo :: DarcsOption
  600 remote_repo = DarcsArgOption [] ["remote-repo"] RemoteRepo "URL"
  601              "specify the remote repository URL to work with"
  602 \end{code}
  603 
  604 \input{Darcs/Match.lhs}
  605 \input{Darcs/Patch/Match.lhs}
  606 
  607 \begin{code}
  608 patchname_option = DarcsArgOption ['m'] ["patch-name"] PatchName "PATCHNAME"
  609                    "name of patch"
  610 
  611 send_to_context = DarcsAbsPathOption [] ["context"] Context "FILENAME"
  612                   "send to context stored in FILENAME"
  613 
  614 match_one_context =
  615     DarcsMultipleChoiceOption
  616     [DarcsArgOption [] ["to-match"] mp "PATTERN"
  617      "select changes up to a patch matching PATTERN",
  618      DarcsArgOption [] ["to-patch"] OnePatch "REGEXP"
  619      "select changes up to a patch matching REGEXP",
  620      __tag,
  621      DarcsAbsPathOption [] ["context"] Context "FILENAME"
  622      "version specified by the context in FILENAME"
  623     ]
  624     where mp s = OnePattern (patch_match s)
  625 
  626 match_one = concat_options [__match, __patch, __tag, __index]
  627 match_one_nontag = concat_options [__match, __patch, __index]
  628 match_several    = concat_options [__matches, __patches, __tags]
  629 match_range            = concat_options [match_to, match_from, __match, __patch, __last, __indexes]
  630 match_several_or_range = concat_options [match_to, match_from, __last, __indexes,
  631                                          __matches, __patches, __tags]
  632 match_several_or_last  = concat_options [match_from, __last, __matches, __patches, __tags]
  633 
  634 match_to, match_from :: DarcsOption
  635 match_to = DarcsMultipleChoiceOption
  636             [DarcsArgOption [] ["to-match"] uptop "PATTERN"
  637              "select changes up to a patch matching PATTERN",
  638              DarcsArgOption [] ["to-patch"] UpToPatch "REGEXP"
  639              "select changes up to a patch matching REGEXP",
  640              DarcsArgOption [] ["to-tag"] UpToTag "REGEXP"
  641              "select changes up to a tag matching REGEXP"]
  642     where uptop s = UpToPattern (patch_match s)
  643 match_from = DarcsMultipleChoiceOption
  644               [DarcsArgOption [] ["from-match"] fromp "PATTERN"
  645                "select changes starting with a patch matching PATTERN",
  646                DarcsArgOption [] ["from-patch"] AfterPatch "REGEXP"
  647                "select changes starting with a patch matching REGEXP",
  648                DarcsArgOption [] ["from-tag"] AfterTag "REGEXP"
  649                "select changes starting with a tag matching REGEXP"]
  650     where fromp s = AfterPattern (patch_match s)
  651 
  652 __tag, __tags, __patch, __patches, __match, __matches, __last, __index, __indexes :: DarcsOption
  653 
  654 __tag = DarcsArgOption ['t'] ["tag"] OneTag "REGEXP"
  655        "select tag matching REGEXP"
  656 __tags = DarcsArgOption ['t'] ["tags"] OneTag "REGEXP"
  657         "select tags matching REGEXP"
  658 
  659 __patch = DarcsArgOption ['p'] ["patch"] OnePatch "REGEXP"
  660          "select a single patch matching REGEXP"
  661 __patches = DarcsArgOption ['p'] ["patches"] SeveralPatch "REGEXP"
  662            "select patches matching REGEXP"
  663 
  664 __match = DarcsArgOption [] ["match"] mp "PATTERN"
  665          "select a single patch matching PATTERN"
  666   where mp s = OnePattern (patch_match s)
  667 __matches = DarcsArgOption [] ["matches"] mp "PATTERN"
  668            "select patches matching PATTERN"
  669   where mp s = SeveralPattern (patch_match s)
  670 
  671 __last = DarcsArgOption [] ["last"] lastn "NUMBER"
  672          "select the last NUMBER patches"
  673     where lastn = LastN . number_string
  674 
  675 __index = DarcsArgOption ['n'] ["index"] indexrange "N" "select one patch"
  676     where indexrange s = if all isDigit s
  677                          then PatchIndexRange (read s) (read s)
  678                          else PatchIndexRange 0 0
  679 
  680 __indexes = DarcsArgOption ['n'] ["index"] indexrange "N-M" "select a range of patches"
  681     where indexrange s = if all isokay s
  682                          then if '-' `elem` s
  683                               then let x1 = takeWhile (/= '-') s
  684                                        x2 = reverse $ takeWhile (/= '-') $ reverse s
  685                                    in PatchIndexRange (read x1) (read x2)
  686                               else PatchIndexRange (read s) (read s)
  687                          else PatchIndexRange 0 0
  688           isokay c = isDigit c || c == '-'
  689 
  690 match_maxcount :: DarcsOption
  691 match_maxcount = DarcsArgOption [] ["max-count"] mc "NUMBER"
  692          "return only NUMBER results"
  693     where mc = MaxCount . number_string
  694 
  695 
  696 -- | 'get_context' takes a list of flags and returns the context
  697 -- specified by @Context c@ in that list of flags, if any.
  698 -- This flag is present if darcs was invoked with @--context=FILE@
  699 get_context :: [DarcsFlag] -> Maybe AbsolutePath
  700 get_context xs = listToMaybe [ c | Context c <- xs ]
  701 
  702 notest = DarcsMultipleChoiceOption
  703          [DarcsNoArgOption [] ["no-test"] NoTest "don't run the test script",
  704           DarcsNoArgOption [] ["test"] Test "run the test script"]
  705 test = DarcsMultipleChoiceOption
  706           [DarcsNoArgOption [] ["test"] Test "run the test script",
  707            DarcsNoArgOption [] ["no-test"] NoTest "don't run the test script"]
  708 leave_test_dir = DarcsMultipleChoiceOption
  709                  [DarcsNoArgOption [] ["leave-test-directory"]
  710                   LeaveTestDir "don't remove the test directory",
  711                   DarcsNoArgOption [] ["remove-test-directory"]
  712                   NoLeaveTestDir "remove the test directory"]
  713 
  714 testByDefault :: [DarcsFlag] -> [DarcsFlag]
  715 testByDefault o = if NoTest `elem` o then o else Test:o
  716 \end{code}
  717 
  718 \begin{options}
  719 --ignore-times
  720 \end{options}
  721 Darcs optimizes its operations by keeping track of the modification times
  722 of your files.  This dramatically speeds up commands such as
  723 \verb!whatsnew! and \verb!record! which would otherwise require reading
  724 every file in the repository and comparing it with a reference version.  However,
  725 there are times when this can cause problems, such as when running a series
  726 of darcs commands from a script, in which case often a file will be
  727 modified twice in the same second, which can lead to the second
  728 modification going unnoticed.  The solution to such predicaments is the
  729 \verb!--ignore-times! option, which instructs darcs not to trust the file
  730 modification times, but instead to check each file's contents explicitly.
  731 \begin{code}
  732 ignoretimes = DarcsNoArgOption [] ["ignore-times"] IgnoreTimes
  733               "don't trust the file modification times"
  734 lookforadds =
  735     DarcsMultipleChoiceOption
  736     [DarcsNoArgOption ['l'] ["look-for-adds"] LookForAdds
  737      "look for (non-boring) files that could be added",
  738      DarcsNoArgOption [] ["dont-look-for-adds"] NoLookForAdds
  739      "don't look for any files that could be added [DEFAULT]"]
  740 
  741 fancy_move_add =
  742     DarcsMultipleChoiceOption
  743     [DarcsNoArgOption [] ["date-trick"] FancyMoveAdd
  744      "add files with date appended to avoid conflict [EXPERIMENTAL] ",
  745      DarcsNoArgOption [] ["no-date-trick"] NoFancyMoveAdd
  746      "don't use experimental date appending trick [DEFAULT]"]
  747 
  748 askdeps =
  749     DarcsMultipleChoiceOption
  750     [DarcsNoArgOption [] ["ask-deps"] AskDeps
  751      "ask for extra dependencies",
  752      DarcsNoArgOption [] ["no-ask-deps"] NoAskDeps
  753      "don't ask for extra dependencies"]
  754 
  755 ask_long_comment =
  756     DarcsMultipleChoiceOption
  757     [DarcsNoArgOption [] ["edit-long-comment"] EditLongComment
  758      "edit the long comment by default",
  759      DarcsNoArgOption [] ["skip-long-comment"] NoEditLongComment
  760      "don't give a long comment",
  761      DarcsNoArgOption [] ["prompt-long-comment"] PromptLongComment
  762      "prompt for whether to edit the long comment"]
  763 \end{code}
  764 
  765 \begin{options}
  766 --author
  767 \end{options}
  768 \label{env:DARCS_EMAIL}
  769 Several commands need to be able to identify you.  Conventionally, you
  770 provide an email address for this purpose, which can include comments,
  771 e.g.\ \verb!David Roundy <droundy@abridgegame.org>!.  The easiest way to do
  772 this is
  773 to define an environment variable \verb!EMAIL! or \verb!DARCS_EMAIL! (with
  774 the latter overriding the former).  You can also override this using the
  775 \verb!--author! flag to any command.  Alternatively, you could set your
  776 email address on a per-repository basis using the ``defaults'' mechanism
  777 for ``ALL'' commands, as described in Appendix~\ref{repository_format}.
  778 Or, you could specify the author on a per-repository basis using the
  779 \verb!_darcs/prefs/author! file as described in section~\ref{author_prefs}.
  780 
  781 Also, a global author file can be created in your home directory with the name
  782 \verb!.darcs/author!, on MS Windows~\ref{ms_win}.  This file overrides the
  783 contents of the environment variables, but a repository-specific author
  784 file overrides the global author file.
  785 
  786 \begin{code}
  787 logfile = DarcsAbsPathOption [] ["logfile"] LogFile "FILE"
  788           "give patch name and comment in file"
  789 
  790 rmlogfile = DarcsNoArgOption [] ["delete-logfile"] RmLogFile
  791             "delete the logfile when done"
  792 
  793 author = DarcsArgOption ['A'] ["author"] Author "EMAIL" "specify author id"
  794 from_opt = DarcsArgOption [] ["from"] Author "EMAIL" "specify email address"
  795 
  796 -- | 'get_author' takes a list of flags and returns the author of the
  797 -- change specified by @Author \"Leo Tolstoy\"@ in that list of flags, if any.
  798 -- Otherwise, if @Pipe@ is present, asks the user who is the author and
  799 -- returns the answer. If neither are present, try to guess the author,
  800 -- from @_darcs/prefs@, and if it's not possible, ask the user.
  801 get_author :: [DarcsFlag] -> IO String
  802 get_author (Author a:_) = return a
  803 get_author (Pipe:_) = do askUser "Who is the author? "
  804 get_author (_:flags) = get_author flags
  805 get_author [] = do
  806   easy_author <- get_easy_author
  807   case easy_author of
  808     Just a -> return a
  809     Nothing -> do
  810       aminrepo <- doesDirectoryExist (darcsdir++"/prefs")
  811       if aminrepo then do
  812           putDocLn $
  813             text "Each patch is attributed to its author, usually by email address (for" $$
  814             text "example, `Fred Bloggs <fred@example.net>').  Darcs could not determine" $$
  815             text "your email address, so you will be prompted for it." $$
  816             text "" $$
  817             text ("Your address will be stored in " ++ darcsdir ++ "/prefs/author.") $$
  818             text "It will be used for all patches recorded in this repository." $$
  819             text "If you move that file to ~/.darcs/author, it will be used for patches" $$
  820             text "you record in ALL repositories."
  821           add <- askUser "What is your email address? "
  822           writeFile (darcsdir++"/prefs/author") add
  823           return add
  824         else askUser "What is your email address (e.g. Fred Bloggs <fred@example.net>)? "
  825 
  826 -- | 'get_easy_author' tries to get the author name first from the repository preferences,
  827 -- then from global preferences, then from environment variables. Returns 'Nothing' if it
  828 -- could not get it.
  829 get_easy_author :: IO (Maybe String)
  830 get_easy_author = firstJustIO [ firstNotBlank `fmap` get_preflist "author",
  831                                 firstNotBlank `fmap` get_global "author",
  832                                 maybeGetEnv "DARCS_EMAIL",
  833                                 maybeGetEnv "EMAIL" ]
  834 \end{code}
  835 
  836 \begin{options}
  837 --dont-compress, --compress
  838 \end{options}
  839 By default, darcs commands that write patches to disk will compress the
  840 patch files.  If you don't want this, you can choose the
  841 \verb!--dont-compress! option, which causes darcs not to compress the patch
  842 file.
  843 
  844 \begin{code}
  845 nocompress = concat_options [__compress, __dont_compress]
  846 uncompress_nocompress = concat_options [__compress, __dont_compress, __uncompress]
  847 
  848 __compress, __dont_compress, __uncompress :: DarcsOption
  849 __compress = DarcsNoArgOption [] ["compress"] Compress
  850             "create compressed patches"
  851 __dont_compress = DarcsNoArgOption [] ["dont-compress"] NoCompress
  852                   "don't create compressed patches"
  853 __uncompress = DarcsNoArgOption [] ["uncompress"] UnCompress
  854                "uncompress patches"
  855 
  856 summary = DarcsMultipleChoiceOption
  857           [DarcsNoArgOption ['s'] ["summary"] Summary "summarize changes",
  858            DarcsNoArgOption [] ["no-summary"] NoSummary "don't summarize changes"]
  859 unified = DarcsNoArgOption ['u'] ["unified"] Unified
  860           "output patch in a darcs-specific format similar to diff -u"
  861 unidiff = DarcsNoArgOption ['u'] ["unified"] Unified
  862           "pass -u option to diff"
  863 diff_cmd_flag = DarcsArgOption [] ["diff-command"]
  864        DiffCmd "COMMAND" "specify diff command (ignores --diff-opts)"
  865 store_in_memory = DarcsNoArgOption [] ["store-in-memory"] StoreInMemory
  866           "do patch application in memory rather than on disk"
  867 
  868 target = DarcsArgOption [] ["to"] Target "EMAIL" "specify destination email"
  869 cc = DarcsArgOption [] ["cc"] Cc "EMAIL" "mail results to additional EMAIL(s). Requires --reply"
  870 
  871 -- |'get_cc' takes a list of flags and returns the addresses to send a copy of
  872 -- the patch bundle to when using @darcs send@.
  873 -- looks for a cc address specified by @Cc \"address\"@ in that list of flags.
  874 -- Returns the addresses as a comma separated string.
  875 get_cc :: [DarcsFlag] -> String
  876 get_cc fs = lt $ catMaybes $ map whatcc fs
  877             where whatcc (Cc t) = Just t
  878                   whatcc _ = Nothing
  879                   lt [t] = t
  880                   lt [t,""] = t
  881                   lt (t:ts) = t++" , "++lt ts
  882                   lt [] = ""
  883 
  884 subject = DarcsArgOption [] ["subject"] Subject "SUBJECT" "specify mail subject"
  885 
  886 -- |'get_subject' takes a list of flags and returns the subject of the mail
  887 -- to be sent by @darcs send@. Looks for a subject specified by
  888 -- @Subject \"subject\"@ in that list of flags, if any.
  889 -- This flag is present if darcs was invoked with @--subject=SUBJECT@
  890 get_subject :: [DarcsFlag] -> Maybe String
  891 get_subject (Subject s:_) = Just s
  892 get_subject (_:fs) = get_subject fs
  893 get_subject [] = Nothing
  894 
  895 in_reply_to = DarcsArgOption [] ["in-reply-to"] InReplyTo "EMAIL" "specify in-reply-to header"
  896 get_in_reply_to :: [DarcsFlag] -> Maybe String
  897 get_in_reply_to (InReplyTo s:_) = Just s
  898 get_in_reply_to (_:fs) = get_in_reply_to fs
  899 get_in_reply_to [] = Nothing
  900 
  901 output = DarcsAbsPathOrStdOption ['o'] ["output"] Output "FILE"
  902          "specify output filename"
  903 
  904 output_auto_name = DarcsOptAbsPathOption ['O'] ["output-auto-name"] "." OutputAutoName "DIRECTORY"
  905                    "output to automatically named file in DIRECTORY, default: current directory"
  906 
  907 edit_description =
  908     DarcsMultipleChoiceOption
  909     [DarcsNoArgOption [] ["edit-description"] EditDescription
  910                           "edit the patch bundle description",
  911      DarcsNoArgOption [] ["dont-edit-description"] NoEditDescription
  912                       "don't edit the patch bundle description"]
  913 
  914 distname_option = DarcsArgOption ['d'] ["dist-name"] DistName "DISTNAME"
  915                   "name of version"
  916 
  917 recursive h
  918     = DarcsMultipleChoiceOption
  919       [DarcsNoArgOption ['r'] ["recursive"] Recursive h,
  920        DarcsNoArgOption [] ["not-recursive"] NoRecursive ("don't "++h)]
  921 
  922 inventory_choices :: DarcsOption
  923 inventory_choices =
  924     DarcsMultipleChoiceOption
  925     [DarcsNoArgOption [] ["hashed"] UseHashedInventory
  926                           "Some new features. Compatible with older repos",
  927      DarcsNoArgOption [] ["darcs-2"] UseFormat2
  928                           "All features. Related repos must use same format [DEFAULT]",
  929      DarcsNoArgOption [] ["old-fashioned-inventory"] UseOldFashionedInventory
  930                           "Minimal features. What older repos use."]
  931 
  932 get_inventory_choices :: DarcsOption
  933 get_inventory_choices =
  934     DarcsMultipleChoiceOption
  935     [DarcsNoArgOption [] ["hashed"] UseHashedInventory
  936                           "Convert darcs-1 format to hashed format",
  937      DarcsNoArgOption [] ["old-fashioned-inventory"] UseOldFashionedInventory
  938                           "Convert from hashed to darcs-1 format"]
  939 
  940 xmloutput = DarcsNoArgOption [] ["xml-output"] XMLOutput
  941         "generate XML formatted output"
  942 
  943 creatorhash = DarcsArgOption [] ["creator-hash"] CreatorHash "HASH"
  944               "specify hash of creator patch (see docs)"
  945 
  946 sign = DarcsMultipleChoiceOption
  947        [DarcsNoArgOption [] ["sign"] Sign
  948         "sign the patch with your gpg key",
  949         DarcsArgOption [] ["sign-as"] SignAs "KEYID"
  950         "sign the patch with a given keyid",
  951         DarcsArgOption [] ["sign-ssl"] SignSSL "IDFILE"
  952         "sign the patch using openssl with a given private key",
  953         DarcsNoArgOption [] ["dont-sign"] NoSign
  954         "don't sign the patch"]
  955 applyas = DarcsMultipleChoiceOption
  956            [DarcsArgOption [] ["apply-as"] ApplyAs "USERNAME"
  957             "apply patch as another user using sudo",
  958             DarcsNoArgOption [] ["apply-as-myself"] NonApply
  959             "don't use sudo to apply as another user [DEFAULT]"]
  960 happy_forwarding = DarcsNoArgOption [] ["happy-forwarding"] HappyForwarding
  961                    "forward unsigned messages without extra header"
  962 set_default = DarcsMultipleChoiceOption
  963               [DarcsNoArgOption [] ["set-default"] SetDefault
  964                "set default repository [DEFAULT]",
  965                DarcsNoArgOption [] ["no-set-default"] NoSetDefault
  966                "don't set default repository"]
  967 
  968 verify = DarcsMultipleChoiceOption
  969          [DarcsAbsPathOption [] ["verify"] Verify "PUBRING"
  970           "verify that the patch was signed by a key in PUBRING",
  971           DarcsAbsPathOption [] ["verify-ssl"] VerifySSL "KEYS"
  972           "verify using openSSL with authorized keys from file KEYS",
  973           DarcsNoArgOption [] ["no-verify"] NonVerify
  974           "don't verify patch signature"]
  975 
  976 reponame = DarcsArgOption [] ["repo-name","repodir"] NewRepo "DIRECTORY"
  977            "path of output directory" --repodir is there for compatibility
  978                                       --should be removed eventually
  979 deps_sel = DarcsMultipleChoiceOption
  980        [DarcsNoArgOption [] ["no-deps"] DontGrabDeps
  981         "don't automatically fulfill dependencies",
  982         DarcsNoArgOption [] ["dont-prompt-for-dependencies"] DontPromptForDependencies
  983         "don't ask about patches that are depended on by matched patches (with --match or --patch)",
  984         DarcsNoArgOption [] ["prompt-for-dependencies"] PromptForDependencies
  985         "prompt about patches that are depended on by matched patches [DEFAULT]"]
  986 tokens = DarcsArgOption [] ["token-chars"] Toks "\"[CHARS]\""
  987          "define token to contain these characters"
  988 
  989 partial       = concat_options [__partial, __lazy, __ephemeral, __complete]
  990 partial_check = concat_options [__complete, __partial]
  991 
  992 __partial, __lazy, __ephemeral, __complete :: DarcsOption
  993 __partial = DarcsNoArgOption [] ["partial"] Partial
  994             "get partial repository using checkpoint (old-fashioned format only)"
  995 __lazy = DarcsNoArgOption [] ["lazy"] Lazy
  996               "get patch files only as needed"
  997 __ephemeral = DarcsNoArgOption [] ["ephemeral"] Ephemeral
  998               "don't save patch files in the repository"
  999 __complete = DarcsNoArgOption [] ["complete"] Complete
 1000              "get a complete copy of the repository"
 1001 
 1002 force_replace = DarcsMultipleChoiceOption
 1003                 [DarcsNoArgOption ['f'] ["force"] ForceReplace
 1004                  "proceed with replace even if 'new' token already exists",
 1005                  DarcsNoArgOption [] ["no-force"]
 1006                  NonForce "don't force the replace if it looks scary"]
 1007 
 1008 reply = DarcsArgOption [] ["reply"] Reply "FROM" "reply to email-based patch using FROM address"
 1009 apply_conflict_options
 1010     = DarcsMultipleChoiceOption
 1011       [DarcsNoArgOption [] ["mark-conflicts"]
 1012        MarkConflicts "mark conflicts",
 1013        DarcsNoArgOption [] ["allow-conflicts"]
 1014        AllowConflicts "allow conflicts, but don't mark them",
 1015        DarcsNoArgOption [] ["no-resolve-conflicts"] NoAllowConflicts
 1016        "equivalent to --dont-allow-conflicts, for backwards compatibility",
 1017        DarcsNoArgOption [] ["dont-allow-conflicts"]
 1018        NoAllowConflicts "fail on patches that create conflicts [DEFAULT]"]
 1019 pull_conflict_options
 1020     = DarcsMultipleChoiceOption
 1021       [DarcsNoArgOption [] ["mark-conflicts"]
 1022        MarkConflicts "mark conflicts [DEFAULT]",
 1023        DarcsNoArgOption [] ["allow-conflicts"]
 1024        AllowConflicts "allow conflicts, but don't mark them",
 1025        DarcsNoArgOption [] ["dont-allow-conflicts"]
 1026        NoAllowConflicts "fail on patches that create conflicts"]
 1027 use_external_merge = DarcsArgOption [] ["external-merge"]
 1028                      ExternalMerge "COMMAND" "use external tool to merge conflicts"
 1029 \end{code}
 1030 
 1031 \begin{options}
 1032 --dry-run
 1033 \end{options}
 1034 The \verb!--dry-run! option will cause darcs not to actually take the specified
 1035 action, but only print what would have happened.  Not all commands accept
 1036 \verb!--dry-run!, but those that do should accept the \verb!--summary!  option.
 1037 
 1038 \begin{options}
 1039 --summary, --no-summary
 1040 \end{options}
 1041 The \verb!--summary! option shows a summary of the patches that would have been
 1042 pulled/pushed/whatever. The format is similar to the output format of
 1043 \verb!cvs update! and looks like this:
 1044 
 1045 \begin{verbatim}
 1046 A  ./added_but_not_recorded.c
 1047 A! ./added_but_not_recorded_conflicts.c
 1048 a  ./would_be_added_if_look_for_adds_option_was_used.h
 1049 
 1050 M  ./modified.t -1 +1
 1051 M! ./modified_conflicts.t -1 +1
 1052 
 1053 R  ./removed_but_not_recorded.c
 1054 R! ./removed_but_not_recorded_conflicts.c
 1055 
 1056 \end{verbatim}
 1057 
 1058 You can probably guess what the flags mean from the clever file names.
 1059 \begin{description}
 1060 \item{\texttt{A}} is for files that have been added but not recorded yet.
 1061 \item{\texttt{a}} is for files found using the \verb!--look-for-adds! option available for
 1062 \verb!whatsnew! and \verb!record!. They have not been added yet, but would be
 1063 added automatically if \verb!--look-for-adds! were used with the next
 1064 \verb!record! command.
 1065 
 1066 \item{\texttt{M}} is for files that have been modified in the working directory but not
 1067 recorded yet. The number of added and subtracted lines is also shown.
 1068 
 1069 \item{\texttt{R}}  is for files that have been removed, but the removal is not
 1070 recorded yet.
 1071 \end{description}
 1072 An exclamation mark appears next to any option that has a conflict.
 1073 
 1074 \begin{code}
 1075 -- NOTE: I'd rather work to have no uses of dry_run_noxml, so that any time
 1076 -- --dry-run is a possibility, automated users can examine the results more
 1077 -- easily with --xml.
 1078 dry_run_noxml :: DarcsOption
 1079 dry_run_noxml = DarcsNoArgOption [] ["dry-run"] DryRun
 1080                 "don't actually take the action"
 1081 
 1082 dry_run :: [DarcsOption]
 1083 dry_run = [dry_run_noxml, xmloutput]
 1084 
 1085 -- | @'showFriendly' flags patch@ returns a 'Doc' representing the right
 1086 -- way to show @patch@ given the list @flags@ of flags darcs was invoked with.
 1087 showFriendly :: Patchy p => [DarcsFlag] -> p C(x y) -> Doc
 1088 showFriendly opts p | Verbose `elem` opts = showNicely p
 1089                     | Summary `elem` opts = Darcs.Patch.summary p
 1090                     | otherwise           = description p
 1091 
 1092 -- | @'print_dry_run_message_and_exit' action opts patches@ prints a string
 1093 -- representing the action that would be taken if the @--dry-run@ option
 1094 -- had not been passed to darcs. Then darcs exits successfully.
 1095 -- @action@ is the name of the action being taken, like @\"push\"@
 1096 -- @opts@ is the list of flags which were sent to darcs
 1097 -- @patches@ is the sequence of patches which would be touched by @action@.
 1098 print_dry_run_message_and_exit :: RepoPatch p => String -> [DarcsFlag] -> FL (PatchInfoAnd p) C(x y) -> IO ()
 1099 print_dry_run_message_and_exit action opts patches =
 1100      do when (DryRun `elem` opts) $ do
 1101           putInfo $ text $ "Would " ++ action ++ " the following changes:"
 1102           putDocLn $ put_mode
 1103           putInfo $ text $ ""
 1104           putInfo $ text $ "Making no changes:  this is a dry run."
 1105           exitWith ExitSuccess
 1106         when (All `elem` opts && Summary `elem` opts) $ do
 1107           putInfo $ text $ "Will " ++ action ++ " the following changes:"
 1108           putDocLn $ put_mode
 1109      where put_mode = if XMLOutput `elem` opts
 1110                       then (text "<patches>" $$
 1111                             vcat (mapFL (indent . xml_info) patches) $$
 1112                             text "</patches>")
 1113                       else (vsep $ mapFL (showFriendly opts) patches)
 1114            putInfo = if XMLOutput `elem` opts then \_ -> return () else putDocLn
 1115            xml_info pl
 1116               | Summary `elem` opts = xml_with_summary pl
 1117               | otherwise = (to_xml . info) pl
 1118             
 1119            xml_with_summary hp
 1120                | Just p <- hopefullyM hp = insert_before_lastline
 1121                                             (to_xml $ info hp) (indent $ xml_summary p)
 1122            xml_with_summary hp = to_xml (info hp)
 1123            indent = prefix "    "
 1124 
 1125 
 1126 \end{code}
 1127 
 1128 \input{Darcs/Resolution.lhs}
 1129 
 1130 \begin{code}
 1131 noskip_boring = DarcsNoArgOption [] ["boring"]
 1132                 Boring "don't skip boring files"
 1133 allow_problematic_filenames = DarcsMultipleChoiceOption
 1134                 [DarcsNoArgOption [] ["case-ok"] AllowCaseOnly
 1135                  "don't refuse to add files differing only in case"
 1136                 ,DarcsNoArgOption [] ["reserved-ok"] AllowWindowsReserved
 1137                  "don't refuse to add files with Windows-reserved names"
 1138                 ]
 1139 diffflags = DarcsArgOption [] ["diff-opts"]
 1140             DiffFlags "OPTIONS" "options to pass to diff"
 1141 
 1142 changes_format = DarcsMultipleChoiceOption
 1143                  [DarcsNoArgOption [] ["context"]
 1144                   (Context rootDirectory) "give output suitable for get --context",
 1145                   xmloutput,
 1146                   human_readable,
 1147                   DarcsNoArgOption [] ["number"] NumberPatches "number the changes",
 1148                   DarcsNoArgOption [] ["count"] Count "output count of changes"
 1149                  ]
 1150 changes_reverse = DarcsNoArgOption [] ["reverse"] Reverse
 1151                   "show changes in reverse order"
 1152 
 1153 only_to_files :: DarcsOption
 1154 only_to_files = DarcsNoArgOption [] ["only-to-files"] OnlyChangesToFiles
 1155                 "show only changes to specified files"
 1156 
 1157 human_readable = DarcsNoArgOption [] ["human-readable"]
 1158                  HumanReadable "give human-readable output"
 1159 pipe = DarcsNoArgOption [] ["pipe"] Pipe "ask user interactively for the patch metadata"
 1160 
 1161 interactive =
 1162     DarcsNoArgOption ['i'] ["interactive"] Interactive
 1163                          "prompt user interactively"
 1164 all_patches = DarcsNoArgOption ['a'] ["all"] All "answer yes to all patches"
 1165 
 1166 all_interactive = DarcsMultipleChoiceOption [all_patches, interactive]
 1167 
 1168 all_pipe_interactive
 1169     = DarcsMultipleChoiceOption [all_patches,pipe,interactive]
 1170 
 1171 pipe_interactive =
 1172     DarcsMultipleChoiceOption [pipe, interactive]
 1173 
 1174 repo_combinator =
 1175     DarcsMultipleChoiceOption
 1176     [DarcsNoArgOption [] ["intersection"] Intersection
 1177      "take intersection of all repositories",
 1178      DarcsNoArgOption [] ["union"] Union
 1179      "take union of all repositories [DEFAULT]",
 1180      DarcsNoArgOption [] ["complement"] Complement
 1181      "take complement of repositories (in order listed)"]
 1182 
 1183 -- | 'list_files' returns the list of all non-boring files in the repository
 1184 list_files :: IO [String]
 1185 list_files = do s <- slurp_all_but_darcs "."
 1186                 skip_boring <- boring_file_filter
 1187                 return (map drop_dotslash $ skip_boring $ list_slurpy s)
 1188 
 1189 drop_dotslash :: String -> String
 1190 drop_dotslash ('.':'/':x) = drop_dotslash x
 1191 drop_dotslash x = x
 1192 
 1193 -- | 'list_unregistered_files' returns the list of all non-boring unregistered
 1194 -- files in the repository.
 1195 list_unregistered_files :: IO [String]
 1196 list_unregistered_files = withRepository [] $- \repository ->
 1197     do s <- slurp_all_but_darcs "."
 1198        skip_boring <- boring_file_filter
 1199        regs <- slurp_pending repository
 1200        return $ map drop_dotslash $ (skip_boring $ list_slurpy s) \\ (list_slurpy regs)
 1201 
 1202 -- | 'list_registered_files' returns the list of all registered files in the repository.
 1203 list_registered_files :: IO [String]
 1204 list_registered_files =
 1205     (map drop_dotslash . list_slurpy) `fmap` (withRepository [] slurp_pending)
 1206 
 1207 options_latex :: [DarcsOption] -> String
 1208 options_latex opts = "\\begin{tabular}{lll}\n"++
 1209                      unlines (map option_latex opts)++
 1210                      "\\end{tabular}\n"
 1211 
 1212 latex_help :: String -> String
 1213 latex_help h
 1214     = "\\begin{minipage}{7cm}\n\\raggedright\n" ++ h ++ "\\end{minipage}\n"
 1215 
 1216 option_latex :: DarcsOption -> String
 1217 option_latex (DarcsNoArgOption a b _ h) =
 1218     show_short_options a ++ show_long_options b ++ latex_help h ++ "\\\\"
 1219 option_latex (DarcsArgOption a b _ arg h) =
 1220     show_short_options a ++
 1221     show_long_options (map (++(" "++arg)) b) ++ latex_help h ++ "\\\\"
 1222 option_latex (DarcsAbsPathOrStdOption a b _ arg h) =
 1223     show_short_options a ++
 1224     show_long_options (map (++(" "++arg)) b) ++ latex_help h ++ "\\\\"
 1225 option_latex (DarcsAbsPathOption a b _ arg h) =
 1226     show_short_options a ++
 1227     show_long_options (map (++(" "++arg)) b) ++ latex_help h ++ "\\\\"
 1228 option_latex (DarcsOptAbsPathOption a b _ _ arg h) =
 1229     show_short_options a ++
 1230     show_long_options (map (++("[="++arg++"]")) b) ++ latex_help h ++ "\\\\"
 1231 option_latex (DarcsMultipleChoiceOption os) =
 1232     unlines (map option_latex os)
 1233 
 1234 show_short_options :: [Char] -> String
 1235 show_short_options [] = "&"
 1236 show_short_options [c] = "\\verb!-"++[c]++"! &"
 1237 show_short_options (c:cs) = "\\verb!-"++[c]++"!,"++show_short_options cs
 1238 
 1239 show_long_options :: [String] -> String
 1240 show_long_options [] = " &"
 1241 show_long_options [s] = "\\verb!--" ++ s ++ "! &"
 1242 show_long_options (s:ss)
 1243     = "\\verb!--" ++ s ++ "!,"++ show_long_options ss
 1244 
 1245 set_scripts_executable :: DarcsOption
 1246 set_scripts_executable = DarcsMultipleChoiceOption
 1247                               [DarcsNoArgOption [] ["set-scripts-executable"] SetScriptsExecutable
 1248                                "make scripts executable",
 1249                                DarcsNoArgOption [] ["dont-set-scripts-executable"] DontSetScriptsExecutable
 1250                                "don't make scripts executable"]
 1251 
 1252 relink, relink_pristine, sibling :: DarcsOption
 1253 relink = DarcsNoArgOption [] ["relink"] Relink
 1254          "relink random internal data to a sibling"
 1255 
 1256 relink_pristine = DarcsNoArgOption [] ["relink-pristine"] RelinkPristine
 1257                   "relink pristine tree (not recommended)"
 1258 
 1259 sibling = DarcsAbsPathOption [] ["sibling"] Sibling "URL"
 1260           "specify a sibling directory"
 1261 
 1262 -- | 'flagsToSiblings' collects the contents of all @Sibling@ flags in a list of flags.
 1263 flagsToSiblings :: [DarcsFlag] -> [AbsolutePath]
 1264 flagsToSiblings ((Sibling s) : l) = s : (flagsToSiblings l)
 1265 flagsToSiblings (_ : l) = flagsToSiblings l
 1266 flagsToSiblings [] = []
 1267 
 1268 nolinks :: DarcsOption
 1269 nolinks = DarcsNoArgOption [] ["nolinks"] NoLinks
 1270           "do not link repository or pristine to sibling"
 1271 
 1272 reorder_patches :: DarcsOption
 1273 reorder_patches = DarcsNoArgOption [] ["reorder-patches"] Reorder
 1274                   "reorder the patches in the repository"
 1275 \end{code}
 1276 \begin{options}
 1277 --sendmail-command
 1278 \end{options}
 1279 \darcsEnv{SENDMAIL}
 1280 
 1281 \begin{code}
 1282 sendmail_cmd = DarcsArgOption [] ["sendmail-command"] SendmailCmd "COMMAND" "specify sendmail command"
 1283 
 1284 environmentHelpSendmail :: ([String], [String])
 1285 environmentHelpSendmail = (["SENDMAIL"], [
 1286  "On Unix, the `darcs send' command relies on sendmail(8).  The",
 1287  "`--sendmail-command' or $SENDMAIL environment variable can be used to",
 1288  "provide an explicit path to this program; otherwise the standard",
 1289  "locations /usr/sbin/sendmail and /usr/lib/sendmail will be tried."])
 1290 -- FIXME: mention the following also:
 1291 -- * sendmail(8) is not sendmail-specific;
 1292 -- * nowadays, desktops often have no MTA or an unconfigured MTA --
 1293 --   which is awful, because it accepts mail but doesn't relay it;
 1294 -- * in this case, can be a sendmail(8)-emulating wrapper on top of an
 1295 --   MUA that sends mail directly to a smarthost; and
 1296 -- * on a multi-user system without an MTA and on which you haven't
 1297 --   got root, can be msmtp.
 1298 
 1299 -- |'get_sendmail_cmd' takes a list of flags and returns the sendmail command
 1300 -- to be used by @darcs send@. Looks for a command specified by
 1301 -- @SendmailCmd \"command\"@ in that list of flags, if any.
 1302 -- This flag is present if darcs was invoked with @--sendmail-command=COMMAND@
 1303 -- Alternatively the user can set @$S@@ENDMAIL@ which will be used as a fallback if present.
 1304 get_sendmail_cmd :: [DarcsFlag] -> IO String 
 1305 get_sendmail_cmd (SendmailCmd a:_) = return a
 1306 get_sendmail_cmd (_:flags) = get_sendmail_cmd flags
 1307 get_sendmail_cmd [] = do easy_sendmail <- firstJustIO [ maybeGetEnv "SENDMAIL" ]
 1308                          case easy_sendmail of
 1309                             Just a -> return a
 1310                             Nothing -> return ""
 1311 
 1312 files :: DarcsOption
 1313 files = DarcsMultipleChoiceOption
 1314         [DarcsNoArgOption [] ["files"] Files
 1315          "include files in output [DEFAULT]",
 1316          DarcsNoArgOption [] ["no-files"] NoFiles
 1317          "don't include files in output"]
 1318 
 1319 directories :: DarcsOption
 1320 directories = DarcsMultipleChoiceOption
 1321               [DarcsNoArgOption [] ["directories"] Directories
 1322                "include directories in output [DEFAULT]",
 1323                DarcsNoArgOption [] ["no-directories"] NoDirectories
 1324                "don't include directories in output"]
 1325 
 1326 pending :: DarcsOption
 1327 pending = DarcsMultipleChoiceOption
 1328               [DarcsNoArgOption [] ["pending"] Pending
 1329                "reflect pending patches in output [DEFAULT]",
 1330                DarcsNoArgOption [] ["no-pending"] NoPending
 1331                "only included recorded patches in output"]
 1332 
 1333 nullFlag :: DarcsOption        -- "null" is already taken
 1334 nullFlag = DarcsNoArgOption ['0'] ["null"] NullFlag
 1335        "separate file names by NUL characters"
 1336 \end{code}
 1337 \begin{options}
 1338 --posthook=COMMAND, --no-posthook
 1339 \end{options}
 1340 To provide a command that should be run whenever a darcs command completes
 1341 successfully, use \verb!--posthook! to specify the command.  This is useful
 1342 for people who want to have a command run whenever a patch is applied.  Using
 1343 \verb!--no-posthook! will disable running the command.
 1344 \begin{options}
 1345 --run-posthook, --prompt-posthook
 1346 \end{options}
 1347 These options control prompting before running the posthook.  Use
 1348 \verb!--prompt-posthook! to have darcs prompt before running the
 1349 posthook command.  You may use --run-posthook to reenable the default
 1350 behavior of running user-specified posthooks.
 1351 
 1352 Some darcs commands export to the posthook command information about the
 1353 changes being made.  In particular, three environment variables are defined.
 1354 \verb!DARCS_PATCHES! contains a human-readable summary of the patches being
 1355 acted upon. The format is the same as "darcs changes".  \verb!DARCS_PATCHES_XML!
 1356 Contains the same details, in the same XML format as "darcs changes". Finally,
 1357 \verb!DARCS_FILES! contains a list of the files affected, one file per line.
 1358 If your repository has filenames including newlines, you'll just have to
 1359 cope.  Note, however, that \emph{none} of these environment variables are
 1360 defined when running under windows.  Note also that we refuse to pass
 1361 environment variables greater in size than 10k, in order to avoid triggering
 1362 \verb!E2BIG! errors.
 1363 
 1364 \begin{code}
 1365 definePatches :: RepoPatch p => FL (PatchInfoAnd p) C(x y) -> IO ()
 1366 #ifndef WIN32
 1367 definePatches ps = do let k = "Defining environment variables"
 1368                       beginTedious k
 1369                       tediousSize k 3
 1370                       finishedOneIO k "DARCS_PATCHES"
 1371                       setEnvCautiously "DARCS_PATCHES" (renderString $ Darcs.Patch.summary ps)
 1372                       finishedOneIO k "DARCS_PATCHES_XML"
 1373                       setEnvCautiously "DARCS_PATCHES_XML"
 1374                                  (renderString $ text "<patches>" $$
 1375                                                  vcat (mapFL (to_xml . info) ps) $$
 1376                                                  text "</patches>")
 1377                       finishedOneIO k "DARCS_FILES"
 1378                       setEnvCautiously "DARCS_FILES" (unlines$ list_touched_files ps)
 1379                       endTedious k
 1380 
 1381 setEnvCautiously :: String -> String -> IO ()
 1382 setEnvCautiously e v | toobig (10*1024) v = return ()
 1383                      | otherwise = setEnv e v True
 1384     where toobig :: Int -> [a] -> Bool
 1385           toobig 0 _ = True
 1386           toobig _ [] = False
 1387           toobig n (_:xs) = toobig (n-1) xs
 1388 #else
 1389 definePatches _ = return ()
 1390 #endif
 1391 
 1392 defineChanges :: Patchy p => p C(x y) -> IO ()
 1393 #ifndef WIN32
 1394 defineChanges ps = setEnvCautiously "DARCS_FILES" (unlines $ list_touched_files ps)
 1395 #else
 1396 defineChanges _ = return ()
 1397 #endif
 1398 
 1399 posthook_cmd :: DarcsOption
 1400 posthook_cmd = DarcsMultipleChoiceOption
 1401                [DarcsArgOption [] ["posthook"] PosthookCmd
 1402                 "COMMAND" "specify command to run after this darcs command",
 1403                 DarcsNoArgOption [] ["no-posthook"] NoPosthook
 1404                 "don't run posthook command"]
 1405 
 1406 posthook_prompt :: DarcsOption
 1407 posthook_prompt = DarcsMultipleChoiceOption
 1408                   [DarcsNoArgOption [] ["prompt-posthook"] AskPosthook
 1409                    "prompt before running posthook [DEFAULT]",
 1410                    DarcsNoArgOption [] ["run-posthook"] RunPosthook
 1411                    "run posthook command without prompting"]
 1412 
 1413 -- | 'get_posthook_cmd' takes a list of flags and returns the posthook command
 1414 --  specified by @PosthookCmd a@ in that list of flags, if any.
 1415 get_posthook_cmd :: [DarcsFlag] -> Maybe String
 1416 get_posthook_cmd (PosthookCmd a:_) = Just a
 1417 get_posthook_cmd (_:flags) = get_posthook_cmd flags
 1418 get_posthook_cmd [] = Nothing
 1419 \end{code}
 1420 \begin{options}
 1421 --prehook=COMMAND, --no-prehook
 1422 \end{options}
 1423 To provide a command that should be run before a darcs command is executed,
 1424  use \verb!--prehook! to specify the command.  An example use is
 1425 for people who want to have a command run whenever a patch is to be recorded, such as
 1426 translating line endings before recording patches.  Using
 1427 \verb!--no-prehook! will disable running the command.
 1428 \begin{options}
 1429 --run-prehook, --prompt-prehook
 1430 \end{options}
 1431 These options control prompting before running the prehook.  See the
 1432 posthook documentation above for details.
 1433 \begin{code}
 1434 prehook_cmd :: DarcsOption
 1435 prehook_cmd = DarcsMultipleChoiceOption
 1436                [DarcsArgOption [] ["prehook"] PrehookCmd
 1437                 "COMMAND" "specify command to run before this darcs command",
 1438                 DarcsNoArgOption [] ["no-prehook"] NoPrehook
 1439                 "don't run prehook command"]
 1440 
 1441 prehook_prompt :: DarcsOption
 1442 prehook_prompt = DarcsMultipleChoiceOption
 1443                   [DarcsNoArgOption [] ["prompt-prehook"] AskPrehook
 1444                    "prompt before running prehook [DEFAULT]",
 1445                    DarcsNoArgOption [] ["run-prehook"] RunPrehook
 1446                    "run prehook command without prompting"]
 1447 
 1448 -- | 'get_prehook_cmd' takes a list of flags and returns the prehook command
 1449 --  specified by @PrehookCmd a@ in that list of flags, if any.
 1450 get_prehook_cmd :: [DarcsFlag] -> Maybe String
 1451 get_prehook_cmd (PrehookCmd a:_) = Just a
 1452 get_prehook_cmd (_:flags) = get_prehook_cmd flags
 1453 get_prehook_cmd [] = Nothing
 1454 \end{code}
 1455 
 1456 \begin{options}
 1457 --ssh-cm, --no-ssh-cm
 1458 \end{options}
 1459 
 1460 For commands which invoke ssh, darcs will normally multiplex ssh
 1461 sessions over a single connection as long as your version of ssh has
 1462 the ControlMaster feature from OpenSSH versions 3.9 and above.  This
 1463 option will avoid darcs trying to use this feature even if your ssh
 1464 supports it.
 1465 
 1466 \begin{options}
 1467 --http-pipelining, --no-http-pipelining
 1468 \end{options}
 1469 
 1470 When compiled with libcurl (version 7.18.0 and above), darcs can
 1471 use HTTP pipelining. It is enabled by default for libcurl
 1472 (version 7.19.1 and above). This option will make darcs enable or
 1473 disable HTTP pipelining, overwriting default. Note that if HTTP
 1474 pipelining is really used depends on the server.
 1475 
 1476 \begin{options}
 1477 --no-cache
 1478 \end{options}
 1479 
 1480 Do not use patch caches.
 1481 \begin{code}
 1482 network_options :: [DarcsOption]
 1483 network_options =
 1484     [DarcsMultipleChoiceOption
 1485      [DarcsNoArgOption [] ["ssh-cm"] SSHControlMaster
 1486                            "use SSH ControlMaster feature",
 1487       DarcsNoArgOption [] ["no-ssh-cm"] NoSSHControlMaster
 1488                            "don't use SSH ControlMaster feature [DEFAULT]"],
 1489      DarcsMultipleChoiceOption
 1490      [DarcsNoArgOption [] ["http-pipelining"] HTTPPipelining
 1491                            pipelining_description,
 1492       DarcsNoArgOption [] ["no-http-pipelining"] NoHTTPPipelining
 1493                            no_pipelining_description],
 1494       no_cache
 1495      ]
 1496     where pipelining_description =
 1497               "enable HTTP pipelining"++
 1498               (if pipeliningEnabledByDefault then " [DEFAULT]" else "")
 1499           no_pipelining_description =
 1500               "disable HTTP pipelining"++
 1501               (if pipeliningEnabledByDefault then "" else " [DEFAULT]")
 1502 
 1503 no_cache :: DarcsOption
 1504 no_cache = DarcsNoArgOption [] ["no-cache"] NoCache
 1505                           "don't use patch caches"
 1506 \end{code}
 1507 \begin{options}
 1508 --umask
 1509 \end{options}
 1510 By default, Darcs will use your current umask.  The option
 1511 \verb|--umask| will cause Darcs to switch to a different umask before
 1512 writing to the repository.
 1513 
 1514 \begin{code}
 1515 umask_option :: DarcsOption
 1516 umask_option =
 1517     DarcsArgOption [] ["umask"] UMask "UMASK"
 1518         "specify umask to use when writing"
 1519 \end{code}
 1520 
 1521 \begin{options}
 1522 --dont-restrict-paths, --restrict-paths
 1523 \end{options}
 1524 By default darcs is only allowed to manage and modify files and directories
 1525 contained inside the current repository and not being part of any darcs
 1526 repository's meta data (including the current one). This is mainly for
 1527 security, to protect you from spoofed patches modifying arbitrary files
 1528 with sensitive data---say, in your home directory---or tampering with any
 1529 repository's meta data to switch off this safety guard.
 1530 
 1531 But sometimes you may want to manage a group of ``sub'' repositories'
 1532 preference files with a global repository, or use darcs in some other
 1533 advanced way. The best way is probably to put
 1534 \verb!ALL dont-restrict-paths! in \verb!_darcs/prefs/defaults!. This turns
 1535 off all sanity checking for file paths in patches.
 1536 
 1537 Path checking can be temporarily turned on with \verb!--restrict-paths! on
 1538 the command line, when pulling or applying unknown patches.
 1539 
 1540 \begin{code}
 1541 restrict_paths =
 1542     DarcsMultipleChoiceOption
 1543     [DarcsNoArgOption [] ["restrict-paths"] RestrictPaths
 1544      "don't allow darcs to touch external files or repo metadata",
 1545      DarcsNoArgOption [] ["dont-restrict-paths"] DontRestrictPaths
 1546      "allow darcs to modify any file or directory (unsafe)"]
 1547 \end{code}
 1548 
 1549 \begin{options}
 1550 --allow-unrelated-repos
 1551 \end{options}
 1552 By default darcs checks and warns user if repositories are unrelated when
 1553 doing pull, push and send. This option makes darcs skip this check.
 1554 
 1555 \begin{code}
 1556 allow_unrelated_repos =
 1557     DarcsNoArgOption [] ["ignore-unrelated-repos"] AllowUnrelatedRepos
 1558                          "do not check if repositories are unrelated"
 1559 \end{code}
 1560 
 1561 \begin{code}
 1562 just_this_repo :: DarcsOption
 1563 \end{code}
 1564 
 1565 \begin{options}
 1566 --just-this-repo
 1567 \end{options}
 1568 This option limits the check or repair to the current repo and
 1569 omits any caches or other repos listed as a source of patches.
 1570 
 1571 \begin{code}
 1572 just_this_repo =
 1573     DarcsNoArgOption [] ["just-this-repo"] JustThisRepo
 1574                         "Limit the check or repair to the current repo"
 1575 \end{code}
 1576 
 1577 \begin{code}
 1578 check, repair, check_or_repair :: DarcsOption
 1579 \end{code}
 1580 
 1581 \begin{options}
 1582 --check
 1583 \end{options}
 1584 This option specifies checking mode.
 1585 
 1586 \begin{code}
 1587 check =
 1588     DarcsNoArgOption [] ["check"] Check
 1589                         "Specify checking mode"
 1590 \end{code}
 1591 
 1592 \begin{options}
 1593 --repair
 1594 \end{options}
 1595 This option specifies repair mode.
 1596 
 1597 \begin{code}
 1598 repair =
 1599     DarcsNoArgOption [] ["repair"] Repair
 1600                         "Specify repair mode"
 1601 
 1602 check_or_repair = concat_options [check, repair]
 1603 
 1604 -- | @'patch_select_flag' f@ holds whenever @f@ is a way of selecting
 1605 -- patches such as @PatchName n@.
 1606 patch_select_flag :: DarcsFlag -> Bool
 1607 patch_select_flag All = True
 1608 patch_select_flag (PatchName _) = True
 1609 patch_select_flag (OnePatch _) = True
 1610 patch_select_flag (SeveralPatch _) = True
 1611 patch_select_flag (AfterPatch _) = True
 1612 patch_select_flag (UpToPatch _) = True
 1613 patch_select_flag (TagName _) = True
 1614 patch_select_flag (LastN _) = True
 1615 patch_select_flag (OneTag _) = True
 1616 patch_select_flag (AfterTag _) = True
 1617 patch_select_flag (UpToTag _) = True
 1618 patch_select_flag (OnePattern _) = True
 1619 patch_select_flag (SeveralPattern _) = True
 1620 patch_select_flag (AfterPattern _) = True
 1621 patch_select_flag (UpToPattern _) = True
 1622 patch_select_flag _ = False
 1623 
 1624 -- | The integer corresponding to a string, if it's only composed of digits.
 1625 --   Otherwise, -1.
 1626 number_string :: String -> Int
 1627 number_string s = if and (map isDigit s) then read s else (-1)
 1628 \end{code}