% Copyright (C) 2007 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; see the file COPYING. If not, write to
% the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
% Boston, MA 02110-1301, USA.
\darcsCommand{show contents}
\begin{code}

moduleDarcs.Commands.ShowContents(showContents)whereimportControl.Monad(filterM,forM_,unless)importControl.Monad.Trans(liftIO)importSystem.IO(stdout)importData.Maybe(fromJust)importqualifiedData.ByteStringasBimportDarcs.Commands(DarcsCommand(..),nodefaults)importDarcs.Arguments(DarcsFlag,matchOne,workingRepoDir,fixSubPaths)importDarcs.RepoPath(sp2fn)importDarcs.IO(mReadFilePS,mDoesFileExist)importDarcs.Patch.Match(Matcher)importDarcs.Match(haveNonrangeMatch,applyInvToMatcher,nonrangeMatcher,InclusiveOrExclusive(..),matchExists)importDarcs.Repository(withRepository,($-),findRepository,readRepo,readRecorded)importDarcs.Patch(RepoPatch)importStorage.Hashed.Monad(virtualTreeIO)showContentsDescription::StringshowContentsDescription="Outputs a specific version of a file."showContentsHelp::StringshowContentsHelp="Show contents can be used to display an earlier version of some file(s).\n"++"If you give show contents no version arguments, it displays the recorded\n"++"version of the file(s).\n"showContents::DarcsCommandshowContents=DarcsCommand{commandProgramName="darcs",commandName="contents",commandHelp=showContentsHelp,commandDescription=showContentsDescription,commandExtraArgs=-1,commandExtraArgHelp=["[FILE]..."],commandCommand=showContentsCmd,commandPrereq=findRepository,commandGetArgPossibilities=return[],commandArgdefaults=nodefaults,commandAdvancedOptions=[],commandBasicOptions=[matchOne,workingRepoDir]}getMatcher::(RepoPatchp)=>[DarcsFlag]->MatcherpgetMatcher=fromJust.nonrangeMatchershowContentsCmd::[DarcsFlag]->[String]->IO()showContentsCmd_[]=fail"show contents needs at least one argument."showContentsCmdoptsargs=withRepositoryopts$-\repository->dopath_list<-mapsp2fn`fmap`fixSubPathsoptsargspristine<-readRecordedrepositoryletmatcher=getMatcheroptsunapply_to_match=applyInvToMatcherExclusivematchermatched<-if(haveNonrangeMatchopts)thendopatchset<-readReporepositoryunless(matchExistsmatcherpatchset)$fail$"Couldn't match pattern "++showmatchersnd`fmap`virtualTreeIO(unapply_to_matchpatchset)pristineelsereturnpristineletdump=dookpaths<-filterMmDoesFileExistpath_listforM_okpaths$\f->docontent<-mReadFilePSfliftIO(B.hPutstdoutcontent)virtualTreeIOdumpmatchedreturn()