module Darcs.UI.Commands.Add ( add ) where
import Darcs.Prelude
import Control.Exception ( catch, IOException )
import Control.Monad ( when, unless, void )
import Data.List ( (\\), nub )
import Data.List.Ordered ( nubSort )
import Data.Maybe ( fromMaybe, isNothing, maybeToList )
import Darcs.Util.Printer ( Doc, text, vcat )
import Darcs.Util.Tree
( Tree
, expand
, explodePaths
, findTree
, treeHas
, treeHasAnycase
, treeHasDir
)
import qualified Darcs.Util.Tree as Tree
import Darcs.Util.Path
( AbsolutePath
, AnchoredPath
, displayPath
, filterPaths
, parent
, parents
, realPath
)
import System.Posix.Files ( isRegularFile, isDirectory, isSymbolicLink )
import System.Directory ( getPermissions, readable )
import qualified System.FilePath.Windows as WindowsFilePath
import Darcs.UI.Commands
( DarcsCommand(..), withStdOpts, putInfo, putWarning, putVerboseWarning
, nodefaults, amInHashedRepository)
import Darcs.UI.Commands.Util ( doesDirectoryReallyExist )
import Darcs.UI.Completion ( unknownFileArgs )
import Darcs.UI.Flags
( DarcsFlag, diffingOpts
, allowCaseDifferingFilenames, allowWindowsReservedFilenames, useCache, dryRun, umask
, pathsFromArgs )
import Darcs.UI.Options ( parseFlags, (?), (^) )
import qualified Darcs.UI.Options.All as O
import Darcs.Patch ( PrimPatch, applyToTree, addfile, adddir, listTouchedFiles )
import Darcs.Patch.Apply ( ApplyState )
import Darcs.Repository.State
( TreeFilter(..)
, readPristineAndPending
, readWorking
)
import Darcs.Repository
( withRepoLock
, RepoJob(..)
, addToPending
, finalizeRepositoryChanges
)
import Darcs.Repository.Prefs ( isBoring )
import Darcs.Util.File ( getFileStatus )
import Darcs.Patch.Witnesses.Ordered ( FL(..), concatGapsFL, nullFL )
import Darcs.Patch.Witnesses.Sealed ( Sealed(..), Gap(..), FreeLeft, unFreeLeft )
addDescription :: String
addDescription :: String
addDescription = String
"Add new files to version control."
addHelp :: Doc
addHelp :: Doc
addHelp = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$
String
"Generally the working tree contains both files that should be version\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"controlled (such as source code) and files that Darcs should ignore\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"(such as executables compiled from the source code). The `darcs add`\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"command is used to tell Darcs which files to version control.\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"When an existing project is first imported into a Darcs repository, it\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"is common to run `darcs add -r *` or `darcs record -l` to add all\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"initial source files into darcs.\n"String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"Adding symbolic links (symlinks) is not supported.\n\n"
addHelp' :: Doc
addHelp' :: Doc
addHelp' = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$
String
"Darcs will ignore all files and folders that look \"boring\". The\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"`--boring` option overrides this behaviour.\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"Darcs will not add a file if another file in the same folder has the\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"same name, except for case. The `--case-ok` option overrides this\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"behaviour. Windows and OS X usually use filesystems that do not allow\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"files a folder to have the same name except for case (for example,\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"`ReadMe` and `README`). If `--case-ok` is used, the repository might be\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"unusable on those systems!\n\n"
add :: DarcsCommand
add :: DarcsCommand
add = DarcsCommand
{ commandProgramName :: String
commandProgramName = String
"darcs"
, commandName :: String
commandName = String
"add"
, commandHelp :: Doc
commandHelp = Doc
addHelp Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
addHelp'
, commandDescription :: String
commandDescription = String
addDescription
, commandExtraArgs :: Int
commandExtraArgs = -Int
1
, commandExtraArgHelp :: [String]
commandExtraArgHelp = [ String
"<FILE or DIRECTORY> ..." ]
, commandCommand :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
commandCommand = (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
addCmd
, commandPrereq :: [DarcsFlag] -> IO (Either String ())
commandPrereq = [DarcsFlag] -> IO (Either String ())
amInHashedRepository
, commandCompleteArgs :: (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
commandCompleteArgs = (AbsolutePath, AbsolutePath)
-> [DarcsFlag] -> [String] -> IO [String]
unknownFileArgs
, commandArgdefaults :: [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
commandArgdefaults = [DarcsFlag] -> AbsolutePath -> [String] -> IO [String]
nodefaults
, commandOptions :: CommandOptions
commandOptions = CommandOptions
addOpts
}
where
addBasicOpts :: OptSpec
DarcsOptDescr
DarcsFlag
a
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
addBasicOpts
= PrimOptSpec
DarcsOptDescr
DarcsFlag
(Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
Bool
PrimDarcsOption Bool
O.includeBoring
PrimOptSpec
DarcsOptDescr
DarcsFlag
(Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
Bool
-> OptSpec
DarcsOptDescr
DarcsFlag
(Bool -> Maybe String -> DryRun -> a)
(Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
-> OptSpec
DarcsOptDescr
DarcsFlag
(Bool -> Maybe String -> DryRun -> a)
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> 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 -> DryRun -> a)
(Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
forall a. DarcsOption a (Bool -> Bool -> a)
O.allowProblematicFilenames
OptSpec
DarcsOptDescr
DarcsFlag
(Bool -> Maybe String -> DryRun -> a)
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
-> OptSpec
DarcsOptDescr
DarcsFlag
(Maybe String -> DryRun -> a)
(Bool -> Maybe String -> DryRun -> a)
-> OptSpec
DarcsOptDescr
DarcsFlag
(Maybe String -> DryRun -> a)
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> 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 -> DryRun -> a)
(Bool -> Maybe String -> DryRun -> a)
PrimDarcsOption Bool
O.recursive
OptSpec
DarcsOptDescr
DarcsFlag
(Maybe String -> DryRun -> a)
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
-> OptSpec
DarcsOptDescr DarcsFlag (DryRun -> a) (Maybe String -> DryRun -> a)
-> OptSpec
DarcsOptDescr
DarcsFlag
(DryRun -> a)
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> 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 -> a) (Maybe String -> DryRun -> a)
PrimDarcsOption (Maybe String)
O.repoDir
OptSpec
DarcsOptDescr
DarcsFlag
(DryRun -> a)
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
-> OptSpec DarcsOptDescr DarcsFlag a (DryRun -> a)
-> OptSpec
DarcsOptDescr
DarcsFlag
a
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> 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 (DryRun -> a)
PrimDarcsOption DryRun
O.dryRun
addAdvancedOpts :: PrimOptSpec DarcsOptDescr DarcsFlag a UMask
addAdvancedOpts = PrimOptSpec DarcsOptDescr DarcsFlag a UMask
PrimDarcsOption UMask
O.umask
addOpts :: CommandOptions
addOpts = DarcsOption
(Maybe StdCmdAction
-> Verbosity
-> UMask
-> UseCache
-> UseIndex
-> HooksConfig
-> Bool
-> Bool
-> [DarcsFlag])
(Bool
-> Bool
-> Bool
-> Bool
-> Maybe String
-> DryRun
-> Maybe StdCmdAction
-> Verbosity
-> UMask
-> UseCache
-> UseIndex
-> HooksConfig
-> Bool
-> Bool
-> [DarcsFlag])
-> DarcsOption
(UseCache
-> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
(UMask
-> UseCache
-> UseIndex
-> HooksConfig
-> Bool
-> Bool
-> [DarcsFlag])
-> CommandOptions
forall b c.
DarcsOption (Maybe StdCmdAction -> Verbosity -> b) c
-> DarcsOption
(UseCache
-> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
b
-> CommandOptions
withStdOpts DarcsOption
(Maybe StdCmdAction
-> Verbosity
-> UMask
-> UseCache
-> UseIndex
-> HooksConfig
-> Bool
-> Bool
-> [DarcsFlag])
(Bool
-> Bool
-> Bool
-> Bool
-> Maybe String
-> DryRun
-> Maybe StdCmdAction
-> Verbosity
-> UMask
-> UseCache
-> UseIndex
-> HooksConfig
-> Bool
-> Bool
-> [DarcsFlag])
forall {a}.
OptSpec
DarcsOptDescr
DarcsFlag
a
(Bool -> Bool -> Bool -> Bool -> Maybe String -> DryRun -> a)
addBasicOpts DarcsOption
(UseCache
-> UseIndex -> HooksConfig -> Bool -> Bool -> [DarcsFlag])
(UMask
-> UseCache
-> UseIndex
-> HooksConfig
-> Bool
-> Bool
-> [DarcsFlag])
PrimDarcsOption UMask
addAdvancedOpts
addCmd :: (AbsolutePath, AbsolutePath)
-> [DarcsFlag]
-> [String]
-> IO ()
addCmd :: (AbsolutePath, AbsolutePath) -> [DarcsFlag] -> [String] -> IO ()
addCmd (AbsolutePath, AbsolutePath)
fps [DarcsFlag]
opts [String]
args
| [String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
args = String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Nothing specified, nothing added. " String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"Maybe you wanted to say `darcs add --recursive .'?"
| Bool
otherwise = do
paths <- (AbsolutePath, AbsolutePath) -> [String] -> IO [AnchoredPath]
pathsFromArgs (AbsolutePath, AbsolutePath)
fps [String]
args
case paths of
[] -> String -> IO ()
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"No valid repository paths were given"
[AnchoredPath]
_ -> [DarcsFlag] -> [AnchoredPath] -> IO ()
addFiles [DarcsFlag]
opts [AnchoredPath]
paths
addFiles :: [DarcsFlag] -> [AnchoredPath] -> IO ()
addFiles :: [DarcsFlag] -> [AnchoredPath] -> IO ()
addFiles [DarcsFlag]
opts [AnchoredPath]
paths =
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
$ \Repository 'RW p wU wR
repository -> do
cur <- Tree IO -> IO (Tree IO)
forall (m :: * -> *). Monad m => Tree m -> m (Tree m)
expand (Tree IO -> IO (Tree IO)) -> IO (Tree IO) -> IO (Tree IO)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Repository 'RW p wU wR -> IO (Tree IO)
forall (p :: * -> * -> *) (rt :: AccessType) wU wR.
(RepoPatch p, ApplyState p ~ Tree) =>
Repository rt p wU wR -> IO (Tree IO)
readPristineAndPending Repository 'RW p wU wR
repository
let parent_paths = Tree IO -> [AnchoredPath] -> [AnchoredPath]
notInTreeParents Tree IO
cur [AnchoredPath]
paths
working <- readWorking (TreeFilter (Tree.filter (filterPaths paths)))
let all_paths = [AnchoredPath] -> [AnchoredPath]
forall a. Ord a => [a] -> [a]
nubSort ([AnchoredPath] -> [AnchoredPath])
-> [AnchoredPath] -> [AnchoredPath]
forall a b. (a -> b) -> a -> b
$ [AnchoredPath]
parent_paths [AnchoredPath] -> [AnchoredPath] -> [AnchoredPath]
forall a. [a] -> [a] -> [a]
++
(if PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
parseFlags PrimOptSpec DarcsOptDescr DarcsFlag a Bool
PrimDarcsOption Bool
O.recursive [DarcsFlag]
opts
then Tree IO -> [AnchoredPath] -> [AnchoredPath]
explodePaths Tree IO
working
else [AnchoredPath] -> [AnchoredPath]
forall a. a -> a
id) [AnchoredPath]
paths
all_orig_paths = (AnchoredPath -> String) -> [AnchoredPath] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map AnchoredPath -> String
displayPath [AnchoredPath]
all_paths
boring <- isBoring
let nboring a -> String
s = if PrimOptSpec DarcsOptDescr DarcsFlag a Bool
PrimDarcsOption Bool
O.includeBoring 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
id else (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Bool
boring (String -> Bool) -> (a -> String) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
s)
mapM_ (putWarning opts . text . ((msgSkipping msgs ++ " boring file ")++)) $
all_orig_paths \\ nboring id all_orig_paths
Sealed ps <- fmap unFreeLeft $ addp msgs opts cur $ nboring realPath all_paths
when (nullFL ps && not (null paths)) $
fail "No files were added"
addToPending repository (diffingOpts opts) ps
void $ finalizeRepositoryChanges repository (O.dryRun ? opts)
unless gotDryRun $ do
putInfo opts $ vcat $
map text $ ["Finished adding:"] ++ map displayPath (listTouchedFiles ps)
where
gotDryRun :: Bool
gotDryRun = 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 DryRun -> DryRun -> Bool
forall a. Eq a => a -> a -> Bool
== DryRun
O.YesDryRun
msgs :: AddMessages
msgs | Bool
gotDryRun = AddMessages
dryRunMessages
| Bool
otherwise = AddMessages
normalMessages
notInTreeParents :: Tree IO -> [AnchoredPath] -> [AnchoredPath]
notInTreeParents :: Tree IO -> [AnchoredPath] -> [AnchoredPath]
notInTreeParents Tree IO
cur = (AnchoredPath -> Bool) -> [AnchoredPath] -> [AnchoredPath]
forall a. (a -> Bool) -> [a] -> [a]
filter (Maybe (Tree IO) -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe (Tree IO) -> Bool)
-> (AnchoredPath -> Maybe (Tree IO)) -> AnchoredPath -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tree IO -> AnchoredPath -> Maybe (Tree IO)
forall (m :: * -> *). Tree m -> AnchoredPath -> Maybe (Tree m)
findTree Tree IO
cur) ([AnchoredPath] -> [AnchoredPath])
-> ([AnchoredPath] -> [AnchoredPath])
-> [AnchoredPath]
-> [AnchoredPath]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AnchoredPath -> [AnchoredPath])
-> [AnchoredPath] -> [AnchoredPath]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap AnchoredPath -> [AnchoredPath]
parents
addp :: forall prim . (PrimPatch prim, ApplyState prim ~ Tree)
=> AddMessages
-> [DarcsFlag]
-> Tree IO
-> [AnchoredPath]
-> IO (FreeLeft (FL prim))
addp :: forall (prim :: * -> * -> *).
(PrimPatch prim, ApplyState prim ~ Tree) =>
AddMessages
-> [DarcsFlag]
-> Tree IO
-> [AnchoredPath]
-> IO (FreeLeft (FL prim))
addp AddMessages
msgs [DarcsFlag]
opts Tree IO
cur0 [AnchoredPath]
files = do
(ps, dups) <-
(AnchoredPath
-> (Tree IO
-> [FreeLeft (FL prim)]
-> [AnchoredPath]
-> IO ([FreeLeft (FL prim)], [AnchoredPath]))
-> Tree IO
-> [FreeLeft (FL prim)]
-> [AnchoredPath]
-> IO ([FreeLeft (FL prim)], [AnchoredPath]))
-> (Tree IO
-> [FreeLeft (FL prim)]
-> [AnchoredPath]
-> IO ([FreeLeft (FL prim)], [AnchoredPath]))
-> [AnchoredPath]
-> Tree IO
-> [FreeLeft (FL prim)]
-> [AnchoredPath]
-> IO ([FreeLeft (FL prim)], [AnchoredPath])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr
(\AnchoredPath
f Tree IO
-> [FreeLeft (FL prim)]
-> [AnchoredPath]
-> IO ([FreeLeft (FL prim)], [AnchoredPath])
rest Tree IO
cur [FreeLeft (FL prim)]
accPS [AnchoredPath]
accDups -> do
addResult <- Tree IO
-> AnchoredPath
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
addp' Tree IO
cur AnchoredPath
f
case addResult of
(Tree IO
_, Maybe (FreeLeft (FL prim))
Nothing, Maybe AnchoredPath
Nothing) -> ([FreeLeft (FL prim)], [AnchoredPath])
-> IO ([FreeLeft (FL prim)], [AnchoredPath])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [])
(Tree IO
cur', Maybe (FreeLeft (FL prim))
mp, Maybe AnchoredPath
mdup) -> Tree IO
-> [FreeLeft (FL prim)]
-> [AnchoredPath]
-> IO ([FreeLeft (FL prim)], [AnchoredPath])
rest Tree IO
cur' (Maybe (FreeLeft (FL prim)) -> [FreeLeft (FL prim)]
forall a. Maybe a -> [a]
maybeToList Maybe (FreeLeft (FL prim))
mp [FreeLeft (FL prim)]
-> [FreeLeft (FL prim)] -> [FreeLeft (FL prim)]
forall a. [a] -> [a] -> [a]
++ [FreeLeft (FL prim)]
accPS) (Maybe AnchoredPath -> [AnchoredPath]
forall a. Maybe a -> [a]
maybeToList Maybe AnchoredPath
mdup [AnchoredPath] -> [AnchoredPath] -> [AnchoredPath]
forall a. [a] -> [a] -> [a]
++ [AnchoredPath]
accDups))
(\Tree IO
_ [FreeLeft (FL prim)]
ps [AnchoredPath]
dups -> ([FreeLeft (FL prim)], [AnchoredPath])
-> IO ([FreeLeft (FL prim)], [AnchoredPath])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([FreeLeft (FL prim)] -> [FreeLeft (FL prim)]
forall a. [a] -> [a]
reverse [FreeLeft (FL prim)]
ps, [AnchoredPath]
dups))
[AnchoredPath]
files
Tree IO
cur0 [] []
let uniq_dups = [AnchoredPath] -> [AnchoredPath]
forall a. Eq a => [a] -> [a]
nub [AnchoredPath]
dups
caseMsg =
if Bool
gotAllowCaseOnly then String
":"
else String
";\nnote that to ensure portability we don't allow\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"files that differ only in case. Use --case-ok to override this:"
unless (null dups) $ do
dupMsg <-
case uniq_dups of
[AnchoredPath
f] -> do
isDir <- String -> IO Bool
doesDirectoryReallyExist (AnchoredPath -> String
realPath AnchoredPath
f)
if isDir
then return $
"The following directory " ++
msgIs msgs ++ " already in the repository"
else return $
"The following file " ++
msgIs msgs ++ " already in the repository"
[AnchoredPath]
fs -> do
areDirs <- (AnchoredPath -> IO Bool) -> [AnchoredPath] -> IO [Bool]
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 -> IO Bool
doesDirectoryReallyExist (String -> IO Bool)
-> (AnchoredPath -> String) -> AnchoredPath -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnchoredPath -> String
realPath) [AnchoredPath]
fs
if and areDirs
then return $
"The following directories " ++
msgAre msgs ++ " already in the repository"
else
(if or areDirs
then return $
"The following files and directories " ++
msgAre msgs ++ " already in the repository"
else return $
"The following files " ++
msgAre msgs ++ " already in the repository")
putWarning opts . text $ "WARNING: Some files were not added because they are already in the repository."
putVerboseWarning opts . text $ dupMsg ++ caseMsg
mapM_ (putVerboseWarning opts . text . displayPath) uniq_dups
return $ concatGapsFL ps
where
addp' :: Tree IO
-> AnchoredPath
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
addp' :: Tree IO
-> AnchoredPath
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
addp' Tree IO
cur AnchoredPath
f = do
already_has <- (if Bool
gotAllowCaseOnly then Tree IO -> AnchoredPath -> IO Bool
forall (m :: * -> *). Monad m => Tree m -> AnchoredPath -> m Bool
treeHas else Tree IO -> AnchoredPath -> IO Bool
forall (m :: * -> *). Monad m => Tree m -> AnchoredPath -> m Bool
treeHasAnycase) Tree IO
cur AnchoredPath
f
mstatus <- getFileStatus (realPath f)
case (already_has, is_badfilename, mstatus) of
(Bool
True, Bool
_, Maybe FileStatus
_) -> (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tree IO
cur, Maybe (FreeLeft (FL prim))
forall a. Maybe a
Nothing, AnchoredPath -> Maybe AnchoredPath
forall a. a -> Maybe a
Just AnchoredPath
f)
(Bool
_, Bool
True, Maybe FileStatus
_) -> do
[DarcsFlag] -> Doc -> IO ()
putWarning [DarcsFlag]
opts (Doc -> IO ()) -> (String -> Doc) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$
String
"The filename " String -> String -> String
forall a. [a] -> [a] -> [a]
++ AnchoredPath -> String
displayPath AnchoredPath
f String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" is invalid on Windows.\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"Use --reserved-ok to allow it."
(Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall {a} {a}. (Tree IO, Maybe a, Maybe a)
add_failure
(Bool
_, Bool
_, Just FileStatus
s)
| FileStatus -> Bool
isDirectory FileStatus
s -> FreeLeft (FL prim)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
trypatch (FreeLeft (FL prim)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath))
-> FreeLeft (FL prim)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall a b. (a -> b) -> a -> b
$ (forall wX wY. FL prim wX wY) -> FreeLeft (FL prim)
forall (p :: * -> * -> *). (forall wX wY. p wX wY) -> FreeLeft p
forall (w :: (* -> * -> *) -> *) (p :: * -> * -> *).
Gap w =>
(forall wX wY. p wX wY) -> w p
freeGap (AnchoredPath -> prim wX wY
forall wX wY. AnchoredPath -> prim wX wY
forall (prim :: * -> * -> *) wX wY.
PrimConstruct prim =>
AnchoredPath -> prim wX wY
adddir AnchoredPath
f prim wX wY -> FL prim wY wY -> FL prim wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL)
| FileStatus -> Bool
isRegularFile FileStatus
s -> FreeLeft (FL prim)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
trypatch (FreeLeft (FL prim)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath))
-> FreeLeft (FL prim)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall a b. (a -> b) -> a -> b
$ (forall wX wY. FL prim wX wY) -> FreeLeft (FL prim)
forall (p :: * -> * -> *). (forall wX wY. p wX wY) -> FreeLeft p
forall (w :: (* -> * -> *) -> *) (p :: * -> * -> *).
Gap w =>
(forall wX wY. p wX wY) -> w p
freeGap (AnchoredPath -> prim wX wY
forall wX wY. AnchoredPath -> prim wX wY
forall (prim :: * -> * -> *) wX wY.
PrimConstruct prim =>
AnchoredPath -> prim wX wY
addfile AnchoredPath
f prim wX wY -> FL prim wY wY -> FL prim wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL prim wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL)
| FileStatus -> Bool
isSymbolicLink FileStatus
s -> do
[DarcsFlag] -> Doc -> IO ()
putWarning [DarcsFlag]
opts (Doc -> IO ()) -> (String -> Doc) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$
String
"Sorry, file " String -> String -> String
forall a. [a] -> [a] -> [a]
++ AnchoredPath -> String
displayPath AnchoredPath
f String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
" is a symbolic link, which is unsupported by darcs."
(Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall {a} {a}. (Tree IO, Maybe a, Maybe a)
add_failure
(Bool, Bool, Maybe FileStatus)
_ -> do
[DarcsFlag] -> Doc -> IO ()
putWarning [DarcsFlag]
opts (Doc -> IO ()) -> (String -> Doc) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"File "String -> String -> String
forall a. [a] -> [a] -> [a]
++ AnchoredPath -> String
displayPath AnchoredPath
f String -> String -> String
forall a. [a] -> [a] -> [a]
++String
" does not exist!"
(Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
forall {a} {a}. (Tree IO, Maybe a, Maybe a)
add_failure
where
is_badfilename :: Bool
is_badfilename = Bool -> Bool
not (Bool
gotAllowWindowsReserved Bool -> Bool -> Bool
|| String -> Bool
WindowsFilePath.isValid (AnchoredPath -> String
realPath AnchoredPath
f))
add_failure :: (Tree IO, Maybe a, Maybe a)
add_failure = (Tree IO
cur, Maybe a
forall a. Maybe a
Nothing, Maybe a
forall a. Maybe a
Nothing)
trypatch :: FreeLeft (FL prim)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
trypatch :: FreeLeft (FL prim)
-> IO (Tree IO, Maybe (FreeLeft (FL prim)), Maybe AnchoredPath)
trypatch FreeLeft (FL prim)
p = do
perms <- String -> IO Permissions
getPermissions (AnchoredPath -> String
realPath AnchoredPath
f)
if not $ readable perms
then do
putWarning opts . text $
msgSkipping msgs ++ " '" ++ displayPath f ++ "': permission denied "
return (cur, Nothing, Nothing)
else trypatch' p
trypatch' :: FreeLeft p -> IO (Tree IO, Maybe (FreeLeft p), Maybe a)
trypatch' FreeLeft p
p = do
Sealed p' <- Sealed (p (ZonkAny 0)) -> IO (Sealed (p (ZonkAny 0)))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sealed (p (ZonkAny 0)) -> IO (Sealed (p (ZonkAny 0))))
-> Sealed (p (ZonkAny 0)) -> IO (Sealed (p (ZonkAny 0)))
forall a b. (a -> b) -> a -> b
$ FreeLeft p -> Sealed (p (ZonkAny 0))
forall (p :: * -> * -> *) wX. FreeLeft p -> Sealed (p wX)
unFreeLeft FreeLeft p
p
ok <- treeHasDir cur parentdir
if ok
then do
tree <- applyToTree p' cur
putInfo opts . text $
msgAdding msgs ++ " '" ++ displayPath f ++ "'"
return (tree, Just p, Nothing)
else do
putWarning opts . text $
msgSkipping msgs ++ " '" ++ displayPath f ++
"' ... couldn't add parent directory '" ++
displayPath parentdir ++ "' to repository"
return (cur, Nothing, Nothing)
IO (Tree IO, Maybe (FreeLeft p), Maybe a)
-> (IOException -> IO (Tree IO, Maybe (FreeLeft p), Maybe a))
-> IO (Tree IO, Maybe (FreeLeft p), Maybe a)
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`catch` \(IOException
e :: IOException) -> do
[DarcsFlag] -> Doc -> IO ()
putWarning [DarcsFlag]
opts (Doc -> IO ()) -> (String -> Doc) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$
AddMessages -> String
msgSkipping AddMessages
msgs String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ AnchoredPath -> String
displayPath AnchoredPath
f String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"' ... " String -> String -> String
forall a. [a] -> [a] -> [a]
++ IOException -> String
forall a. Show a => a -> String
show IOException
e
(Tree IO, Maybe (FreeLeft p), Maybe a)
-> IO (Tree IO, Maybe (FreeLeft p), Maybe a)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Tree IO
cur, Maybe (FreeLeft p)
forall a. Maybe a
Nothing, Maybe a
forall a. Maybe a
Nothing)
parentdir :: AnchoredPath
parentdir = AnchoredPath -> Maybe AnchoredPath -> AnchoredPath
forall a. a -> Maybe a -> a
fromMaybe (String -> AnchoredPath
forall a. HasCallStack => String -> a
error String
"cannot take parent of root path") (Maybe AnchoredPath -> AnchoredPath)
-> Maybe AnchoredPath -> AnchoredPath
forall a b. (a -> b) -> a -> b
$ AnchoredPath -> Maybe AnchoredPath
parent AnchoredPath
f
gotAllowCaseOnly :: Bool
gotAllowCaseOnly = PrimOptSpec DarcsOptDescr DarcsFlag a Bool
PrimDarcsOption Bool
allowCaseDifferingFilenames PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts
gotAllowWindowsReserved :: Bool
gotAllowWindowsReserved = PrimOptSpec DarcsOptDescr DarcsFlag a Bool
PrimDarcsOption Bool
allowWindowsReservedFilenames PrimDarcsOption Bool -> [DarcsFlag] -> Bool
forall (d :: * -> *) f v.
(forall a. PrimOptSpec d f a v) -> [f] -> v
? [DarcsFlag]
opts
data AddMessages = AddMessages
{
AddMessages -> String
msgSkipping :: String
, AddMessages -> String
msgAdding :: String
, AddMessages -> String
msgIs :: String
, AddMessages -> String
msgAre :: String
}
normalMessages :: AddMessages
normalMessages :: AddMessages
normalMessages = AddMessages
{
msgSkipping :: String
msgSkipping = String
"Skipping"
, msgAdding :: String
msgAdding = String
"Adding"
, msgIs :: String
msgIs = String
"is"
, msgAre :: String
msgAre = String
"are"
}
dryRunMessages :: AddMessages
dryRunMessages :: AddMessages
dryRunMessages = AddMessages
{
msgSkipping :: String
msgSkipping = String
"Would skip"
, msgAdding :: String
msgAdding = String
"Would add"
, msgIs :: String
msgIs = String
"would be"
, msgAre :: String
msgAre = String
"would be"
}