% Copyright (C) 2009 Petr Rockai
%
% Permission is hereby granted, free of charge, to any person
% obtaining a copy of this software and associated documentation
% files (the "Software"), to deal in the Software without
% restriction, including without limitation the rights to use, copy,
% modify, merge, publish, distribute, sublicense, and/or sell copies
% of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be
% included in all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
% BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.
\darcsCommand{show index}
\begin{code}

{-# OPTIONS_GHC -cpp #-}{-# LANGUAGE CPP #-}#include "gadts.h"moduleDarcs.Commands.ShowIndex(showIndex,showPristineCmd-- for alias)whereimportDarcs.Arguments(DarcsFlag(..),workingRepoDir,files,directories,nullFlag)importDarcs.Commands(DarcsCommand(..),nodefaults)importDarcs.Repository(amInRepository,withRepository,($-),readIndex)importDarcs.Repository.State(readRecorded)importStorage.Hashed(floatPath)importStorage.Hashed.Hash(encodeBase16,Hash(NoHash))importStorage.Hashed.Tree(list,expand,itemHash,Tree,TreeItem(SubTree))importStorage.Hashed.Index(updateIndex)importStorage.Hashed.AnchoredPath(anchorPath)importqualifiedData.ByteString.Char8asBSshowIndex::DarcsCommandshowIndex=DarcsCommand{commandName="index",commandDescription="Dump contents of working tree index.",commandHelp="The `darcs show index' command lists all version-controlled files and "++"directories along with their hashes as stored in _darcs/index. "++"For files, the fields correspond to file size, sha256 of the current "++"file content and the filename.",commandExtraArgs=0,commandExtraArgHelp=[],commandCommand=showIndexCmd,commandPrereq=amInRepository,commandGetArgPossibilities=return[],commandArgdefaults=nodefaults,commandAdvancedOptions=[],commandBasicOptions=[files,directories,nullFlag,workingRepoDir]}dump::[DarcsFlag]->TreeIO->IO()dumpoptstree=doletline|NullFlag`elem`opts=\t->putStrt>>putChar'\0'|otherwise=putStrLnoutput(p,i)=dolethash=caseitemHashiofNoHash->"(no hash available)"h->BS.unpack$encodeBase16hpath=anchorPath""pisdir=caseiofSubTree_->"/"_->""line$hash++" "++path++isdirx<-expandtreemapM_output$(floatPath".",SubTreex):listxshowIndexCmd::[DarcsFlag]->[String]->IO()showIndexCmdopts_=withRepositoryopts$-\repo->doreadIndexrepo>>=updateIndex>>=dumpoptsshowPristineCmd::[DarcsFlag]->[String]->IO()showPristineCmdopts_=withRepositoryopts$-\repo->doreadRecordedrepo>>=dumpopts