--  Copyright (C) 2003-2004 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 PatternGuards #-}

module Darcs.UI.Commands.Log
    ( changes, log
    , changelog, getLogInfo
    ) where

import Prelude ()
import Darcs.Prelude

import Data.List ( intersect, sort, nub, find )
import Data.Maybe ( fromMaybe, fromJust, isJust )
import Control.Arrow ( second )
import Control.Exception ( catch, IOException )
import Control.Monad.State.Strict

import Darcs.UI.PrintPatch ( showFriendly )
import Darcs.Patch.PatchInfoAnd ( fmapFLPIAP, hopefullyM, info )
import Darcs.UI.Commands ( DarcsCommand(..), withStdOpts, nodefaults, commandAlias, findRepository )
import Darcs.UI.Completion ( knownFileArgs )
import Darcs.UI.External ( viewDocWith )
import Darcs.UI.Flags
    ( DarcsFlag
    , changesReverse, onlyToFiles
    , useCache, maxCount, hasXmlOutput
    , verbosity, withContext, isInteractive, verbose
    , fixSubPaths, getRepourl )
import Darcs.UI.Options ( (^), odesc, ocheck, onormalise, defaultFlags, parseFlags, (?) )
import qualified Darcs.UI.Options.All as O
import Darcs.Util.Path ( SubPath(), toFilePath,
                    fp2fn, fn2fp, normPath, AbsolutePath, simpleSubPath )
import Darcs.Repository ( PatchSet, PatchInfoAnd,
                          withRepositoryLocation, RepoJob(..),
                          readRepo, unrecordedChanges,
                          withRepoLockCanFail )
import Darcs.Repository.Flags ( UseIndex(..), ScanKnown(..), DiffAlgorithm(MyersDiff) )
import Darcs.Util.Lock ( withTempDir )
import Darcs.Patch.Set ( PatchSet(..), patchSet2RL )
import Darcs.Patch.Conflict ( Conflict, CommuteNoConflicts )
import Darcs.Patch.Format ( PatchListFormat )
import Darcs.Patch.FileHunk ( IsHunk )
import Darcs.Patch.Info ( toXml, toXmlShort, showPatchInfo, displayPatchInfo, escapeXML, PatchInfo )
import Darcs.Patch.Depends ( findCommonWithThem )
import Darcs.Patch.Bundle( contextPatches )
import Darcs.Patch.Prim ( PrimPatchBase )
import Darcs.Patch.Show ( ShowPatch, ShowPatchFor(..) )
import Darcs.Patch.TouchesFiles ( lookTouch )
import Darcs.Patch.Type ( PatchType(PatchType) )
import Darcs.Patch.Apply ( Apply, ApplyState )
import Darcs.Patch ( IsRepoType, invert, xmlSummary, description,
                     effectOnFilePaths, listTouchedFiles, showPatch )
import Darcs.Patch.Named.Wrapped ( (:~:)(..), getdeps )
import Darcs.Patch.Witnesses.Eq ( EqCheck(..) )
import Darcs.Patch.Witnesses.Ordered
    ( FL(NilFL), RL(..), filterOutFLFL, filterRL,
    reverseFL, (:>)(..), mapRL )
import Darcs.Patch.Witnesses.Sealed ( Sealed2(..), unseal2, Sealed(..), seal2 )
import Darcs.Patch.Witnesses.Unsafe ( unsafeCoerceP )
import Darcs.Patch.Match
    ( MatchFlag
    , firstMatch
    , secondMatch
    , matchAPatch
    , haveNonrangeMatch
    , matchFirstPatchset
    , matchSecondPatchset
    )
import Darcs.Patch.Matchable ( Matchable )
import Darcs.Util.Printer ( Doc, simplePrinters, (<+>), prefix, text, vcat,
                 vsep, ($$), errorDoc, insertBeforeLastline, empty )
import Darcs.Util.Printer.Color ( fancyPrinters )
import Darcs.Util.Progress ( setProgressMode, debugMessage )
import Darcs.Util.URL ( isValidLocalPath )
import Darcs.UI.SelectChanges ( viewChanges )
import qualified Darcs.UI.SelectChanges as S ( PatchSelectionOptions (..) )
import Darcs.Repository.PatchIndex ( PatchFilter, maybeFilterPatches, attemptCreatePatchIndex )
import Darcs.Util.Tree( Tree )

logHelp :: String
logHelp :: String
logHelp = [String] -> String
unlines
 [ "The `darcs log` command lists patches of the current repository or,"
 , "with `--repo`, a remote repository.  Without options or arguments,"
 , "ALL patches will be listed."
 , ""]
 String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
logHelp'
 String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
logHelp''

log :: DarcsCommand [DarcsFlag]
log :: DarcsCommand [DarcsFlag]
log = DarcsCommand :: forall parsedFlags.
String
-> String
-> String
-> String
-> Int
-> [String]
-> ((AbsolutePath, AbsolutePath)
    -> parsedFlags -> [String] -> IO ())
-> ([DarcsFlag] -> IO (Either String ()))
-> ((AbsolutePath, AbsolutePath)
    -> [DarcsFlag] -> [String] -> IO [String])
-> ([DarcsFlag] -> AbsolutePath -> [String] -> IO [String])
-> [DarcsOptDescr DarcsFlag]
-> [DarcsOptDescr DarcsFlag]
-> [DarcsFlag]
-> ([DarcsFlag] -> [String])
-> ([DarcsFlag] -> parsedFlags)
-> DarcsCommand parsedFlags
DarcsCommand
    { commandProgramName :: String
commandProgramName = "darcs"
    , commandName :: String
commandName = "log"
    , commandHelp :: String
commandHelp = String
logHelp
    , commandDescription :: String
commandDescription = "List patches in the repository."
    , commandExtraArgs :: Int
commandExtraArgs = -1
    , commandExtraArgHelp :: [String]
commandExtraArgHelp = ["[FILE or DIRECTORY]..."]
    , commandCompleteArgs :: (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
commandCompleteArgs = (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
knownFileArgs
    , commandCommand :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
commandCommand = (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
logCmd
    , commandPrereq :: [DarcsFlag] -> IO (Either String ())
commandPrereq = [DarcsFlag] -> IO (Either String ())
findRepository
    , commandArgdefaults :: [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
commandArgdefaults = [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
nodefaults
    , commandAdvancedOptions :: [DarcsOptDescr DarcsFlag]
commandAdvancedOptions = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (NetworkOptions -> WithPatchIndex -> Any)
-> [DarcsOptDescr DarcsFlag]
forall (d :: * -> *) f a b. OptSpec d f a b -> [d f]
odesc OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  (NetworkOptions -> WithPatchIndex -> Any)
forall a.
OptSpec
  DarcsOptDescr DarcsFlag a (NetworkOptions -> WithPatchIndex -> a)
logAdvancedOpts
    , commandBasicOptions :: [DarcsOptDescr DarcsFlag]
commandBasicOptions = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Any)
-> [DarcsOptDescr DarcsFlag]
forall (d :: * -> *) f a b. OptSpec d f a b -> [d f]
odesc OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Any)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
logBasicOpts
    , commandDefaults :: [DarcsFlag]
commandDefaults = OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> [DarcsFlag])
-> [DarcsFlag]
forall (d :: * -> *) f b. OptSpec d f [f] b -> [f]
defaultFlags OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> [DarcsFlag])
forall a.
DarcsOption
  a
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> a)
logOpts
    , commandCheckOptions :: [DarcsFlag] -> [String]
commandCheckOptions = OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> Any)
-> [DarcsFlag] -> [String]
forall (d :: * -> *) f a b. OptSpec d f a b -> [f] -> [String]
ocheck OptSpec
  DarcsOptDescr
  DarcsFlag
  Any
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> Any)
forall a.
DarcsOption
  a
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> a)
logOpts
    , commandParseOptions :: [DarcsFlag] -> [DarcsFlag]
commandParseOptions = OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> [DarcsFlag])
-> [DarcsFlag] -> [DarcsFlag]
forall (d :: * -> *) f b. OptSpec d f [f] b -> [f] -> [f]
onormalise OptSpec
  DarcsOptDescr
  DarcsFlag
  [DarcsFlag]
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> [DarcsFlag])
forall a.
DarcsOption
  a
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> a)
logOpts
    }
  where
    logBasicOpts :: OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
logBasicOpts
      = PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
  [MatchFlag]
MatchOption
O.matchSeveralOrRange
      PrimOptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
  [MatchFlag]
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
     (Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
  (Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
PrimDarcsOption (Maybe Int)
O.maxCount
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
     (Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> 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 ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
  (Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
PrimDarcsOption Bool
O.onlyToFiles
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Summary
      -> Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
     (Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Summary
      -> Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> 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
  (Summary
   -> Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
  (Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
PrimDarcsOption (Maybe ChangesFormat)
O.changesFormat
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Summary
   -> Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
     (Summary
      -> Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> a)
forall (d :: * -> *) f b c a.
OptSpec d f b c -> OptSpec d f a b -> OptSpec d f a c
^ OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
  (Summary
   -> Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
PrimDarcsOption Summary
O.summary
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> Maybe String -> Maybe Bool -> a)
     (Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> Maybe String -> Maybe Bool -> a)
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> 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 String -> Maybe Bool -> a)
  (Bool -> Maybe String -> Maybe String -> Maybe Bool -> a)
PrimDarcsOption Bool
O.changesReverse
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String -> Maybe String -> Maybe Bool -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> Maybe Bool -> a)
     (Maybe String -> Maybe String -> Maybe Bool -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe String -> Maybe Bool -> a)
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> 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 Bool -> a)
  (Maybe String -> Maybe String -> Maybe Bool -> a)
PrimDarcsOption (Maybe String)
O.possiblyRemoteRepo
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe String -> Maybe Bool -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool -> a)
     (Maybe String -> Maybe Bool -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     (Maybe Bool -> a)
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> 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 -> a)
  (Maybe String -> Maybe Bool -> a)
PrimDarcsOption (Maybe String)
O.repoDir
      OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe Bool -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (Maybe Bool -> a)
-> OptSpec
     DarcsOptDescr
     DarcsFlag
     a
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> 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 (Maybe Bool -> a)
PrimDarcsOption (Maybe Bool)
O.interactive
    logAdvancedOpts :: OptSpec
  DarcsOptDescr DarcsFlag a (NetworkOptions -> WithPatchIndex -> a)
logAdvancedOpts = PrimOptSpec
  DarcsOptDescr DarcsFlag (WithPatchIndex -> a) NetworkOptions
PrimDarcsOption NetworkOptions
O.network PrimOptSpec
  DarcsOptDescr DarcsFlag (WithPatchIndex -> a) NetworkOptions
-> OptSpec DarcsOptDescr DarcsFlag a (WithPatchIndex -> a)
-> OptSpec
     DarcsOptDescr DarcsFlag a (NetworkOptions -> WithPatchIndex -> 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 (WithPatchIndex -> a)
PrimDarcsOption WithPatchIndex
O.patchIndexYes
    logOpts :: DarcsOption
  a
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> a)
logOpts = OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> a)
forall a.
OptSpec
  DarcsOptDescr
  DarcsFlag
  a
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> a)
logBasicOpts OptSpec
  DarcsOptDescr
  DarcsFlag
  (Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> a)
  ([MatchFlag]
   -> Maybe Int
   -> Bool
   -> Maybe ChangesFormat
   -> Summary
   -> Bool
   -> Maybe String
   -> Maybe String
   -> Maybe Bool
   -> Maybe StdCmdAction
   -> Bool
   -> Bool
   -> Verbosity
   -> Bool
   -> NetworkOptions
   -> WithPatchIndex
   -> UseCache
   -> HooksConfig
   -> a)
-> DarcsOption
     (UseCache -> HooksConfig -> a)
     (NetworkOptions -> WithPatchIndex -> UseCache -> HooksConfig -> a)
-> DarcsOption
     a
     ([MatchFlag]
      -> Maybe Int
      -> Bool
      -> Maybe ChangesFormat
      -> Summary
      -> Bool
      -> Maybe String
      -> Maybe String
      -> Maybe Bool
      -> Maybe StdCmdAction
      -> Bool
      -> Bool
      -> Verbosity
      -> Bool
      -> NetworkOptions
      -> WithPatchIndex
      -> UseCache
      -> HooksConfig
      -> a)
forall b c a.
DarcsOption
  (Maybe StdCmdAction -> Bool -> Bool -> Verbosity -> Bool -> b) c
-> DarcsOption (UseCache -> HooksConfig -> a) b -> DarcsOption a c
`withStdOpts` DarcsOption
  (UseCache -> HooksConfig -> a)
  (NetworkOptions -> WithPatchIndex -> UseCache -> HooksConfig -> a)
forall a.
OptSpec
  DarcsOptDescr DarcsFlag a (NetworkOptions -> WithPatchIndex -> a)
logAdvancedOpts

logCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
logCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
logCmd fps :: (AbsolutePath, AbsolutePath)
fps opts :: [DarcsFlag]
opts args :: [String]
args
  | PrimDarcsOption (Maybe ChangesFormat)
O.changesFormat PrimDarcsOption (Maybe ChangesFormat)
-> [DarcsFlag] -> Maybe ChangesFormat
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts Maybe ChangesFormat -> Maybe ChangesFormat -> Bool
forall a. Eq a => a -> a -> Bool
== ChangesFormat -> Maybe ChangesFormat
forall a. a -> Maybe a
Just ChangesFormat
O.GenContext = if Bool -> Bool
not (Bool -> Bool) -> ([String] -> Bool) -> [String] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([String] -> Bool) -> [String] -> Bool
forall a b. (a -> b) -> a -> b
$ [String]
args
      then String -> IO ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail "log --context cannot accept other arguments"
      else [DarcsFlag] -> IO ()
logContext [DarcsFlag]
opts
  | [DarcsFlag] -> Bool
hasRemoteRepo [DarcsFlag]
opts = do
      (fs :: [SubPath]
fs, es :: [String]
es) <- [String] -> [String] -> IO ([SubPath], [String])
remoteSubPaths [String]
args []
      if [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
es then
        String -> (AbsolutePath -> IO ()) -> IO ()
forall a. String -> (AbsolutePath -> IO a) -> IO a
withTempDir "darcs.log" (\_ -> [DarcsFlag] -> Maybe [SubPath] -> IO ()
showLog [DarcsFlag]
opts (Maybe [SubPath] -> IO ()) -> Maybe [SubPath] -> IO ()
forall a b. (a -> b) -> a -> b
$ [SubPath] -> Maybe [SubPath]
forall a. [a] -> Maybe [a]
maybeNotNull ([SubPath] -> Maybe [SubPath]) -> [SubPath] -> Maybe [SubPath]
forall a b. (a -> b) -> a -> b
$ [SubPath] -> [SubPath]
forall a. Eq a => [a] -> [a]
nub ([SubPath] -> [SubPath]) -> [SubPath] -> [SubPath]
forall a b. (a -> b) -> a -> b
$ [SubPath] -> [SubPath]
forall a. Ord a => [a] -> [a]
sort [SubPath]
fs)
      else
        String -> IO ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ "For a remote repo I can only handle relative paths.\n"
            String -> String -> String
forall a. [a] -> [a] -> [a]
++ "Invalid arguments: "String -> String -> String
forall a. [a] -> [a] -> [a]
++[String] -> String
unwords [String]
es
  | [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
args = [DarcsFlag] -> Maybe [SubPath] -> IO ()
showLog [DarcsFlag]
opts Maybe [SubPath]
forall a. Maybe a
Nothing
  | Bool
otherwise = do
      [SubPath]
fs <- (AbsolutePath, AbsolutePath) -> [String] -> IO [SubPath]
fixSubPaths (AbsolutePath, AbsolutePath)
fps [String]
args
      case [SubPath]
fs of
        [] -> String -> IO ()
putStrLn "No valid arguments were given, nothing to do."
        _ -> do Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool -> [DarcsFlag] -> Bool
isInteractive Bool
False [DarcsFlag]
opts)
                 (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PrimDarcsOption WithPatchIndex
O.patchIndexNo PrimDarcsOption WithPatchIndex -> [DarcsFlag] -> WithPatchIndex
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts WithPatchIndex -> WithPatchIndex -> Bool
forall a. Eq a => a -> a -> Bool
== WithPatchIndex
O.YesPatchIndex)
                  (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ UseCache -> RepoJob () -> IO ()
withRepoLockCanFail (PrimDarcsOption UseCache
useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts)
                    (RepoJob () -> IO ()) -> RepoJob () -> IO ()
forall a b. (a -> b) -> a -> b
$ (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
 (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
 Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a.
(forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
 (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
 Repository rt p wR wU wR -> IO a)
-> RepoJob a
RepoJob (\repo :: Repository rt p wR wU wR
repo -> Repository rt p wR wU wR -> IO (PatchSet rt p Origin wR)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p) =>
Repository rt p wR wU wT -> IO (PatchSet rt p Origin wR)
readRepo Repository rt p wR wU wR
repo IO (PatchSet rt p Origin wR)
-> (PatchSet rt p Origin wR -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Repository rt p wR wU wR -> PatchSet rt p Origin wR -> IO ()
forall (p :: * -> * -> *) (rt :: RepoType) wR wU wT.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wT -> PatchSet rt p Origin wR -> IO ()
attemptCreatePatchIndex Repository rt p wR wU wR
repo)
                [DarcsFlag] -> Maybe [SubPath] -> IO ()
showLog [DarcsFlag]
opts (Maybe [SubPath] -> IO ()) -> Maybe [SubPath] -> IO ()
forall a b. (a -> b) -> a -> b
$ [SubPath] -> Maybe [SubPath]
forall a. a -> Maybe a
Just ([SubPath] -> Maybe [SubPath]) -> [SubPath] -> Maybe [SubPath]
forall a b. (a -> b) -> a -> b
$ [SubPath] -> [SubPath]
forall a. Eq a => [a] -> [a]
nub ([SubPath] -> [SubPath]) -> [SubPath] -> [SubPath]
forall a b. (a -> b) -> a -> b
$ [SubPath] -> [SubPath]
forall a. Ord a => [a] -> [a]
sort [SubPath]
fs

maybeNotNull :: [a] -> Maybe [a]
maybeNotNull :: [a] -> Maybe [a]
maybeNotNull [] = Maybe [a]
forall a. Maybe a
Nothing
maybeNotNull xs :: [a]
xs = [a] -> Maybe [a]
forall a. a -> Maybe a
Just [a]
xs

hasRemoteRepo :: [DarcsFlag] -> Bool
hasRemoteRepo :: [DarcsFlag] -> Bool
hasRemoteRepo = Bool -> (String -> Bool) -> Maybe String -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Bool -> Bool
not (Bool -> Bool) -> (String -> Bool) -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Bool
isValidLocalPath) (Maybe String -> Bool)
-> ([DarcsFlag] -> Maybe String) -> [DarcsFlag] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimDarcsOption (Maybe String) -> [DarcsFlag] -> Maybe String
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
parseFlags PrimDarcsOption (Maybe String)
O.possiblyRemoteRepo

remoteSubPaths :: [String] -> [String] -> IO ([SubPath],[String])
remoteSubPaths :: [String] -> [String] -> IO ([SubPath], [String])
remoteSubPaths [] es :: [String]
es = ([SubPath], [String]) -> IO ([SubPath], [String])
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [String]
es)
remoteSubPaths (arg :: String
arg:args :: [String]
args) es :: [String]
es = case String -> Maybe SubPath
simpleSubPath String
arg of
  Nothing -> [String] -> [String] -> IO ([SubPath], [String])
remoteSubPaths [String]
args (String
argString -> [String] -> [String]
forall a. a -> [a] -> [a]
:[String]
es)
  Just sp :: SubPath
sp -> do
    (sps :: [SubPath]
sps, es' :: [String]
es') <- [String] -> [String] -> IO ([SubPath], [String])
remoteSubPaths [String]
args [String]
es
    ([SubPath], [String]) -> IO ([SubPath], [String])
forall (m :: * -> *) a. Monad m => a -> m a
return (SubPath
spSubPath -> [SubPath] -> [SubPath]
forall a. a -> [a] -> [a]
:[SubPath]
sps, [String]
es')

showLog :: [DarcsFlag] -> Maybe [SubPath] -> IO ()
showLog :: [DarcsFlag] -> Maybe [SubPath] -> IO ()
showLog opts :: [DarcsFlag]
opts files :: Maybe [SubPath]
files =
  let repodir :: String
repodir = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe "." ([DarcsFlag] -> Maybe String
getRepourl [DarcsFlag]
opts) in
  UseCache -> String -> RepoJob () -> IO ()
forall a. UseCache -> String -> RepoJob a -> IO a
withRepositoryLocation (PrimDarcsOption UseCache
useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) String
repodir (RepoJob () -> IO ()) -> RepoJob () -> IO ()
forall a b. (a -> b) -> a -> b
$ (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
 (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
 Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a.
(forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
 (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
 Repository rt p wR wU wR -> IO a)
-> RepoJob a
RepoJob ((forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
  (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
  Repository rt p wR wU wR -> IO ())
 -> RepoJob ())
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
    Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a b. (a -> b) -> a -> b
$ \repository :: Repository rt p wR wU wR
repository -> do
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (PrimDarcsOption Bool
O.debug PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO ()
setProgressMode Bool
False
  Sealed unrec :: FL (PrimOf p) wR wX
unrec <- case Maybe [SubPath]
files of
    Nothing -> Sealed (FL (PrimOf p) wR) -> IO (Sealed (FL (PrimOf p) wR))
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed (FL (PrimOf p) wR) -> IO (Sealed (FL (PrimOf p) wR)))
-> Sealed (FL (PrimOf p) wR) -> IO (Sealed (FL (PrimOf p) wR))
forall a b. (a -> b) -> a -> b
$ FL (PrimOf p) wR wR -> Sealed (FL (PrimOf p) wR)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed FL (PrimOf p) wR wR
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
    Just _ -> FL (PrimOf p) wR wU -> Sealed (FL (PrimOf p) wR)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (FL (PrimOf p) wR wU -> Sealed (FL (PrimOf p) wR))
-> IO (FL (PrimOf p) wR wU) -> IO (Sealed (FL (PrimOf p) wR))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` (UseIndex, ScanKnown, DiffAlgorithm)
-> LookForMoves
-> LookForReplaces
-> Repository rt p wR wU wR
-> Maybe [SubPath]
-> IO (FL (PrimOf p) wR wU)
forall (p :: * -> * -> *) (rt :: RepoType) wR wU wT.
(RepoPatch p, ApplyState p ~ Tree) =>
(UseIndex, ScanKnown, DiffAlgorithm)
-> LookForMoves
-> LookForReplaces
-> Repository rt p wR wU wT
-> Maybe [SubPath]
-> IO (FL (PrimOf p) wT wU)
unrecordedChanges (UseIndex
UseIndex, ScanKnown
ScanKnown, DiffAlgorithm
MyersDiff)
                  LookForMoves
O.NoLookForMoves LookForReplaces
O.NoLookForReplaces
                  Repository rt p wR wU wR
repository Maybe [SubPath]
files
                  IO (Sealed (FL (PrimOf p) wR))
-> (IOException -> IO (Sealed (FL (PrimOf p) wR)))
-> IO (Sealed (FL (PrimOf p) wR))
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`catch` \(IOException
_ :: IOException) -> Sealed (FL (PrimOf p) wR) -> IO (Sealed (FL (PrimOf p) wR))
forall (m :: * -> *) a. Monad m => a -> m a
return (FL (PrimOf p) wR wR -> Sealed (FL (PrimOf p) wR)
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed FL (PrimOf p) wR wR
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL) -- this is triggered when repository is remote
  String -> IO ()
debugMessage "About to read the repository..."
  PatchSet rt p Origin wR
patches <- Repository rt p wR wU wR -> IO (PatchSet rt p Origin wR)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p) =>
Repository rt p wR wU wT -> IO (PatchSet rt p Origin wR)
readRepo Repository rt p wR wU wR
repository
  String -> IO ()
debugMessage "Done reading the repository."
  let normfp :: String -> String
normfp = FileName -> String
fn2fp (FileName -> String) -> (String -> FileName) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileName -> FileName
normPath (FileName -> FileName)
-> (String -> FileName) -> String -> FileName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> FileName
fp2fn
      undoUnrecordedOnFPs :: [String] -> [String]
undoUnrecordedOnFPs = FL (PrimOf p) wX wR -> [String] -> [String]
forall (p :: * -> * -> *) wX wY.
(Apply p, ApplyState p ~ Tree) =>
p wX wY -> [String] -> [String]
effectOnFilePaths (FL (PrimOf p) wR wX -> FL (PrimOf p) wX wR
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert FL (PrimOf p) wR wX
unrec)
      recFiles :: Maybe [String]
recFiles = (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
normfp ([String] -> [String])
-> ([SubPath] -> [String]) -> [SubPath] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> [String]
undoUnrecordedOnFPs ([String] -> [String])
-> ([SubPath] -> [String]) -> [SubPath] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SubPath -> String) -> [SubPath] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map SubPath -> String
forall a. FilePathLike a => a -> String
toFilePath ([SubPath] -> [String]) -> Maybe [SubPath] -> Maybe [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [SubPath]
files
      filtered_changes :: PatchSet rt p wX wY
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
filtered_changes p :: PatchSet rt p wX wY
p =
          ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall a b c. ([a], b, c) -> ([a], b, c)
maybe_reverse (([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
  Maybe Doc)
 -> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
     Maybe Doc))
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          Maybe Int
-> [MatchFlag]
-> Bool
-> Maybe [String]
-> PatchFilter rt p
-> PatchSet rt p wX wY
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall (rt :: RepoType) (p :: * -> * -> *) wX wY.
(IsRepoType rt, Matchable p, ApplyState p ~ Tree) =>
Maybe Int
-> [MatchFlag]
-> Bool
-> Maybe [String]
-> PatchFilter rt p
-> PatchSet rt p wX wY
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
getLogInfo
              (PrimDarcsOption (Maybe Int)
maxCount PrimDarcsOption (Maybe Int) -> [DarcsFlag] -> Maybe Int
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts)
              (MatchOption -> [DarcsFlag] -> [MatchFlag]
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
parseFlags MatchOption
O.matchSeveralOrRange [DarcsFlag]
opts)
              (PrimDarcsOption Bool
onlyToFiles PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts)
              Maybe [String]
recFiles
              (Repository rt p wR wU wR
-> PatchSet rt p Origin wR -> PatchFilter rt p
forall (p :: * -> * -> *) (rt :: RepoType) wR wU wT.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wR wU wT
-> PatchSet rt p Origin wR -> PatchFilter rt p
maybeFilterPatches Repository rt p wR wU wR
repository PatchSet rt p Origin wR
patches)
              PatchSet rt p wX wY
p
  if Bool -> [DarcsFlag] -> Bool
isInteractive Bool
False [DarcsFlag]
opts
    then do (fp_and_fs :: [(Sealed2 (PatchInfoAnd rt p), [String])]
fp_and_fs, _, _) <- PatchSet rt p Origin wR
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall wX wY.
PatchSet rt p wX wY
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
filtered_changes PatchSet rt p Origin wR
patches
            let fp :: [Sealed2 (PatchInfoAnd rt p)]
fp = ((Sealed2 (PatchInfoAnd rt p), [String])
 -> Sealed2 (PatchInfoAnd rt p))
-> [(Sealed2 (PatchInfoAnd rt p), [String])]
-> [Sealed2 (PatchInfoAnd rt p)]
forall a b. (a -> b) -> [a] -> [b]
map (Sealed2 (PatchInfoAnd rt p), [String])
-> Sealed2 (PatchInfoAnd rt p)
forall a b. (a, b) -> a
fst [(Sealed2 (PatchInfoAnd rt p), [String])]
fp_and_fs
            PatchSelectionOptions -> [Sealed2 (PatchInfoAnd rt p)] -> IO ()
forall (p :: * -> * -> *).
(ShowPatch p, ShowContextPatch p, ApplyState p ~ Tree) =>
PatchSelectionOptions -> [Sealed2 p] -> IO ()
viewChanges ([DarcsFlag] -> PatchSelectionOptions
logPatchSelOpts [DarcsFlag]
opts) [Sealed2 (PatchInfoAnd rt p)]
fp
    else do let header :: Doc
header = if Maybe [SubPath] -> Bool
forall a. Maybe a -> Bool
isJust Maybe [SubPath]
files Bool -> Bool -> Bool
&& [DarcsFlag] -> Bool
hasXmlOutput [DarcsFlag]
opts
                          then String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ "Changes to "String -> String -> String
forall a. [a] -> [a] -> [a]
++[String] -> String
unwords (Maybe [String] -> [String]
forall a. HasCallStack => Maybe a -> a
fromJust Maybe [String]
recFiles)String -> String -> String
forall a. [a] -> [a] -> [a]
++":\n"
                          else Doc
empty
            String -> IO ()
debugMessage "About to print the patches..."
            let printers :: Printers
printers = if [DarcsFlag] -> Bool
hasXmlOutput [DarcsFlag]
opts then Printers
simplePrinters else Printers
fancyPrinters
            PatchSet rt p Origin wR
ps <- Repository rt p wR wU wR -> IO (PatchSet rt p Origin wR)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p) =>
Repository rt p wR wU wT -> IO (PatchSet rt p Origin wR)
readRepo Repository rt p wR wU wR
repository -- read repo again to prevent holding onto
                                       -- values forced by filtered_changes
            Doc
logOutput <- [DarcsFlag]
-> PatchSet rt p Origin wR
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> Doc
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
(Apply p, ApplyState p ~ Tree, ShowPatch p, IsHunk p,
 PrimPatchBase p, PatchListFormat p, Conflict p,
 CommuteNoConflicts p) =>
[DarcsFlag]
-> PatchSet rt p wStart wX
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> Doc
changelog [DarcsFlag]
opts PatchSet rt p Origin wR
ps (([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
  Maybe Doc)
 -> Doc)
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
-> IO Doc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` PatchSet rt p Origin wR
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall wX wY.
PatchSet rt p wX wY
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
filtered_changes PatchSet rt p Origin wR
patches
            Printers -> Doc -> IO ()
viewDocWith Printers
printers (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ Doc
header Doc -> Doc -> Doc
$$ Doc
logOutput
  where maybe_reverse :: ([a], b, c) -> ([a], b, c)
maybe_reverse (xs :: [a]
xs,b :: b
b,c :: c
c) = if PrimDarcsOption Bool
changesReverse PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts
                                 then ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
xs, b
b, c
c)
                                 else ([a]
xs, b
b, c
c)

logHelp' :: String
logHelp' :: String
logHelp' = [String] -> String
unlines
 [ "When given files or directories paths as arguments, only patches which"
 , "affect those paths are listed.  This includes patches that happened to"
 , "files before they were moved or renamed."
 , ""
 , "When given `--from-tag` or `--from-patch`, only patches since that tag"
 , "or patch are listed.  Similarly, the `--to-tag` and `--to-patch`"
 , "options restrict the list to older patches."
 , ""
 , "The `--last` and `--max-count` options both limit the number of patches"
 , "listed.  The former applies BEFORE other filters, whereas the latter"
 , "applies AFTER other filters.  For example `darcs log foo.c"
 , "--max-count 3` will print the last three patches that affect foo.c,"
 , "whereas `darcs log --last 3 foo.c` will, of the last three"
 , "patches, print only those that affect foo.c."
 , ""
 ]

getLogInfo :: forall rt p wX wY
                . (IsRepoType rt, Matchable p, ApplyState p ~ Tree)
               => Maybe Int -> [MatchFlag] -> Bool
               -> Maybe [FilePath]
               -> PatchFilter rt p
               -> PatchSet rt p wX wY
               -> IO ( [(Sealed2 (PatchInfoAnd rt p), [FilePath])]
                     , [(FilePath, FilePath)]
                     , Maybe Doc )
getLogInfo :: Maybe Int
-> [MatchFlag]
-> Bool
-> Maybe [String]
-> PatchFilter rt p
-> PatchSet rt p wX wY
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
getLogInfo maxCountFlag :: Maybe Int
maxCountFlag matchFlags :: [MatchFlag]
matchFlags onlyToFilesFlag :: Bool
onlyToFilesFlag plain_fs :: Maybe [String]
plain_fs patchFilter :: PatchFilter rt p
patchFilter ps :: PatchSet rt p wX wY
ps =
    case (SealedPatchSet rt p wX
sp1s, SealedPatchSet rt p wX
sp2s) of
      (Sealed p1s :: PatchSet rt p wX wX
p1s, Sealed p2s :: PatchSet rt p wX wX
p2s) ->
          case PatchSet rt p wX wX
-> PatchSet rt p wX wX
-> (:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) wX wX
forall (p :: * -> * -> *) (rt :: RepoType) wStart wX wY.
Commute p =>
PatchSet rt p wStart wX
-> PatchSet rt p wStart wY
-> (:>) (PatchSet rt p) (FL (PatchInfoAnd rt p)) wStart wX
findCommonWithThem PatchSet rt p wX wX
p2s PatchSet rt p wX wX
p1s of
            _ :> us :: FL (PatchInfoAnd rt p) wZ wX
us ->
              let ps' :: [Sealed2 (PatchInfoAnd rt p)]
ps' = (forall wX wY. PatchInfoAnd rt p wX wY -> Bool)
-> RL (PatchInfoAnd rt p) wZ wX -> [Sealed2 (PatchInfoAnd rt p)]
forall (p :: * -> * -> *) wA wB.
(forall wX wY. p wX wY -> Bool) -> RL p wA wB -> [Sealed2 p]
filterRL forall wX wY. PatchInfoAnd rt p wX wY -> Bool
pf (FL (PatchInfoAnd rt p) wZ wX -> RL (PatchInfoAnd rt p) wZ wX
forall (a :: * -> * -> *) wX wZ. FL a wX wZ -> RL a wX wZ
reverseFL FL (PatchInfoAnd rt p) wZ wX
us) in
                case Maybe [String]
plain_fs of
                  Nothing -> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall (m :: * -> *) a. Monad m => a -> m a
return (([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
  Maybe Doc)
 -> IO
      ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
       Maybe Doc))
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall a b. (a -> b) -> a -> b
$ (Sealed2 (PatchInfoAnd rt p)
 -> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
     Maybe Doc)
 -> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
     Maybe Doc))
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> [Sealed2 (PatchInfoAnd rt p)]
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\x :: Sealed2 (PatchInfoAnd rt p)
x xs :: ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
xs -> (Sealed2 (PatchInfoAnd rt p)
x, []) (Sealed2 (PatchInfoAnd rt p), [String])
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall a b c. a -> ([a], b, c) -> ([a], b, c)
-:- ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
xs) ([], [], Maybe Doc
forall a. Maybe a
Nothing) ([Sealed2 (PatchInfoAnd rt p)]
 -> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
     Maybe Doc))
-> [Sealed2 (PatchInfoAnd rt p)]
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall a b. (a -> b) -> a -> b
$
                    ([Sealed2 (PatchInfoAnd rt p)] -> [Sealed2 (PatchInfoAnd rt p)])
-> (Int
    -> [Sealed2 (PatchInfoAnd rt p)] -> [Sealed2 (PatchInfoAnd rt p)])
-> Maybe Int
-> [Sealed2 (PatchInfoAnd rt p)]
-> [Sealed2 (PatchInfoAnd rt p)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Sealed2 (PatchInfoAnd rt p)] -> [Sealed2 (PatchInfoAnd rt p)]
forall a. a -> a
id Int
-> [Sealed2 (PatchInfoAnd rt p)] -> [Sealed2 (PatchInfoAnd rt p)]
forall a. Int -> [a] -> [a]
take Maybe Int
maxCountFlag [Sealed2 (PatchInfoAnd rt p)]
ps'
                  Just fs :: [String]
fs -> let fs' :: [String]
fs' = (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\x :: String
x -> "./" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x) [String]
fs in do
                    ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall (q :: * -> * -> *) (rt :: RepoType) b c.
PatchInspect q =>
([(Sealed2 (PatchInfoAnd rt q), [String])], b, c)
-> ([(Sealed2 (PatchInfoAnd rt q), [String])], b, c)
filterOutUnrelatedChanges (([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
  Maybe Doc)
 -> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
     Maybe Doc))
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
                       [Sealed2 (PatchInfoAnd rt p)]
ps'' <- PatchFilter rt p
patchFilter [String]
fs' [Sealed2 (PatchInfoAnd rt p)]
ps'
                       ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall (m :: * -> *) a. Monad m => a -> m a
return (([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
  Maybe Doc)
 -> IO
      ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
       Maybe Doc))
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> IO
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall a b. (a -> b) -> a -> b
$ Maybe Int
-> [String]
-> [Sealed2 (PatchInfoAnd rt p)]
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall (rt :: RepoType) (p :: * -> * -> *).
(Matchable p, ApplyState p ~ Tree) =>
Maybe Int
-> [String]
-> [Sealed2 (PatchInfoAnd rt p)]
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
filterPatchesByNames Maybe Int
maxCountFlag [String]
fs' [Sealed2 (PatchInfoAnd rt p)]
ps''
  where
        sp1s :: SealedPatchSet rt p wX
sp1s = if [MatchFlag] -> Bool
firstMatch [MatchFlag]
matchFlags
               then [MatchFlag] -> PatchSet rt p wX wY -> SealedPatchSet rt p wX
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
(IsRepoType rt, Matchable p) =>
[MatchFlag]
-> PatchSet rt p wStart wX -> SealedPatchSet rt p wStart
matchFirstPatchset [MatchFlag]
matchFlags PatchSet rt p wX wY
ps
               else PatchSet rt p wX wX -> SealedPatchSet rt p wX
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed (PatchSet rt p wX wX -> SealedPatchSet rt p wX)
-> PatchSet rt p wX wX -> SealedPatchSet rt p wX
forall a b. (a -> b) -> a -> b
$ RL (Tagged rt p) wX wX
-> RL (PatchInfoAnd rt p) wX wX -> PatchSet rt p wX wX
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX wY.
RL (Tagged rt p) wStart wX
-> RL (PatchInfoAnd rt p) wX wY -> PatchSet rt p wStart wY
PatchSet RL (Tagged rt p) wX wX
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL RL (PatchInfoAnd rt p) wX wX
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL
        sp2s :: SealedPatchSet rt p wX
sp2s = if [MatchFlag] -> Bool
secondMatch [MatchFlag]
matchFlags
               then [MatchFlag] -> PatchSet rt p wX wY -> SealedPatchSet rt p wX
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
(IsRepoType rt, Matchable p) =>
[MatchFlag]
-> PatchSet rt p wStart wX -> SealedPatchSet rt p wStart
matchSecondPatchset [MatchFlag]
matchFlags PatchSet rt p wX wY
ps
               else PatchSet rt p wX wY -> SealedPatchSet rt p wX
forall (a :: * -> *) wX. a wX -> Sealed a
Sealed PatchSet rt p wX wY
ps
        pf :: PatchInfoAnd rt p wX wY -> Bool
pf = if PatchType rt p -> [MatchFlag] -> Bool
forall (rt :: RepoType) (p :: * -> * -> *).
(IsRepoType rt, Matchable p) =>
PatchType rt p -> [MatchFlag] -> Bool
haveNonrangeMatch (PatchType rt p
forall (rt :: RepoType) (p :: * -> * -> *). PatchType rt p
PatchType :: PatchType rt p) [MatchFlag]
matchFlags
             then [MatchFlag] -> PatchInfoAnd rt p wX wY -> Bool
forall (rt :: RepoType) (p :: * -> * -> *) wX wY.
(IsRepoType rt, Matchable p) =>
[MatchFlag] -> PatchInfoAnd rt p wX wY -> Bool
matchAPatch [MatchFlag]
matchFlags
             else \_ -> Bool
True

        filterOutUnrelatedChanges :: ([(Sealed2 (PatchInfoAnd rt q), [String])], b, c)
-> ([(Sealed2 (PatchInfoAnd rt q), [String])], b, c)
filterOutUnrelatedChanges (pfs :: [(Sealed2 (PatchInfoAnd rt q), [String])]
pfs, renames :: b
renames, doc :: c
doc)
          | Bool
onlyToFilesFlag = (((Sealed2 (PatchInfoAnd rt q), [String])
 -> (Sealed2 (PatchInfoAnd rt q), [String]))
-> [(Sealed2 (PatchInfoAnd rt q), [String])]
-> [(Sealed2 (PatchInfoAnd rt q), [String])]
forall a b. (a -> b) -> [a] -> [b]
map (Sealed2 (PatchInfoAnd rt q), [String])
-> (Sealed2 (PatchInfoAnd rt q), [String])
forall (q :: * -> * -> *) (rt :: RepoType).
PatchInspect q =>
(Sealed2 (PatchInfoAnd rt q), [String])
-> (Sealed2 (PatchInfoAnd rt q), [String])
onlyRelated [(Sealed2 (PatchInfoAnd rt q), [String])]
pfs, b
renames, c
doc)
          | Bool
otherwise       = ([(Sealed2 (PatchInfoAnd rt q), [String])]
pfs, b
renames, c
doc)

        onlyRelated :: (Sealed2 (PatchInfoAnd rt q), [String])
-> (Sealed2 (PatchInfoAnd rt q), [String])
onlyRelated (Sealed2 p :: PatchInfoAnd rt q wX wY
p, fs :: [String]
fs) =
          (PatchInfoAnd rt q wX wY -> Sealed2 (PatchInfoAnd rt q)
forall (a :: * -> * -> *) wX wY. a wX wY -> Sealed2 a
Sealed2 (PatchInfoAnd rt q wX wY -> Sealed2 (PatchInfoAnd rt q))
-> PatchInfoAnd rt q wX wY -> Sealed2 (PatchInfoAnd rt q)
forall a b. (a -> b) -> a -> b
$ (FL q wX wY -> FL q wX wY)
-> ((RebaseTypeOf rt :~~: 'IsRebase) -> q :~: q)
-> PatchInfoAnd rt q wX wY
-> PatchInfoAnd rt q wX wY
forall (p :: * -> * -> *) wX wY (q :: * -> * -> *)
       (rt :: RepoType).
(FL p wX wY -> FL q wX wY)
-> ((RebaseTypeOf rt :~~: 'IsRebase) -> p :~: q)
-> PatchInfoAnd rt p wX wY
-> PatchInfoAnd rt q wX wY
fmapFLPIAP ((forall wX wY. q wX wY -> EqCheck wX wY)
-> FL q wX wY -> FL q wX wY
forall (p :: * -> * -> *) wW wZ.
(forall wX wY. p wX wY -> EqCheck wX wY)
-> FL p wW wZ -> FL p wW wZ
filterOutFLFL ([String] -> q wX wY -> EqCheck wX wY
forall (p :: * -> * -> *) wX wY wB wC.
PatchInspect p =>
[String] -> p wX wY -> EqCheck wB wC
unrelated [String]
fs)) (\_ -> q :~: q
forall (a :: * -> * -> *). a :~: a
ReflPatch) PatchInfoAnd rt q wX wY
p, [String]
fs)

        unrelated :: [String] -> p wX wY -> EqCheck wB wC
unrelated fs :: [String]
fs p :: p wX wY
p
          -- If the change does not affect the patches we are looking at,
          -- we ignore the difference between the two states.
          | [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([String] -> Bool) -> [String] -> Bool
forall a b. (a -> b) -> a -> b
$ [String]
fs [String] -> [String] -> [String]
forall a. Eq a => [a] -> [a] -> [a]
`intersect` p wX wY -> [String]
forall (p :: * -> * -> *) wX wY.
PatchInspect p =>
p wX wY -> [String]
listTouchedFiles p wX wY
p = EqCheck Any Any -> EqCheck wB wC
forall (a :: * -> * -> *) wX wY wB wC. a wX wY -> a wB wC
unsafeCoerceP EqCheck Any Any
forall wA. EqCheck wA wA
IsEq
          | Bool
otherwise                                = EqCheck wB wC
forall wA wB. EqCheck wA wB
NotEq

-- | Take a list of filenames and patches and produce a list of patches that
-- actually touch the given files with a list of touched file names, a list of
-- original-to-current filepath mappings, indicating the original names of the
-- affected files and possibly an error. Additionaly, the function takes a
-- "depth limit" -- maxcount, that could be Nothing (return everything) or
-- "Just n" -- returns at most n patches touching the file (starting from the
-- beginning of the patch list).
filterPatchesByNames
    :: forall rt p
     . (Matchable p, ApplyState p ~ Tree)
    => Maybe Int -- ^ maxcount
    -> [FilePath] -- ^ filenames
    -> [Sealed2 (PatchInfoAnd rt p)] -- ^ patchlist
    -> ([(Sealed2 (PatchInfoAnd rt p),[FilePath])], [(FilePath, FilePath)], Maybe Doc)
filterPatchesByNames :: Maybe Int
-> [String]
-> [Sealed2 (PatchInfoAnd rt p)]
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
filterPatchesByNames maxcount :: Maybe Int
maxcount fns :: [String]
fns patches :: [Sealed2 (PatchInfoAnd rt p)]
patches = ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall a c.
(a, [(String, String)], c) -> (a, [(String, String)], c)
removeNonRenames (([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
  Maybe Doc)
 -> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
     Maybe Doc))
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall a b. (a -> b) -> a -> b
$
    State
  (Maybe Int, [(String, String)])
  ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
   Maybe Doc)
-> (Maybe Int, [(String, String)])
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall s a. State s a -> s -> a
evalState ([String]
-> [Sealed2 (PatchInfoAnd rt p)]
-> State
     (Maybe Int, [(String, String)])
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall a (p :: * -> * -> *) (rt :: RepoType).
(MonadState
   (Maybe a, [(String, String)])
   (StateT (Maybe Int, [(String, String)]) Identity),
 MonadState
   (Maybe a, [(String, String)])
   (StateT (Maybe Int, [(String, String)]) Identity),
 Apply p, Invert p, ApplyState p ~ Tree, Ord a, Num a) =>
[String]
-> [Sealed2 (PatchInfoAnd rt p)]
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
filterPatchesByNames' [String]
fns [Sealed2 (PatchInfoAnd rt p)]
patches) (Maybe Int
maxcount, [(String, String)]
initRenames) where
        removeNonRenames :: (a, [(String, String)], c) -> (a, [(String, String)], c)
removeNonRenames (ps :: a
ps, renames :: [(String, String)]
renames, doc :: c
doc) = (a
ps, [(String, String)] -> [(String, String)]
removeIds [(String, String)]
renames, c
doc)
        removeIds :: [(String, String)] -> [(String, String)]
removeIds = ((String, String) -> Bool)
-> [(String, String)] -> [(String, String)]
forall a. (a -> Bool) -> [a] -> [a]
filter (((String, String) -> Bool)
 -> [(String, String)] -> [(String, String)])
-> ((String, String) -> Bool)
-> [(String, String)]
-> [(String, String)]
forall a b. (a -> b) -> a -> b
$ (String -> String -> Bool) -> (String, String) -> Bool
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry String -> String -> Bool
forall a. Eq a => a -> a -> Bool
(/=)
        initRenames :: [(String, String)]
initRenames = (String -> (String, String)) -> [String] -> [(String, String)]
forall a b. (a -> b) -> [a] -> [b]
map (\x :: String
x -> (String
x, String
x)) [String]
fns
        returnFinal :: StateT
  (Maybe Int, [(String, String)])
  Identity
  ([a], [(String, String)], Maybe a)
returnFinal = (\renames :: [(String, String)]
renames -> ([], [(String, String)]
renames, Maybe a
forall a. Maybe a
Nothing)) ([(String, String)] -> ([a], [(String, String)], Maybe a))
-> StateT
     (Maybe Int, [(String, String)]) Identity [(String, String)]
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([a], [(String, String)], Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Maybe Int, [(String, String)]) -> [(String, String)])
-> StateT
     (Maybe Int, [(String, String)]) Identity [(String, String)]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Maybe Int, [(String, String)]) -> [(String, String)]
forall a b. (a, b) -> b
snd
        filterPatchesByNames' :: [String]
-> [Sealed2 (PatchInfoAnd rt p)]
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
filterPatchesByNames' [] _ = StateT
  (Maybe Int, [(String, String)])
  Identity
  ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
   Maybe Doc)
forall a a.
StateT
  (Maybe Int, [(String, String)])
  Identity
  ([a], [(String, String)], Maybe a)
returnFinal
        filterPatchesByNames' _ [] = StateT
  (Maybe Int, [(String, String)])
  Identity
  ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
   Maybe Doc)
forall a a.
StateT
  (Maybe Int, [(String, String)])
  Identity
  ([a], [(String, String)], Maybe a)
returnFinal
        filterPatchesByNames' fs :: [String]
fs (s2hp :: Sealed2 (PatchInfoAnd rt p)
s2hp@(Sealed2 hp :: PatchInfoAnd rt p wX wY
hp) : ps :: [Sealed2 (PatchInfoAnd rt p)]
ps) = do
            (count :: Maybe a
count, renames :: [(String, String)]
renames) <- StateT
  (Maybe Int, [(String, String)])
  Identity
  (Maybe a, [(String, String)])
forall s (m :: * -> *). MonadState s m => m s
get
            let stopNow :: Bool
stopNow = case Maybe a
count of
                                Nothing -> Bool
False
                                Just c -> a
c a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= 0
            if Bool
stopNow
                then StateT
  (Maybe Int, [(String, String)])
  Identity
  ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
   Maybe Doc)
forall a a.
StateT
  (Maybe Int, [(String, String)])
  Identity
  ([a], [(String, String)], Maybe a)
returnFinal
                else case PatchInfoAnd rt p wX wY -> Maybe (WrappedNamed rt p wX wY)
forall (m :: * -> *) (rt :: RepoType) (p :: * -> * -> *) wA wB.
MonadFail m =>
PatchInfoAnd rt p wA wB -> m (WrappedNamed rt p wA wB)
hopefullyM PatchInfoAnd rt p wX wY
hp of
                    Nothing -> do
                        let err :: Doc
err = String -> Doc
text "Can't find patches prior to:"
                                  Doc -> Doc -> Doc
$$ PatchInfo -> Doc
displayPatchInfo (PatchInfoAnd rt p wX wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wX wY
hp)
                        ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [(String, String)]
renames, Doc -> Maybe Doc
forall a. a -> Maybe a
Just Doc
err)
                    Just p :: WrappedNamed rt p wX wY
p ->
                        case Maybe [(String, String)]
-> [String]
-> WrappedNamed rt p wY wX
-> (Bool, [String], [String], [(String, String)])
forall (p :: * -> * -> *) wX wY.
(Apply p, ApplyState p ~ Tree) =>
Maybe [(String, String)]
-> [String]
-> p wX wY
-> (Bool, [String], [String], [(String, String)])
lookTouch ([(String, String)] -> Maybe [(String, String)]
forall a. a -> Maybe a
Just [(String, String)]
renames) [String]
fs (WrappedNamed rt p wX wY -> WrappedNamed rt p wY wX
forall (p :: * -> * -> *) wX wY. Invert p => p wX wY -> p wY wX
invert WrappedNamed rt p wX wY
p) of
                            (True, affected :: [String]
affected, [], renames' :: [(String, String)]
renames') ->
                                ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Sealed2 (PatchInfoAnd rt p)
s2hp, [String]
affected)], [(String, String)]
renames', Maybe Doc
forall a. Maybe a
Nothing)
                            (True, affected :: [String]
affected, fs' :: [String]
fs', renames' :: [(String, String)]
renames') -> do
                                let sub1Mb :: f b -> f b
sub1Mb c :: f b
c = b -> b -> b
forall a. Num a => a -> a -> a
subtract 1 (b -> b) -> f b -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
c
                                ((Maybe a, [(String, String)]) -> (Maybe a, [(String, String)]))
-> StateT (Maybe Int, [(String, String)]) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (((Maybe a, [(String, String)]) -> (Maybe a, [(String, String)]))
 -> StateT (Maybe Int, [(String, String)]) Identity ())
-> ((Maybe a, [(String, String)]) -> (Maybe a, [(String, String)]))
-> StateT (Maybe Int, [(String, String)]) Identity ()
forall a b. (a -> b) -> a -> b
$ \(c :: Maybe a
c, _) -> (Maybe a -> Maybe a
forall (f :: * -> *) b. (Functor f, Num b) => f b -> f b
sub1Mb Maybe a
c, [(String, String)]
renames')
                                ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
rest <- [String]
-> [Sealed2 (PatchInfoAnd rt p)]
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
filterPatchesByNames' [String]
fs' [Sealed2 (PatchInfoAnd rt p)]
ps
                                ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall (m :: * -> *) a. Monad m => a -> m a
return (([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
  Maybe Doc)
 -> StateT
      (Maybe Int, [(String, String)])
      Identity
      ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
       Maybe Doc))
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
forall a b. (a -> b) -> a -> b
$ (Sealed2 (PatchInfoAnd rt p)
s2hp, [String]
affected) (Sealed2 (PatchInfoAnd rt p), [String])
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
forall a b c. a -> ([a], b, c) -> ([a], b, c)
-:- ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
 Maybe Doc)
rest
                            (False, _, fs' :: [String]
fs', renames' :: [(String, String)]
renames') -> do
                                ((Maybe a, [(String, String)]) -> (Maybe a, [(String, String)]))
-> StateT (Maybe Int, [(String, String)]) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (((Maybe a, [(String, String)]) -> (Maybe a, [(String, String)]))
 -> StateT (Maybe Int, [(String, String)]) Identity ())
-> ((Maybe a, [(String, String)]) -> (Maybe a, [(String, String)]))
-> StateT (Maybe Int, [(String, String)]) Identity ()
forall a b. (a -> b) -> a -> b
$ ([(String, String)] -> [(String, String)])
-> (Maybe a, [(String, String)]) -> (Maybe a, [(String, String)])
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ([(String, String)] -> [(String, String)] -> [(String, String)]
forall a b. a -> b -> a
const [(String, String)]
renames')
                                [String]
-> [Sealed2 (PatchInfoAnd rt p)]
-> StateT
     (Maybe Int, [(String, String)])
     Identity
     ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
      Maybe Doc)
filterPatchesByNames' [String]
fs' [Sealed2 (PatchInfoAnd rt p)]
ps

-- | Note, lazy pattern matching is required to make functions like
-- filterPatchesByNames lazy in case you are only not interested in
-- the first element. E.g.:
--
--   let (fs, _, _) = filterPatchesByNames ...
(-:-) :: a -> ([a],b,c) -> ([a],b,c)
x :: a
x -:- :: a -> ([a], b, c) -> ([a], b, c)
-:- ~(xs :: [a]
xs,y :: b
y,z :: c
z) = (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
xs,b
y,c
z)

changelog :: forall rt p wStart wX
           . ( Apply p, ApplyState p ~ Tree, ShowPatch p, IsHunk p
             , PrimPatchBase p, PatchListFormat p
             , Conflict p, CommuteNoConflicts p
             )
          => [DarcsFlag] -> PatchSet rt p wStart wX
          -> ([(Sealed2 (PatchInfoAnd rt p), [FilePath])], [(FilePath, FilePath)], Maybe Doc)
          -> Doc
changelog :: [DarcsFlag]
-> PatchSet rt p wStart wX
-> ([(Sealed2 (PatchInfoAnd rt p), [String])], [(String, String)],
    Maybe Doc)
-> Doc
changelog opts :: [DarcsFlag]
opts patchset :: PatchSet rt p wStart wX
patchset (pis_and_fs :: [(Sealed2 (PatchInfoAnd rt p), [String])]
pis_and_fs, createdAsFs :: [(String, String)]
createdAsFs, mbErr :: Maybe Doc
mbErr)
    | PrimDarcsOption (Maybe ChangesFormat)
O.changesFormat PrimDarcsOption (Maybe ChangesFormat)
-> [DarcsFlag] -> Maybe ChangesFormat
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts Maybe ChangesFormat -> Maybe ChangesFormat -> Bool
forall a. Eq a => a -> a -> Bool
== ChangesFormat -> Maybe ChangesFormat
forall a. a -> Maybe a
Just ChangesFormat
O.CountPatches = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Int -> String
forall a. Show a => a -> String
show (Int -> String) -> Int -> String
forall a b. (a -> b) -> a -> b
$ [(Sealed2 (PatchInfoAnd rt p), [String])] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Sealed2 (PatchInfoAnd rt p), [String])]
pis_and_fs
    | [DarcsFlag] -> Bool
hasXmlOutput [DarcsFlag]
opts =
         String -> Doc
text "<changelog>"
      Doc -> Doc -> Doc
$$ [Doc] -> Doc
vcat [Doc]
created_as_xml
      Doc -> Doc -> Doc
$$ [Doc] -> Doc
vcat [Doc]
actual_xml_changes
      Doc -> Doc -> Doc
$$ String -> Doc
text "</changelog>"
    | Summary -> Bool
forall a. YesNo a => a -> Bool
O.yes (PrimDarcsOption Summary
O.summary PrimDarcsOption Summary -> [DarcsFlag] -> Summary
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) Bool -> Bool -> Bool
|| [DarcsFlag] -> Bool
verbose [DarcsFlag]
opts =
        Doc -> Doc
mbAppendErr (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vsep ((Sealed2 (PatchInfoAnd rt p) -> Doc)
-> [Sealed2 (PatchInfoAnd rt p)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((Sealed2 (PatchInfoAnd rt p) -> Doc)
-> Sealed2 (PatchInfoAnd rt p) -> Doc
forall (re :: RepoType).
(Sealed2 (PatchInfoAnd re p) -> Doc)
-> Sealed2 (PatchInfoAnd re p) -> Doc
number_patch Sealed2 (PatchInfoAnd rt p) -> Doc
change_with_summary) [Sealed2 (PatchInfoAnd rt p)]
pis)
    | Bool
otherwise = Doc -> Doc
mbAppendErr (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vsep ((Sealed2 (PatchInfoAnd rt p) -> Doc)
-> [Sealed2 (PatchInfoAnd rt p)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((Sealed2 (PatchInfoAnd rt p) -> Doc)
-> Sealed2 (PatchInfoAnd rt p) -> Doc
forall (re :: RepoType).
(Sealed2 (PatchInfoAnd re p) -> Doc)
-> Sealed2 (PatchInfoAnd re p) -> Doc
number_patch Sealed2 (PatchInfoAnd rt p) -> Doc
description') [Sealed2 (PatchInfoAnd rt p)]
pis)
    where mbAppendErr :: Doc -> Doc
mbAppendErr = (Doc -> Doc) -> (Doc -> Doc -> Doc) -> Maybe Doc -> Doc -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc -> Doc
forall a. a -> a
id (\err :: Doc
err -> (Doc -> Doc -> Doc
$$ Doc
err)) Maybe Doc
mbErr
          change_with_summary :: Sealed2 (PatchInfoAnd rt p) -> Doc
          change_with_summary :: Sealed2 (PatchInfoAnd rt p) -> Doc
change_with_summary (Sealed2 hp :: PatchInfoAnd rt p wX wY
hp)
            | Just p :: WrappedNamed rt p wX wY
p <- PatchInfoAnd rt p wX wY -> Maybe (WrappedNamed rt p wX wY)
forall (m :: * -> *) (rt :: RepoType) (p :: * -> * -> *) wA wB.
MonadFail m =>
PatchInfoAnd rt p wA wB -> m (WrappedNamed rt p wA wB)
hopefullyM PatchInfoAnd rt p wX wY
hp =
              if PrimDarcsOption (Maybe ChangesFormat)
O.changesFormat PrimDarcsOption (Maybe ChangesFormat)
-> [DarcsFlag] -> Maybe ChangesFormat
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts Maybe ChangesFormat -> Maybe ChangesFormat -> Bool
forall a. Eq a => a -> a -> Bool
== ChangesFormat -> Maybe ChangesFormat
forall a. a -> Maybe a
Just ChangesFormat
O.MachineReadable
                then ShowPatchFor -> WrappedNamed rt p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatchBasic p =>
ShowPatchFor -> p wX wY -> Doc
showPatch ShowPatchFor
ForStorage WrappedNamed rt p wX wY
p
                else Verbosity -> Summary -> WrappedNamed rt p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
ShowPatch p =>
Verbosity -> Summary -> p wX wY -> Doc
showFriendly (PrimDarcsOption Verbosity
verbosity PrimDarcsOption Verbosity -> [DarcsFlag] -> Verbosity
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) (PrimDarcsOption Summary
O.summary PrimDarcsOption Summary -> [DarcsFlag] -> Summary
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) WrappedNamed rt p wX wY
p
            | Bool
otherwise = PatchInfoAnd rt p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description PatchInfoAnd rt p wX wY
hp Doc -> Doc -> Doc
$$ Doc -> Doc
indent (String -> Doc
text "[this patch is unavailable]")

          xml_with_summary :: Sealed2 (PatchInfoAnd rt p) -> Doc
xml_with_summary (Sealed2 hp :: PatchInfoAnd rt p wX wY
hp) | Just p :: WrappedNamed rt p wX wY
p <- PatchInfoAnd rt p wX wY -> Maybe (WrappedNamed rt p wX wY)
forall (m :: * -> *) (rt :: RepoType) (p :: * -> * -> *) wA wB.
MonadFail m =>
PatchInfoAnd rt p wA wB -> m (WrappedNamed rt p wA wB)
hopefullyM PatchInfoAnd rt p wX wY
hp =
                    let
                      deps :: [PatchInfo]
deps = WrappedNamed rt p wX wY -> [PatchInfo]
forall (rt :: RepoType) (p :: * -> * -> *) wX wY.
WrappedNamed rt p wX wY -> [PatchInfo]
getdeps WrappedNamed rt p wX wY
p
                      xmlDependencies :: Doc
xmlDependencies =
                        String -> Doc
text "<explicit_dependencies>"
                        Doc -> Doc -> Doc
$$ [Doc] -> Doc
vcat ((PatchInfo -> Doc) -> [PatchInfo] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Doc -> Doc
indent (Doc -> Doc) -> (PatchInfo -> Doc) -> PatchInfo -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfo -> Doc
toXmlShort) [PatchInfo]
deps)
                        Doc -> Doc -> Doc
$$ String -> Doc
text "</explicit_dependencies>"
                      summary :: Doc
summary | [PatchInfo]
deps [PatchInfo] -> [PatchInfo] -> Bool
forall a. Eq a => a -> a -> Bool
== [] = Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ WrappedNamed rt p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
(Conflict p, PrimPatchBase p) =>
p wX wY -> Doc
xmlSummary WrappedNamed rt p wX wY
p
                              | Bool
otherwise = Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
xmlDependencies Doc -> Doc -> Doc
$$ WrappedNamed rt p wX wY -> Doc
forall (p :: * -> * -> *) wX wY.
(Conflict p, PrimPatchBase p) =>
p wX wY -> Doc
xmlSummary WrappedNamed rt p wX wY
p
                    in
                      Doc -> Doc -> Doc
insertBeforeLastline (PatchInfo -> Doc
toXml (PatchInfo -> Doc) -> PatchInfo -> Doc
forall a b. (a -> b) -> a -> b
$ PatchInfoAnd rt p wX wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wX wY
hp) Doc
summary
          xml_with_summary (Sealed2 hp :: PatchInfoAnd rt p wX wY
hp) = PatchInfo -> Doc
toXml (PatchInfoAnd rt p wX wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wX wY
hp)
          indent :: Doc -> Doc
indent = String -> Doc -> Doc
prefix "    "
          actual_xml_changes :: [Doc]
actual_xml_changes =
            case PrimDarcsOption Summary
O.summary PrimDarcsOption Summary -> [DarcsFlag] -> Summary
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts of
              O.YesSummary -> (Sealed2 (PatchInfoAnd rt p) -> Doc)
-> [Sealed2 (PatchInfoAnd rt p)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Sealed2 (PatchInfoAnd rt p) -> Doc
forall (p :: * -> * -> *) (rt :: RepoType).
(CommuteNoConflicts p, Conflict p, PrimPatchBase p) =>
Sealed2 (PatchInfoAnd rt p) -> Doc
xml_with_summary [Sealed2 (PatchInfoAnd rt p)]
pis
              O.NoSummary -> (Sealed2 (PatchInfoAnd rt p) -> Doc)
-> [Sealed2 (PatchInfoAnd rt p)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (PatchInfo -> Doc
toXml (PatchInfo -> Doc)
-> (Sealed2 (PatchInfoAnd rt p) -> PatchInfo)
-> Sealed2 (PatchInfoAnd rt p)
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wX wY. PatchInfoAnd rt p wX wY -> PatchInfo)
-> Sealed2 (PatchInfoAnd rt p) -> PatchInfo
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. PatchInfoAnd rt p wX wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info) [Sealed2 (PatchInfoAnd rt p)]
pis

          created_as_xml :: [Doc]
created_as_xml = ((String, String) -> Doc) -> [(String, String)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (String, String) -> Doc
create [(String, String)]
createdAsFs where
            create :: (String, String) -> Doc
create rename :: (String, String)
rename@(_, as :: String
as) = PatchInfo -> (String, String) -> Doc
createdAsXml (String -> PatchInfo
first_change_of String
as) (String, String)
rename
            -- We need to reorder the patches when they haven't been reversed
            -- already, so that we find the *first* patch that modifies a given
            -- file, not the last (by default, the list is oldest->newest).
            reorderer :: [a] -> [a]
reorderer = if Bool -> Bool
not (PrimDarcsOption Bool
changesReverse PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) then [a] -> [a]
forall a. [a] -> [a]
reverse else [a] -> [a]
forall a. a -> a
id
            oldest_first_pis_and_fs :: [(Sealed2 (PatchInfoAnd rt p), [String])]
oldest_first_pis_and_fs = [(Sealed2 (PatchInfoAnd rt p), [String])]
-> [(Sealed2 (PatchInfoAnd rt p), [String])]
forall a. [a] -> [a]
reorderer [(Sealed2 (PatchInfoAnd rt p), [String])]
pis_and_fs
            couldnt_find :: String -> a
couldnt_find fn :: String
fn = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ "Couldn't find first patch affecting " String -> String -> String
forall a. [a] -> [a] -> [a]
++
                                      String
fn String -> String -> String
forall a. [a] -> [a] -> [a]
++ " in pis_and_fs"
            mb_first_change_of :: String -> Maybe (Sealed2 (PatchInfoAnd rt p), [String])
mb_first_change_of fn :: String
fn = ((Sealed2 (PatchInfoAnd rt p), [String]) -> Bool)
-> [(Sealed2 (PatchInfoAnd rt p), [String])]
-> Maybe (Sealed2 (PatchInfoAnd rt p), [String])
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((String
fn String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem`) ([String] -> Bool)
-> ((Sealed2 (PatchInfoAnd rt p), [String]) -> [String])
-> (Sealed2 (PatchInfoAnd rt p), [String])
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sealed2 (PatchInfoAnd rt p), [String]) -> [String]
forall a b. (a, b) -> b
snd) [(Sealed2 (PatchInfoAnd rt p), [String])]
oldest_first_pis_and_fs
            find_first_change_of :: String -> (Sealed2 (PatchInfoAnd rt p), [String])
find_first_change_of fn :: String
fn = (Sealed2 (PatchInfoAnd rt p), [String])
-> Maybe (Sealed2 (PatchInfoAnd rt p), [String])
-> (Sealed2 (PatchInfoAnd rt p), [String])
forall a. a -> Maybe a -> a
fromMaybe (String -> (Sealed2 (PatchInfoAnd rt p), [String])
forall a. String -> a
couldnt_find String
fn)
              (String -> Maybe (Sealed2 (PatchInfoAnd rt p), [String])
mb_first_change_of String
fn)
            first_change_of :: String -> PatchInfo
first_change_of = (forall wX wY. PatchInfoAnd rt p wX wY -> PatchInfo)
-> Sealed2 (PatchInfoAnd rt p) -> PatchInfo
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. PatchInfoAnd rt p wX wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info (Sealed2 (PatchInfoAnd rt p) -> PatchInfo)
-> (String -> Sealed2 (PatchInfoAnd rt p)) -> String -> PatchInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sealed2 (PatchInfoAnd rt p), [String])
-> Sealed2 (PatchInfoAnd rt p)
forall a b. (a, b) -> a
fst ((Sealed2 (PatchInfoAnd rt p), [String])
 -> Sealed2 (PatchInfoAnd rt p))
-> (String -> (Sealed2 (PatchInfoAnd rt p), [String]))
-> String
-> Sealed2 (PatchInfoAnd rt p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> (Sealed2 (PatchInfoAnd rt p), [String])
find_first_change_of
          number_patch :: (Sealed2 (PatchInfoAnd re p) -> Doc)
-> Sealed2 (PatchInfoAnd re p) -> Doc
number_patch f :: Sealed2 (PatchInfoAnd re p) -> Doc
f x :: Sealed2 (PatchInfoAnd re p)
x = if PrimDarcsOption (Maybe ChangesFormat)
O.changesFormat PrimDarcsOption (Maybe ChangesFormat)
-> [DarcsFlag] -> Maybe ChangesFormat
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts Maybe ChangesFormat -> Maybe ChangesFormat -> Bool
forall a. Eq a => a -> a -> Bool
== ChangesFormat -> Maybe ChangesFormat
forall a. a -> Maybe a
Just ChangesFormat
O.NumberPatches
                             then case Sealed2 (PatchInfoAnd re p) -> Maybe Int
forall (re :: RepoType). Sealed2 (PatchInfoAnd re p) -> Maybe Int
get_number Sealed2 (PatchInfoAnd re p)
x of
                                  Just n :: Int
n -> String -> Doc
text (Int -> String
forall a. Show a => a -> String
show Int
nString -> String -> String
forall a. [a] -> [a] -> [a]
++":") Doc -> Doc -> Doc
<+> Sealed2 (PatchInfoAnd re p) -> Doc
f Sealed2 (PatchInfoAnd re p)
x
                                  Nothing -> Sealed2 (PatchInfoAnd re p) -> Doc
f Sealed2 (PatchInfoAnd re p)
x
                             else Sealed2 (PatchInfoAnd re p) -> Doc
f Sealed2 (PatchInfoAnd re p)
x
          get_number :: Sealed2 (PatchInfoAnd re p) -> Maybe Int
          get_number :: Sealed2 (PatchInfoAnd re p) -> Maybe Int
get_number (Sealed2 y :: PatchInfoAnd re p wX wY
y) = Int -> RL (PatchInfoAnd rt p) wStart wX -> Maybe Int
forall wY. Int -> RL (PatchInfoAnd rt p) wStart wY -> Maybe Int
gn 1 (PatchSet rt p wStart wX -> RL (PatchInfoAnd rt p) wStart wX
forall (rt :: RepoType) (p :: * -> * -> *) wStart wX.
PatchSet rt p wStart wX -> RL (PatchInfoAnd rt p) wStart wX
patchSet2RL PatchSet rt p wStart wX
patchset)
              where iy :: PatchInfo
iy = PatchInfoAnd re p wX wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info PatchInfoAnd re p wX wY
y
                    gn :: Int -> RL (PatchInfoAnd rt p) wStart wY -> Maybe Int
                    gn :: Int -> RL (PatchInfoAnd rt p) wStart wY -> Maybe Int
gn n :: Int
n (bs :: RL (PatchInfoAnd rt p) wStart wY
bs:<:b :: PatchInfoAnd rt p wY wY
b) | Int -> PatchInfo -> PatchInfo
forall a b. a -> b -> b
seq Int
n (PatchInfoAnd rt p wY wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info PatchInfoAnd rt p wY wY
b) PatchInfo -> PatchInfo -> Bool
forall a. Eq a => a -> a -> Bool
== PatchInfo
iy = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n
                                  | Bool
otherwise = Int -> RL (PatchInfoAnd rt p) wStart wY -> Maybe Int
forall wY. Int -> RL (PatchInfoAnd rt p) wStart wY -> Maybe Int
gn (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) RL (PatchInfoAnd rt p) wStart wY
bs
                    gn _ NilRL = Maybe Int
forall a. Maybe a
Nothing
          pis :: [Sealed2 (PatchInfoAnd rt p)]
pis = ((Sealed2 (PatchInfoAnd rt p), [String])
 -> Sealed2 (PatchInfoAnd rt p))
-> [(Sealed2 (PatchInfoAnd rt p), [String])]
-> [Sealed2 (PatchInfoAnd rt p)]
forall a b. (a -> b) -> [a] -> [b]
map (Sealed2 (PatchInfoAnd rt p), [String])
-> Sealed2 (PatchInfoAnd rt p)
forall a b. (a, b) -> a
fst [(Sealed2 (PatchInfoAnd rt p), [String])]
pis_and_fs
          description' :: Sealed2 (PatchInfoAnd rt p) -> Doc
description' = (forall wX wY. PatchInfoAnd rt p wX wY -> Doc)
-> Sealed2 (PatchInfoAnd rt p) -> Doc
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 forall wX wY. PatchInfoAnd rt p wX wY -> Doc
forall (p :: * -> * -> *) wX wY. ShowPatch p => p wX wY -> Doc
description

logHelp'' :: String
logHelp'' :: String
logHelp'' = [String] -> String
unlines
 [ "Four output formats exist.  The default is `--human-readable`. The slightly"
 , "different `--machine-readable` format enables to see patch dependencies in"
 , "non-interactive mode. You can also select `--context`, which is an internal"
 , "format that can be re-read by Darcs (e.g. `darcs clone --context`)."
 , ""
 , "Finally, there is `--xml-output`, which emits valid XML... unless a the"
 , "patch metadata (author, name or description) contains a non-ASCII"
 , "character and was recorded in a non-UTF8 locale."
 ]

logContext :: [DarcsFlag] -> IO ()
logContext :: [DarcsFlag] -> IO ()
logContext opts :: [DarcsFlag]
opts = do
  let repodir :: String
repodir = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe "." (Maybe String -> String) -> Maybe String -> String
forall a b. (a -> b) -> a -> b
$ [DarcsFlag] -> Maybe String
getRepourl [DarcsFlag]
opts
  UseCache -> String -> RepoJob () -> IO ()
forall a. UseCache -> String -> RepoJob a -> IO a
withRepositoryLocation (PrimDarcsOption UseCache
useCache PrimDarcsOption UseCache -> [DarcsFlag] -> UseCache
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts) String
repodir (RepoJob () -> IO ()) -> RepoJob () -> IO ()
forall a b. (a -> b) -> a -> b
$ (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
 (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
 Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a.
(forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
 (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
 Repository rt p wR wU wR -> IO a)
-> RepoJob a
RepoJob ((forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
  (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
  Repository rt p wR wU wR -> IO ())
 -> RepoJob ())
-> (forall (rt :: RepoType) (p :: * -> * -> *) wR wU.
    (IsRepoType rt, RepoPatch p, ApplyState p ~ Tree) =>
    Repository rt p wR wU wR -> IO ())
-> RepoJob ()
forall a b. (a -> b) -> a -> b
$ \repository :: Repository rt p wR wU wR
repository -> do
      (_ :> ps' :: RL (PatchInfoAnd rt p) wZ wR
ps') <- PatchSet rt p Origin wR
-> (:>) (PatchSet rt p) (RL (PatchInfoAnd rt p)) Origin wR
forall (rt :: RepoType) (p :: * -> * -> *) wX.
PatchSet rt p Origin wX
-> (:>) (PatchSet rt p) (RL (PatchInfoAnd rt p)) Origin wX
contextPatches (PatchSet rt p Origin wR
 -> (:>) (PatchSet rt p) (RL (PatchInfoAnd rt p)) Origin wR)
-> IO (PatchSet rt p Origin wR)
-> IO ((:>) (PatchSet rt p) (RL (PatchInfoAnd rt p)) Origin wR)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Repository rt p wR wU wR -> IO (PatchSet rt p Origin wR)
forall (rt :: RepoType) (p :: * -> * -> *) wR wU wT.
(IsRepoType rt, RepoPatch p) =>
Repository rt p wR wU wT -> IO (PatchSet rt p Origin wR)
readRepo Repository rt p wR wU wR
repository
      let pis :: [Sealed2 (PatchInfoAnd rt p)]
pis = (forall wW wZ.
 PatchInfoAnd rt p wW wZ -> Sealed2 (PatchInfoAnd rt p))
-> RL (PatchInfoAnd rt p) wZ wR -> [Sealed2 (PatchInfoAnd rt p)]
forall (a :: * -> * -> *) b wX wY.
(forall wW wZ. a wW wZ -> b) -> RL a wX wY -> [b]
mapRL forall wW wZ.
PatchInfoAnd rt p wW wZ -> Sealed2 (PatchInfoAnd rt p)
forall (a :: * -> * -> *) wX wY. a wX wY -> Sealed2 a
seal2 RL (PatchInfoAnd rt p) wZ wR
ps'
      let header :: Doc
header = String -> Doc
text "\nContext:\n"
      let logOutput :: Doc
logOutput = Doc -> (Doc -> Doc) -> Maybe Doc -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Doc] -> Doc
vsep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Sealed2 (PatchInfoAnd rt p) -> Doc)
-> [Sealed2 (PatchInfoAnd rt p)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((forall wX wY. PatchInfoAnd rt p wX wY -> Doc)
-> Sealed2 (PatchInfoAnd rt p) -> Doc
forall (a :: * -> * -> *) b.
(forall wX wY. a wX wY -> b) -> Sealed2 a -> b
unseal2 (ShowPatchFor -> PatchInfo -> Doc
showPatchInfo ShowPatchFor
ForStorage (PatchInfo -> Doc)
-> (PatchInfoAnd rt p wX wY -> PatchInfo)
-> PatchInfoAnd rt p wX wY
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchInfoAnd rt p wX wY -> PatchInfo
forall (rt :: RepoType) (p :: * -> * -> *) wA wB.
PatchInfoAnd rt p wA wB -> PatchInfo
info)) [Sealed2 (PatchInfoAnd rt p)]
pis) Doc -> Doc
forall a. Doc -> a
errorDoc Maybe Doc
forall a. Maybe a
Nothing
      Printers -> Doc -> IO ()
viewDocWith Printers
simplePrinters (Doc -> IO ()) -> Doc -> IO ()
forall a b. (a -> b) -> a -> b
$ Doc
header Doc -> Doc -> Doc
$$ Doc
logOutput

-- | changes is an alias for log
changes :: DarcsCommand [DarcsFlag]
changes :: DarcsCommand [DarcsFlag]
changes = String
-> Maybe (DarcsCommand [DarcsFlag])
-> DarcsCommand [DarcsFlag]
-> DarcsCommand [DarcsFlag]
forall pf.
String
-> Maybe (DarcsCommand pf) -> DarcsCommand pf -> DarcsCommand pf
commandAlias "changes" Maybe (DarcsCommand [DarcsFlag])
forall a. Maybe a
Nothing DarcsCommand [DarcsFlag]
log

createdAsXml :: PatchInfo -> (String, String) -> Doc
createdAsXml :: PatchInfo -> (String, String) -> Doc
createdAsXml pinfo :: PatchInfo
pinfo (current :: String
current, createdAs :: String
createdAs) =
    String -> Doc
text "<created_as current_name='"
       Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
escapeXML String
current
       Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text "' original_name='"
       Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
escapeXML String
createdAs
       Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text "'>"
    Doc -> Doc -> Doc
$$    PatchInfo -> Doc
toXml PatchInfo
pinfo
    Doc -> Doc -> Doc
$$    String -> Doc
text "</created_as>"

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