1 % Copyright (C) 2005 Florian Weimer
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
18 \subsubsection{darcs show files}
21 module Darcs.Commands.ShowFiles ( show_files, show_manifest ) where
22 import Darcs.Arguments ( DarcsFlag(..), working_repo_dir,
23 files, directories, pending, nullFlag )
24 import Darcs.Commands ( DarcsCommand(..), nodefaults, command_alias )
25 import Darcs.Repository ( Repository, amInRepository, slurp_pending, slurp_recorded,
27 import Darcs.Patch ( RepoPatch )
28 import Darcs.SlurpDirectory ( Slurpy, list_slurpy, list_slurpy_files, list_slurpy_dirs )
33 \haskell{show_files_help}
35 By default (and if the \verb!--pending! option is specified),
36 the effect of pending patches on the repository is taken into account.
37 In other words, if you add a file using {\tt darcs add}, it
38 immediately appears in the output of {\tt query manifest}, even if it
39 is not yet recorded. If you specify the \verb!--no-pending! option,
40 {\tt query manifest} will only list recorded files (and directories).
42 The \verb!--files! and \verb!--directories! options control whether
43 files and directories are included in the output. The
44 \verb!--no-files! and \verb!--no-directories! options have the
45 reverse effect. The default is to include files, but not directories.
47 If you specify the \verb!--null! option, the file names are written to
48 standard output in unescaped form, and separated by ASCII NUL bytes.
49 This format is suitable for further automatic processing (for example,
50 using \verb!xargs -0!).
53 show_files_description :: String
54 show_files_description = "Show version-controlled files in the working copy."
58 show_files_help :: String
60 "The files command lists the version-controlled files in the\n"++
61 "working copy. The similar manifest command, lists the same\n"++
62 "files, excluding any directories.\n"
66 show_files :: DarcsCommand
67 show_files = DarcsCommand {
68 command_name = "files",
69 command_help = show_files_help,
70 command_description = show_files_description,
71 command_extra_args = 0,
72 command_extra_arg_help = [],
73 command_command = manifest_cmd to_list_files,
74 command_prereq = amInRepository,
75 command_get_arg_possibilities = return [],
76 command_argdefaults = nodefaults,
77 command_advanced_options = [],
78 command_basic_options = [files, directories, pending, nullFlag,
81 show_manifest :: DarcsCommand
82 show_manifest = command_alias "manifest" show_files {
83 command_command = manifest_cmd to_list_manifest
86 to_list_files, to_list_manifest :: [DarcsFlag] -> Slurpy -> [FilePath]
87 to_list_files opts = files_dirs (NoFiles `notElem` opts) (NoDirectories `notElem` opts)
88 to_list_manifest opts = files_dirs (NoFiles `notElem` opts) (Directories `elem` opts)
90 files_dirs :: Bool -> Bool -> Slurpy -> [FilePath]
91 files_dirs False False = \_ -> []
92 files_dirs False True = list_slurpy_dirs
93 files_dirs True False = list_slurpy_files
94 files_dirs True True = list_slurpy
96 manifest_cmd :: ([DarcsFlag] -> Slurpy -> [FilePath]) -> [DarcsFlag] -> [String] -> IO ()
97 manifest_cmd to_list opts _ = do
98 list <- (to_list opts) `fmap` withRepository opts slurp
100 where slurp :: RepoPatch p => Repository p -> IO Slurpy
101 slurp = if NoPending `notElem` opts
102 then slurp_pending else slurp_recorded
103 output_null name = do { putStr name ; putChar '\0' }
104 output = if NullFlag `elem` opts then output_null else putStrLn