On Sat, Nov 11, 2006 at 11:35:34 -0500, Ralph Dratman wrote: > That is fascinating! Thank you! But why should we have to use a trick?
Because nobody has gotten around to implementing darcs query cat yet: http://bugs.darcs.net/issue141 In case anybody wants to take the initiative, attached is my very incomplete attempt from a long time ago, bits copied and pasted from diff (or was it annotate), so incomplete, it probably doesn't even compile or make any sense. -- Eric Kow http://www.loria.fr/~kow PGP Key ID: 08AC04F9 Merci de corriger mon français.
% Copyright (C) 2006 Eric Kow
%
% 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; if not, write to the Free Software Foundation,
% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\subsection{darcs query cat}
\label{query-cat}
\begin{code}
module QueryCat ( query_cat ) where
import Control.Monad ( liftM )
import ColourPrinter ( fancyPrinters )
import DarcsArguments ( DarcsFlag(..), match_one, working_repo_dir,
fix_filepath,
files, directories, pending, nullFlag )
import DarcsCommands ( DarcsCommand(..), nodefaults )
import DarcsUtils ( withCurrentDirectory )
import External ( clonePaths )
import FileName ( fp2fn )
import FilePathUtils ( (///) )
import Lock ( withTempDir )
import Match ( get_first_match, get_second_match,
first_match, second_match,
match_first_patchset, match_second_patchset,
)
import PatchCore ( fn2d )
import Repository ( amInRepository, slurp_pending, slurp_recorded,
slurp_recorded_and_unrecorded,
withRepoLock )
import SlurpDirectory ( list_slurpy, list_slurpy_files, list_slurpy_dirs,
get_path_list )
import Workaround ( getCurrentDirectory )
\end{code}
\options{query cat}
\haskell{query_cat_help}
\begin{code}
query_cat_description :: String
query_cat_description = "Output contents of version-controlled files."
\end{code}
\begin{code}
query_cat_help :: String
query_cat_help =
"The cat command outputs the contents of a version-controlled file or files."
++ " This is useful for retrieving prior versions of a given file\n"
\end{code}
\begin{code}
query_cat :: DarcsCommand
query_cat = DarcsCommand {
command_name = "cat",
command_help = query_cat_help,
command_description = query_cat_description,
command_extra_args = 0,
command_extra_arg_help = [],
command_command = cat_cmd,
command_prereq = amInRepository,
command_get_arg_possibilities = return [],
command_argdefaults = nodefaults,
command_darcsoptions = [match_one,
files,
working_repo_dir] }
cat_cmd :: [DarcsFlag] -> [String] -> IO ()
cat_cmd opts args =
do formerdir <- getCurrentDirectory
thename <- return $ just_dir formerdir
withTempDir ("cat-"++thename) $ \dir -> do
if second_match opts
then -- apply selected patches in the temp directory
withCurrentDirectory dir $ get_second_match formerdir opts
else -- no match flag... means we just want the pristine version
do (_, s) <- slurp_recorded_and_unrecorded formerdir
let ps = concatMap (get_path_list s) path_list
clonePaths formerdir dir ps
--
case path_list of
[] -> return ()
fs -> -- Dump the contents of each file to the screen
-- Would it be better use FastPackedString here?
mapM (\f -> (putStr . readFile $ (just_dir dir /// f))) fs
where just_dir d = reverse $ takeWhile (/='/') $ reverse d
path_list = if null args then [""] else map (fix_filepath "" opts) args
\end{code}
pgprJKApBfehk.pgp
Description: PGP signature
_______________________________________________ darcs-users mailing list [email protected] http://www.abridgegame.org/mailman/listinfo/darcs-users
