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

{-# LANGUAGE OverloadedStrings #-}
module Darcs.UI.Commands.Pull ( -- * Commands.
                                pull, fetch,
                                pullCmd, StandardPatchApplier,
                                -- * Utility functions.
                                fetchPatches
                              ) where

import Darcs.Prelude

import System.Exit ( exitSuccess )
import Control.Monad ( when, unless, (>=>) )
import Data.List ( nub )
import Data.Maybe ( fromMaybe )
import Safe ( headErr, tailErr )

import Darcs.UI.Commands
    ( DarcsCommand(..)
    , withStdOpts
    , putInfo
    , putVerbose
    , setEnvDarcsPatches
    , defaultRepo
    , amInHashedRepository
    )
import Darcs.UI.Commands.Clone ( otherHelpInheritDefault )
import Darcs.UI.Flags
    ( DarcsFlag
    , fixUrl, getOutput
    , changesReverse, verbosity,  dryRun, umask, useCache, selectDeps
    , reorder, setDefault
    , hasXmlOutput
    , isInteractive, quiet
    )
import Darcs.UI.Options ( parseFlags, (?), (^) )
import qualified Darcs.UI.Options.All as O
import Darcs.Repository
    ( Repository
    , AccessType(..)
    , identifyRepositoryFor
    , ReadingOrWriting(..)
    , withRepoLock
    , RepoJob(..)
    , readPatches
    , modifyCache
    , mkCache
    , cacheEntries
    , CacheLoc(..)
    , WritableOrNot(..)
    , CacheType(..)
    , filterOutConflicts
    )

import Darcs.Patch.PatchInfoAnd ( PatchInfoAnd, info, hopefully, patchDesc )
import Darcs.Patch ( RepoPatch, description )
import qualified Darcs.Patch.Bundle as Bundle ( makeBundle )
import Darcs.Patch.Apply( ApplyState )
import Darcs.Patch.Set ( PatchSet, Origin, emptyPatchSet, SealedPatchSet )
import Darcs.Patch.Witnesses.Sealed ( Sealed(..), seal )
import Darcs.Patch.Witnesses.Ordered
    ( (:>)(..), FL(..), Fork(..)
    , mapFL, nullFL, mapFL_FL )
import Darcs.Patch.Permutations ( partitionFL )
import Darcs.Repository.Prefs
    ( Pref(Defaultrepo, Repos)
    , addRepoSource
    , addToPreflist
    , getPreflist
    , showMotd
    )
import Darcs.Patch.Depends
    ( findCommon
    , findCommonWithThem
    , patchSetIntersection
    , patchSetUnion
    )
import Darcs.UI.ApplyPatches ( PatchApplier(..), StandardPatchApplier(..) )
import Darcs.UI.Completion ( prefArgs )
import Darcs.UI.Commands.Util ( checkUnrelatedRepos, getUniqueDPatchName )
import Darcs.UI.SelectChanges
    ( WhichChanges(..)
    , runSelection
    , selectionConfig
    )
import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) )
import Darcs.Util.Printer
    ( Doc
    , ($$)
    , ($+$)
    , (<+>)
    , formatWords
    , hsep
    , putDoc
    , quoted
    , text
    , vcat
    )
import Darcs.Util.Lock ( writeDocBinFile )
import Darcs.Util.Path ( useAbsoluteOrStd, stdOut, AbsolutePath )
import Darcs.Util.Workaround ( getCurrentDirectory )
import Darcs.Util.Tree( Tree )

pullDescription :: String
pullDescription :: String
pullDescription =
 String
"Copy and apply patches from another repository to this one."

fetchDescription :: String
fetchDescription :: String
fetchDescription =
 String
"Fetch patches from another repository, but don't apply them."

pullHelp :: Doc
pullHelp :: Doc
pullHelp =
  [String] -> Doc
formatWords
  [ String
"Pull is used to bring patches made in another repository into the current"
  , String
"repository (that is, either the one in the current directory, or the one"
  , String
"specified with the `--repodir` option). Pull accepts arguments, which are"
  , String
"URLs from which to pull, and when called without an argument, pull will"
  , String
"use the repository specified at `_darcs/prefs/defaultrepo`."
  ]
  Doc -> Doc -> Doc
$+$ [String] -> Doc
formatWords
  [ String
"The default (`--union`) behavior is to pull any patches that are in any of"
  , String
"the specified repositories.  If you specify the `--intersection` flag, darcs"
  , String
"will only pull those patches which are present in all source repositories."
  , String
"If you specify the `--complement` flag, darcs will only pull elements in the"
  , String
"first repository that do not exist in any of the remaining repositories."
  ]
  Doc -> Doc -> Doc
$+$ [String] -> Doc
formatWords
  [ String
"If `--reorder` is supplied, the set of patches that exist only in the current"
  , String
"repository is brought at the top of the current history. This will work even"
  , String
"if there are no new patches to pull."
  ]
  Doc -> Doc -> Doc
$+$ Doc
otherHelpInheritDefault
  Doc -> Doc -> Doc
$+$ [String] -> Doc
formatWords
  [ String
"See `darcs help apply` for detailed description of many options."
  ]

fetchHelp :: Doc
fetchHelp :: Doc
fetchHelp =
  [String] -> Doc
formatWords
  [ String
"Fetch is similar to `pull` except that it does not apply any patches"
  , String
"to the current repository. Instead, it generates a patch bundle that"
  , String
"you can apply later with `apply`."
  ]
  Doc -> Doc -> Doc
$+$ [String] -> Doc
formatWords
  [ String
"Fetch's behaviour is essentially similar to pull's, so please consult"
  , String
"the help of `pull` to know more."
  ]

fetch :: DarcsCommand
fetch :: DarcsCommand
fetch = DarcsCommand
    { commandProgramName :: String
commandProgramName = String
"darcs"
    , commandName :: String
commandName = String
"fetch"
    , commandHelp :: Doc
commandHelp = Doc
fetchHelp
    , commandDescription :: String
commandDescription = String
fetchDescription
    , commandExtraArgs :: Int
commandExtraArgs = -Int
1
    , commandExtraArgHelp :: [String]
commandExtraArgHelp = [String
"[REPOSITORY]..."]
    , commandCommand :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
commandCommand = (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
fetchCmd
    , commandPrereq :: [DarcsFlag] -> IO (Either String ())
commandPrereq = [DarcsFlag] -> IO (Either String ())
amInHashedRepository
    , commandCompleteArgs :: (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
commandCompleteArgs = Pref
-> (AbsolutePath, AbsolutePath)
-> [DarcsFlag]
-> [String]
-> IO [String]
prefArgs Pref
Repos
    , commandArgdefaults :: [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
commandArgdefaults = [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
defaultRepo
    , commandOptions :: CommandOptions
commandOptions = CommandOptions
allOpts
    }
  where
    basicOpts :: OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
basicOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  [MatchFlag]
MatchOption
O.matchSeveral
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  [MatchFlag]
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
     (Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  (Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe Bool)
O.interactive -- True
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
     (DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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
  (WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  (DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption DryRun
O.dryRun
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
     (WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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
  (SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  (WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption WithSummary
O.withSummary
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
     (SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  (SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption SelectDeps
O.selectDeps
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (InheritDefault
      -> Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
     (Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (InheritDefault
      -> Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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
  (InheritDefault
   -> Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
  (Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe Bool)
O.setDefault
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (InheritDefault
   -> Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
     (InheritDefault
      -> Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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 -> Maybe Output -> Bool -> DiffAlgorithm -> a)
  (InheritDefault
   -> Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
PrimDarcsOption InheritDefault
O.inheritDefault
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Output -> Bool -> DiffAlgorithm -> a)
     (Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Output -> Bool -> DiffAlgorithm -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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 Output -> Bool -> DiffAlgorithm -> a)
  (Maybe String -> Maybe Output -> Bool -> DiffAlgorithm -> a)
PrimDarcsOption (Maybe String)
O.repoDir
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Output -> Bool -> DiffAlgorithm -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> DiffAlgorithm -> a)
     (Maybe Output -> Bool -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> DiffAlgorithm -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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 -> DiffAlgorithm -> a)
  (Maybe Output -> Bool -> DiffAlgorithm -> a)
PrimDarcsOption (Maybe Output)
O.output
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> DiffAlgorithm -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     (Bool -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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)
  (Bool -> DiffAlgorithm -> a)
PrimDarcsOption Bool
O.allowUnrelatedRepos
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (DiffAlgorithm -> a)
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     a
     ([MatchFlag]
      -> Maybe Bool
      -> DryRun
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Maybe Output
      -> Bool
      -> 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 (RepoCombinator -> RemoteDarcs -> a)
advancedOpts
      = PrimOptSpec
  DarcsOptDescr DarcsFlag (RemoteDarcs -> a) RepoCombinator
PrimDarcsOption RepoCombinator
O.repoCombinator
      PrimOptSpec
  DarcsOptDescr DarcsFlag (RemoteDarcs -> a) RepoCombinator
-> OptSpec DarcsOptDescr DarcsFlag a (RemoteDarcs -> a)
-> OptSpec
     DarcsOptDescr DarcsFlag a (RepoCombinator -> RemoteDarcs -> 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 (RemoteDarcs -> a)
PrimDarcsOption RemoteDarcs
O.remoteDarcs
    allOpts :: CommandOptions
allOpts = OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe StdCmdAction
   -> Verbosity
   -> RepoCombinator
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> RepoCombinator
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
forall {a}.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> a)
basicOpts OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe StdCmdAction
   -> Verbosity
   -> RepoCombinator
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
  ([MatchFlag]
   -> Maybe Bool
   -> DryRun
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Maybe Output
   -> Bool
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> RepoCombinator
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
-> DarcsOption
     (UseCache
      -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
     (RepoCombinator
      -> RemoteDarcs
      -> UseCache
      -> UseIndex
      -> HooksConfig
      -> Bool
      -> Bool
      -> [DarcsFlag])
-> CommandOptions
forall b c.
DarcsOption (Maybe StdCmdAction -> Verbosity -> b) c
-> DarcsOption
     (UseCache
      -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
     b
-> CommandOptions
`withStdOpts` DarcsOption
  (UseCache
   -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
  (RepoCombinator
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
forall {a}.
OptSpec
  DarcsOptDescr DarcsFlag a (RepoCombinator -> RemoteDarcs -> a)
advancedOpts

pull :: DarcsCommand
pull :: DarcsCommand
pull = DarcsCommand
    { commandProgramName :: String
commandProgramName = String
"darcs"
    , commandName :: String
commandName = String
"pull"
    , commandHelp :: Doc
commandHelp = Doc
pullHelp
    , commandDescription :: String
commandDescription = String
pullDescription
    , commandExtraArgs :: Int
commandExtraArgs = -Int
1
    , commandExtraArgHelp :: [String]
commandExtraArgHelp = [String
"[REPOSITORY]..."]
    , commandCommand :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
commandCommand = StandardPatchApplier
-> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
forall pa.
PatchApplier pa =>
pa
-> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
pullCmd StandardPatchApplier
StandardPatchApplier
    , commandPrereq :: [DarcsFlag] -> IO (Either String ())
commandPrereq = [DarcsFlag] -> IO (Either String ())
amInHashedRepository
    , commandCompleteArgs :: (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
commandCompleteArgs = Pref
-> (AbsolutePath, AbsolutePath)
-> [DarcsFlag]
-> [String]
-> IO [String]
prefArgs Pref
Repos
    , commandArgdefaults :: [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
commandArgdefaults = [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
defaultRepo
    , commandOptions :: CommandOptions
commandOptions = CommandOptions
allOpts
    }
  where
    basicOpts :: OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
basicOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  [MatchFlag]
MatchOption
O.matchSeveral
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  [MatchFlag]
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     (Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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 AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  (Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption Reorder
O.reorder
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     (Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  (Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe Bool)
O.interactive
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     (Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  (Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption (Maybe AllowConflicts)
O.conflictsYes
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     (TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  (TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption TestChanges
O.testChanges
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     (DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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
  (WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  (DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
forall a. DarcsOption a (DryRun -> XmlOutput -> a)
O.dryRunXml
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     (WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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
  (SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  (WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption WithSummary
O.withSummary
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
     (SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> DiffAlgorithm
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool
      -> InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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
   -> InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
  (SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
PrimDarcsOption SelectDeps
O.selectDeps
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool
   -> InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
     (Maybe Bool
      -> InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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
  (InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
  (Maybe Bool
   -> InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
PrimDarcsOption (Maybe Bool)
O.setDefault
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> Bool -> DiffAlgorithm -> a)
     (InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> Bool -> DiffAlgorithm -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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 -> DiffAlgorithm -> a)
  (InheritDefault -> Maybe String -> Bool -> DiffAlgorithm -> a)
PrimDarcsOption InheritDefault
O.inheritDefault
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String -> Bool -> DiffAlgorithm -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> DiffAlgorithm -> a)
     (Maybe String -> Bool -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> DiffAlgorithm -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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 -> DiffAlgorithm -> a)
  (Maybe String -> Bool -> DiffAlgorithm -> a)
PrimDarcsOption (Maybe String)
O.repoDir
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> DiffAlgorithm -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     (Bool -> DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (DiffAlgorithm -> a)
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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)
  (Bool -> DiffAlgorithm -> a)
PrimDarcsOption Bool
O.allowUnrelatedRepos
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (DiffAlgorithm -> a)
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (DiffAlgorithm -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     a
     ([MatchFlag]
      -> Reorder
      -> Maybe Bool
      -> Maybe AllowConflicts
      -> TestChanges
      -> DryRun
      -> XmlOutput
      -> WithSummary
      -> SelectDeps
      -> Maybe Bool
      -> InheritDefault
      -> Maybe String
      -> Bool
      -> 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
  (RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> a)
advancedOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (SetScriptsExecutable
   -> UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
  RepoCombinator
PrimDarcsOption RepoCombinator
O.repoCombinator
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (SetScriptsExecutable
   -> UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
  RepoCombinator
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
     (SetScriptsExecutable
      -> UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
     (RepoCombinator
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> WantGuiPause
      -> RemoteDarcs
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
  (SetScriptsExecutable
   -> UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
PrimDarcsOption SetScriptsExecutable
O.setScriptsExecutable
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
  (RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> WantGuiPause -> RemoteDarcs -> a)
     (UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> WantGuiPause -> RemoteDarcs -> a)
     (RepoCombinator
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> WantGuiPause
      -> RemoteDarcs
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> WantGuiPause -> RemoteDarcs -> a)
  (UMask -> Bool -> WantGuiPause -> RemoteDarcs -> a)
PrimDarcsOption UMask
O.umask
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> WantGuiPause -> RemoteDarcs -> a)
  (RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WantGuiPause -> RemoteDarcs -> a)
     (Bool -> WantGuiPause -> RemoteDarcs -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (WantGuiPause -> RemoteDarcs -> a)
     (RepoCombinator
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> WantGuiPause
      -> RemoteDarcs
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (WantGuiPause -> RemoteDarcs -> a)
  (Bool -> WantGuiPause -> RemoteDarcs -> a)
PrimDarcsOption Bool
O.changesReverse
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (WantGuiPause -> RemoteDarcs -> a)
  (RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (RemoteDarcs -> a)
     (WantGuiPause -> RemoteDarcs -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (RemoteDarcs -> a)
     (RepoCombinator
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> WantGuiPause
      -> RemoteDarcs
      -> 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
  (RemoteDarcs -> a)
  (WantGuiPause -> RemoteDarcs -> a)
PrimDarcsOption WantGuiPause
O.pauseForGui
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (RemoteDarcs -> a)
  (RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (RemoteDarcs -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     a
     (RepoCombinator
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> WantGuiPause
      -> RemoteDarcs
      -> 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 (RemoteDarcs -> a)
PrimDarcsOption RemoteDarcs
O.remoteDarcs
    allOpts :: CommandOptions
allOpts = OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe StdCmdAction
   -> Verbosity
   -> RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
forall {a}.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> a)
basicOpts OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe StdCmdAction
   -> Verbosity
   -> RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
  ([MatchFlag]
   -> Reorder
   -> Maybe Bool
   -> Maybe AllowConflicts
   -> TestChanges
   -> DryRun
   -> XmlOutput
   -> WithSummary
   -> SelectDeps
   -> Maybe Bool
   -> InheritDefault
   -> Maybe String
   -> Bool
   -> DiffAlgorithm
   -> Maybe StdCmdAction
   -> Verbosity
   -> RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
-> DarcsOption
     (UseCache
      -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
     (RepoCombinator
      -> SetScriptsExecutable
      -> UMask
      -> Bool
      -> WantGuiPause
      -> RemoteDarcs
      -> UseCache
      -> UseIndex
      -> HooksConfig
      -> Bool
      -> Bool
      -> [DarcsFlag])
-> CommandOptions
forall b c.
DarcsOption (Maybe StdCmdAction -> Verbosity -> b) c
-> DarcsOption
     (UseCache
      -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
     b
-> CommandOptions
`withStdOpts` DarcsOption
  (UseCache
   -> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
  (RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> UseCache
   -> UseIndex
   -> HooksConfig
   -> Bool
   -> Bool
   -> [DarcsFlag])
forall {a}.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  (RepoCombinator
   -> SetScriptsExecutable
   -> UMask
   -> Bool
   -> WantGuiPause
   -> RemoteDarcs
   -> a)
advancedOpts

pullCmd
  :: PatchApplier pa
  => pa -> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
pullCmd :: forall pa.
PatchApplier pa =>
pa
-> (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
pullCmd pa
patchApplier (AbsolutePath
_,AbsolutePath
o) [DarcsFlag]
opts [String]
repos =
  do
    pullingFrom <- (String -> IO String) -> [String] -> IO [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (AbsolutePath -> String -> IO String
fixUrl AbsolutePath
o) [String]
repos
    withRepoLock (useCache ? opts) (umask ? opts) $
     repoJob patchApplier $ \PatchProxy p
patchProxy Repository 'RW p wU wR
initRepo -> do
      let repository :: Repository 'RW p wU wR
repository = (Cache -> Cache)
-> Repository 'RW p wU wR -> Repository 'RW p wU wR
forall (rt :: AccessType) (p :: * -> * -> *) wU wR.
(Cache -> Cache) -> Repository rt p wU wR -> Repository rt p wU wR
modifyCache ([String] -> Cache -> Cache
addReposToCache [String]
pullingFrom) Repository 'RW p wU wR
initRepo
      Sealed fork <- AbsolutePath
-> [DarcsFlag]
-> [String]
-> String
-> Repository 'RW p wU wR
-> IO
     (Sealed
        (Fork
           (PatchSet p)
           (FL (PatchInfoAnd p))
           (FL (PatchInfoAnd p))
           Origin
           wR))
forall (p :: * -> * -> *) wU wR.
(RepoPatch p, ApplyState p ~ Tree) =>
AbsolutePath
-> [DarcsFlag]
-> [String]
-> String
-> Repository 'RW p wU wR
-> IO
     (Sealed
        (Fork
           (PatchSet p)
           (FL (PatchInfoAnd p))
           (FL (PatchInfoAnd p))
           Origin
           wR))
fetchPatches AbsolutePath
o [DarcsFlag]
opts [String]
repos String
"pull" Repository 'RW p wU wR
repository
      applyPatches patchApplier patchProxy "pull" opts repository fork
    where
      addReposToCache :: [String] -> Cache -> Cache
addReposToCache [String]
repos' Cache
cache =
        [CacheLoc] -> Cache
mkCache ([CacheLoc] -> Cache) -> [CacheLoc] -> Cache
forall a b. (a -> b) -> a -> b
$ [ String -> CacheLoc
toReadOnlyCache String
r | String
r <- [String]
repos' ] [CacheLoc] -> [CacheLoc] -> [CacheLoc]
forall a. [a] -> [a] -> [a]
++ Cache -> [CacheLoc]
cacheEntries Cache
cache
      toReadOnlyCache :: String -> CacheLoc
toReadOnlyCache = CacheType -> WritableOrNot -> String -> CacheLoc
Cache CacheType
Repo WritableOrNot
NotWritable


fetchCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
fetchCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
fetchCmd (AbsolutePath
_,AbsolutePath
o) [DarcsFlag]
opts [String]
repos =
    UseCache -> UMask -> RepoJob 'RW () -> IO ()
forall a. UseCache -> UMask -> RepoJob 'RW a -> IO a
withRepoLock (PrimOptSpec DarcsOptDescr DarcsFlag a UseCache
PrimDarcsOption UseCache
useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) (PrimOptSpec DarcsOptDescr DarcsFlag a UMask
PrimDarcsOption UMask
umask PrimDarcsOption UMask -> [DarcsFlag] -> UMask
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) (RepoJob 'RW () -> IO ()) -> RepoJob 'RW () -> IO ()
forall a b. (a -> b) -> a -> b
$ TreePatchJob 'RW () -> RepoJob 'RW ()
forall (rt :: AccessType) a. TreePatchJob rt a -> RepoJob rt a
RepoJob (TreePatchJob 'RW () -> RepoJob 'RW ())
-> TreePatchJob 'RW () -> RepoJob 'RW ()
forall a b. (a -> b) -> a -> b
$
        AbsolutePath
-> [DarcsFlag]
-> [String]
-> String
-> Repository 'RW p wU wR
-> IO
     (Sealed
        (Fork
           (PatchSet p)
           (FL (PatchInfoAnd p))
           (FL (PatchInfoAnd p))
           Origin
           wR))
forall (p :: * -> * -> *) wU wR.
(RepoPatch p, ApplyState p ~ Tree) =>
AbsolutePath
-> [DarcsFlag]
-> [String]
-> String
-> Repository 'RW p wU wR
-> IO
     (Sealed
        (Fork
           (PatchSet p)
           (FL (PatchInfoAnd p))
           (FL (PatchInfoAnd p))
           Origin
           wR))
fetchPatches AbsolutePath
o [DarcsFlag]
opts [String]
repos String
"fetch" (Repository 'RW p wU wR
 -> IO
      (Sealed
         (Fork
            (PatchSet p)
            (FL (PatchInfoAnd p))
            (FL (PatchInfoAnd p))
            Origin
            wR)))
-> (Sealed
      (Fork
         (PatchSet p) (FL (PatchInfoAnd p)) (FL (PatchInfoAnd p)) Origin wR)
    -> IO ())
-> Repository 'RW p wU wR
-> IO ()
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> [DarcsFlag]
-> Sealed
     (Fork
        (PatchSet p) (FL (PatchInfoAnd p)) (FL (PatchInfoAnd p)) Origin wR)
-> IO ()
forall (p :: * -> * -> *) wR.
(RepoPatch p, ApplyState p ~ Tree) =>
[DarcsFlag]
-> Sealed
     (Fork
        (PatchSet p) (FL (PatchInfoAnd p)) (FL (PatchInfoAnd p)) Origin wR)
-> IO ()
makeBundle [DarcsFlag]
opts

fetchPatches :: (RepoPatch p, ApplyState p ~ Tree)
             => AbsolutePath -> [DarcsFlag] -> [String] -> String
             -> Repository 'RW p wU wR
             -> IO (Sealed (Fork (PatchSet p)
                                 (FL (PatchInfoAnd p))
                                 (FL (PatchInfoAnd p)) Origin wR))
fetchPatches :: forall (p :: * -> * -> *) wU wR.
(RepoPatch p, ApplyState p ~ Tree) =>
AbsolutePath
-> [DarcsFlag]
-> [String]
-> String
-> Repository 'RW p wU wR
-> IO
     (Sealed
        (Fork
           (PatchSet p)
           (FL (PatchInfoAnd p))
           (FL (PatchInfoAnd p))
           Origin
           wR))
fetchPatches AbsolutePath
o [DarcsFlag]
opts unfixedrepourls :: [String]
unfixedrepourls@(String
_:[String]
_) String
jobname Repository 'RW p wU wR
repository = do
  here <- IO String
getCurrentDirectory
  repourls <- (nub . filter (/= here)) `fmap` mapM (fixUrl o) unfixedrepourls
  -- Test to make sure we aren't trying to pull from the current repo
  when (null repourls) $
        fail "Can't pull from current repository!"
  old_default <- getPreflist Defaultrepo
  when (old_default == repourls && not (hasXmlOutput opts)) $
      let pulling = case PrimOptSpec DarcsOptDescr DarcsFlag a DryRun
PrimDarcsOption DryRun
dryRun PrimDarcsOption DryRun -> [DarcsFlag] -> DryRun
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts of
                      DryRun
O.YesDryRun -> String
"Would pull"
                      DryRun
O.NoDryRun -> String
"Pulling"
      in  putInfo opts $ text pulling <+> "from" <+> hsep (map quoted repourls) <> "..."
  (Sealed them, Sealed compl) <- readRepos repository opts repourls
  addRepoSource (headErr repourls) (dryRun ? opts)
      (setDefault False opts) (O.inheritDefault ? opts) (isInteractive True opts)
  mapM_ (addToPreflist Repos) repourls
  unless (quiet opts || hasXmlOutput opts) $ mapM_ showMotd repourls
  us <- readPatches repository
  checkUnrelatedRepos (parseFlags O.allowUnrelatedRepos opts) us them

  Fork common us' them' <- return $ findCommon us them
  _ :> compl' <- return $ findCommonWithThem compl us

  let avoided = (forall wW wZ. PatchInfoAnd p wW wZ -> PatchInfo)
-> FL (PatchInfoAnd p) wZ wX -> [PatchInfo]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL PatchInfoAndG (Named p) wW wZ -> PatchInfo
forall wW wZ. PatchInfoAnd p wW wZ -> PatchInfo
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> PatchInfo
info FL (PatchInfoAnd p) wZ wX
compl'
  ps :> _ <- return $ partitionFL (not . (`elem` avoided) . info) them'
  putVerbose opts $
    case us' of
      (x :: FL (PatchInfoAnd p) wU wR
x@(PatchInfoAnd p wU wY
_ :>: FL (PatchInfoAnd p) wY wR
_)) ->
        String -> Doc
text String
"We have the following new (to them) patches:" Doc -> Doc -> Doc
$$
        [Doc] -> Doc
vcat ((forall wW wZ. PatchInfoAnd p wW wZ -> Doc)
-> FL (PatchInfoAnd p) wU wR -> [Doc]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> FL a wX wY -> [b]
mapFL PatchInfoAnd p wW wZ -> Doc
forall wW wZ. PatchInfoAnd p wW wZ -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description FL (PatchInfoAnd p) wU wR
x)
      FL (PatchInfoAnd p) wU wR
_ -> Doc
forall a. Monoid a => a
mempty
  unless (nullFL ps) $ putVerbose opts $
      text "They have the following patches to pull:" $$
      vcat (mapFL description ps)
  (hadConflicts, Sealed psFiltered)
    <- if O.conflictsYes ? opts == Nothing
        then filterOutConflicts repository (O.useIndex ? opts) us' ps
        else return (False, Sealed ps)
  when hadConflicts $ putInfo opts $ text "Skipping some patches which would cause conflicts."
  when (nullFL psFiltered) $ do putInfo opts $ text "No remote patches to pull in!"
                                setEnvDarcsPatches psFiltered
                                when (reorder ? opts /= O.Reorder) exitSuccess
  let direction = if PrimOptSpec DarcsOptDescr DarcsFlag a Bool
PrimDarcsOption Bool
changesReverse PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts then WhichChanges
FirstReversed else WhichChanges
First
      selection_config = WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter (PatchInfoAnd p))
-> Maybe [AnchoredPath]
-> SelectionConfig (PatchInfoAnd p)
forall (p :: * -> * -> *).
Matchable p =>
WhichChanges
-> String
-> PatchSelectionOptions
-> Maybe (Splitter p)
-> Maybe [AnchoredPath]
-> SelectionConfig p
selectionConfig WhichChanges
direction String
jobname ([DarcsFlag] -> PatchSelectionOptions
pullPatchSelOpts [DarcsFlag]
opts) Maybe (Splitter (PatchInfoAnd p))
forall a. Maybe a
Nothing Maybe [AnchoredPath]
forall a. Maybe a
Nothing
  (to_be_pulled :> _) <- runSelection psFiltered selection_config
  return (Sealed (Fork common us' to_be_pulled))

fetchPatches AbsolutePath
_ [DarcsFlag]
_ [] String
jobname Repository 'RW p wU wR
_ = String
-> IO
     (Sealed
        (Fork
           (PatchSet p)
           (FL (PatchInfoAnd p))
           (FL (PatchInfoAnd p))
           Origin
           wR))
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
 -> IO
      (Sealed
         (Fork
            (PatchSet p)
            (FL (PatchInfoAnd p))
            (FL (PatchInfoAnd p))
            Origin
            wR)))
-> String
-> IO
     (Sealed
        (Fork
           (PatchSet p)
           (FL (PatchInfoAnd p))
           (FL (PatchInfoAnd p))
           Origin
           wR))
forall a b. (a -> b) -> a -> b
$
  String
"No default repository to " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
jobname String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" from, please specify one"

makeBundle :: forall p wR . (RepoPatch p, ApplyState p ~ Tree)
           => [DarcsFlag]
           -> (Sealed (Fork (PatchSet p)
                      (FL (PatchInfoAnd p))
                      (FL (PatchInfoAnd p)) Origin wR))
           -> IO ()
makeBundle :: forall (p :: * -> * -> *) wR.
(RepoPatch p, ApplyState p ~ Tree) =>
[DarcsFlag]
-> Sealed
     (Fork
        (PatchSet p) (FL (PatchInfoAnd p)) (FL (PatchInfoAnd p)) Origin wR)
-> IO ()
makeBundle [DarcsFlag]
opts (Sealed (Fork PatchSet p Origin wU
common FL (PatchInfoAnd p) wU wR
_ FL (PatchInfoAnd p) wU wX
to_be_fetched)) =
    do
      bundle <- Maybe (ApplyState p IO)
-> PatchSet p Origin wU -> FL (Named p) wU wX -> IO Doc
forall (p :: * -> * -> *) wStart wX wY.
(RepoPatch p, ApplyMonadTrans (ApplyState p) IO,
 ObjectId (ObjectIdOfPatch p)) =>
Maybe (ApplyState p IO)
-> PatchSet p wStart wX -> FL (Named p) wX wY -> IO Doc
Bundle.makeBundle Maybe (Tree IO)
Maybe (ApplyState p IO)
forall a. Maybe a
Nothing PatchSet p Origin wU
common (FL (Named p) wU wX -> IO Doc) -> FL (Named p) wU wX -> IO Doc
forall a b. (a -> b) -> a -> b
$
                 (forall wW wY. PatchInfoAnd p wW wY -> Named p wW wY)
-> FL (PatchInfoAnd p) wU wX -> FL (Named p) wU wX
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL PatchInfoAndG (Named p) wW wY -> Named p wW wY
forall wW wY. PatchInfoAnd p wW wY -> Named p wW wY
forall (p :: * -> * -> *) wA wB. PatchInfoAndG p wA wB -> p wA wB
hopefully FL (PatchInfoAnd p) wU wX
to_be_fetched
      let fname = case FL (PatchInfoAnd p) wU wX
to_be_fetched of
                    (PatchInfoAnd p wU wY
x:>:FL (PatchInfoAnd p) wY wX
_)-> String -> IO String
getUniqueDPatchName (String -> IO String) -> String -> IO String
forall a b. (a -> b) -> a -> b
$ PatchInfoAnd p wU wY -> String
forall (p :: * -> * -> *) wX wY. PatchInfoAnd p wX wY -> String
patchDesc PatchInfoAnd p wU wY
x
                    FL (PatchInfoAnd p) wU wX
_ -> String -> IO String
forall a. Partial => String -> a
error String
"impossible case"
      o <- fromMaybe (return stdOut) (getOutput opts fname)
      useAbsoluteOrStd writeDocBinFile putDoc o bundle

{- Read in the specified pull-from repositories.  Perform
Intersection, Union, or Complement read.  In patch-theory terms
(stated in set algebra, where + is union and & is intersection
and \ is complement):

    Union =         ((R1 + R2 + ... + Rn) \ Rc)
    Intersection =  ((R1 & R2 & ... & Rn) \ Rc)
    Complement =    (R1 \ Rc) \ ((R2 + R3 + ... + Rn) \ Rc)

                        where Rc = local repo
                              R1 = 1st specified pull repo
                              R2, R3, Rn = other specified pull repo

Since Rc is not provided here yet, the result of readRepos is a
tuple: the first patchset(s) to be complemented against Rc and then
the second patchset(s) to be complemented against Rc.
-}

readRepos :: RepoPatch p
          => Repository rt p wU wR -> [DarcsFlag] -> [String]
          -> IO (SealedPatchSet p Origin,SealedPatchSet p Origin)
readRepos :: forall (p :: * -> * -> *) (rt :: AccessType) wU wR.
RepoPatch p =>
Repository rt p wU wR
-> [DarcsFlag]
-> [String]
-> IO (SealedPatchSet p Origin, SealedPatchSet p Origin)
readRepos Repository rt p wU wR
_ [DarcsFlag]
_ [] = String -> IO (SealedPatchSet p Origin, SealedPatchSet p Origin)
forall a. Partial => String -> a
error String
"impossible case"
readRepos Repository rt p wU wR
to_repo [DarcsFlag]
opts [String]
us =
    do rs <- (String -> IO (SealedPatchSet p Origin))
-> [String] -> IO [SealedPatchSet p Origin]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\String
u -> do r <- ReadingOrWriting
-> Repository rt p wU wR
-> UseCache
-> String
-> IO (Repository 'RO p (ZonkAny 0) (ZonkAny 1))
forall (rt :: AccessType) (p :: * -> * -> *) wU wR vR vU.
ReadingOrWriting
-> Repository rt p wU wR
-> UseCache
-> String
-> IO (Repository 'RO p vR vU)
identifyRepositoryFor ReadingOrWriting
Reading Repository rt p wU wR
to_repo (PrimOptSpec DarcsOptDescr DarcsFlag a UseCache
PrimDarcsOption UseCache
useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) String
u
                            ps <- readPatches r
                            return $ seal ps) [String]
us
       return $ case parseFlags O.repoCombinator opts of
                  RepoCombinator
O.Intersection -> ([SealedPatchSet p Origin] -> SealedPatchSet p Origin
forall (p :: * -> * -> *).
Commute p =>
[SealedPatchSet p Origin] -> SealedPatchSet p Origin
patchSetIntersection [SealedPatchSet p Origin]
rs, PatchSet p Origin Origin -> SealedPatchSet p Origin
forall (a :: * -> *) wX. a wX -> Sealed a
seal PatchSet p Origin Origin
forall (p :: * -> * -> *). PatchSet p Origin Origin
emptyPatchSet)
                  RepoCombinator
O.Complement -> ([SealedPatchSet p Origin] -> SealedPatchSet p Origin
forall a. Partial => [a] -> a
headErr [SealedPatchSet p Origin]
rs, [SealedPatchSet p Origin] -> SealedPatchSet p Origin
forall (p :: * -> * -> *).
(Commute p, Merge p) =>
[SealedPatchSet p Origin] -> SealedPatchSet p Origin
patchSetUnion ([SealedPatchSet p Origin] -> SealedPatchSet p Origin)
-> [SealedPatchSet p Origin] -> SealedPatchSet p Origin
forall a b. (a -> b) -> a -> b
$ [SealedPatchSet p Origin] -> [SealedPatchSet p Origin]
forall a. Partial => [a] -> [a]
tailErr [SealedPatchSet p Origin]
rs)
                  RepoCombinator
O.Union -> ([SealedPatchSet p Origin] -> SealedPatchSet p Origin
forall (p :: * -> * -> *).
(Commute p, Merge p) =>
[SealedPatchSet p Origin] -> SealedPatchSet p Origin
patchSetUnion [SealedPatchSet p Origin]
rs, PatchSet p Origin Origin -> SealedPatchSet p Origin
forall (a :: * -> *) wX. a wX -> Sealed a
seal PatchSet p Origin Origin
forall (p :: * -> * -> *). PatchSet p Origin Origin
emptyPatchSet)

pullPatchSelOpts :: [DarcsFlag] -> S.PatchSelectionOptions
pullPatchSelOpts :: [DarcsFlag] -> PatchSelectionOptions
pullPatchSelOpts [DarcsFlag]
flags = S.PatchSelectionOptions
    { verbosity :: Verbosity
S.verbosity = PrimOptSpec DarcsOptDescr DarcsFlag a Verbosity
PrimDarcsOption Verbosity
verbosity PrimDarcsOption Verbosity -> [DarcsFlag] -> Verbosity
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
flags
    , matchFlags :: [MatchFlag]
S.matchFlags = MatchOption -> [DarcsFlag] -> [MatchFlag]
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
parseFlags PrimOptSpec DarcsOptDescr DarcsFlag a [MatchFlag]
MatchOption
O.matchSeveral [DarcsFlag]
flags
    , interactive :: Bool
S.interactive = Bool -> [DarcsFlag] -> Bool
isInteractive Bool
True [DarcsFlag]
flags
    , selectDeps :: SelectDeps
S.selectDeps = PrimOptSpec DarcsOptDescr DarcsFlag a SelectDeps
PrimDarcsOption SelectDeps
selectDeps PrimDarcsOption SelectDeps -> [DarcsFlag] -> SelectDeps
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
flags
    , withSummary :: WithSummary
S.withSummary = PrimOptSpec DarcsOptDescr DarcsFlag a WithSummary
PrimDarcsOption WithSummary
O.withSummary PrimDarcsOption WithSummary -> [DarcsFlag] -> WithSummary
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
flags
    }