%Copyright(C)2007KevinQuick%%Thisprogramisfreesoftware;youcanredistributeitand/ormodify%itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby%theFreeSoftwareFoundation;eitherversion2,or(atyouroption)%anylaterversion.%%Thisprogramisdistributedinthehopethatitwillbeuseful,%butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof%MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe%GNUGeneralPublicLicenseformoredetails.%%YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense%alongwiththisprogram;seethefileCOPYING.Ifnot,writeto%theFreeSoftwareFoundation,Inc.,51FranklinStreet,FifthFloor,%Boston,MA02110-1301,USA.\subsubsection{darcsshowrepo}%%\label{show-repo}\options{showrepo}The\verb!showrepo!displaysinformationaboutthecurrentrepository:thelocation,thetype,etc.Thisisprovidedasinformationaloutputfortwopurposes:curioususersandscriptsinvokingdarcs.Forthelatter,thisinformationcanbeparsedtofacilitatethescript;forexample,\verb!darcsshowrepo|grepRoot:|awk{print$2}!canbeusedtolocatethetop-level\verb!_darcs!directoryfromanyplacewithinadarcsrepositoryworkingdirectory.\begin{code}{-# OPTIONS_GHC -cpp #-}{-# LANGUAGE CPP #-}#include "gadts.h"moduleDarcs.Commands.ShowRepo(show_repo)whereimportData.Char(toLower,isSpace)importData.List(intersperse)importControl.Monad(when,unless)importText.Html(tag,stringToHtml)importDarcs.Arguments(DarcsFlag(..),working_repo_dir,files,xmloutput)importDarcs.Commands(DarcsCommand(..),nodefaults)importDarcs.Repository(withRepository,($-),amInRepository,read_repo)importDarcs.Repository.Internal(Repository(..),RepoType(..))importDarcs.Repository.Format(RepoFormat(..))importDarcs.Repository.Prefs(get_preflist)importDarcs.Repository.Motd(get_motd)importDarcs.Global(darcsdir)importDarcs.Patch(RepoPatch)importDarcs.Ordered(lengthRL,concatRL)importqualifiedData.ByteString.Char8asBC(unpack)show_repo_help::Stringshow_repo_help="The repo command displays information about the current repository\n"++"(location, type, etc.). Some of this information is already available\n"++"by inspecting files within the "++darcsdir++" directory and some is internal\n"++"information that is informational only (i.e. for developers). This\n"++"command collects all of the repository information into a readily\n"++"available source.\n"show_repo_description::Stringshow_repo_description="Show repository summary information"show_repo::DarcsCommandshow_repo=DarcsCommand{command_name="repo",command_help=show_repo_help,command_description=show_repo_description,command_extra_args=0,command_extra_arg_help=[],command_command=repo_cmd,command_prereq=amInRepository,command_get_arg_possibilities=return[],command_argdefaults=nodefaults,command_advanced_options=[],command_basic_options=[working_repo_dir,files,xmloutput]}\end{code}\begin{options}--files, --no-files\end{options}Ifthe\verb!--files!optionisspecified(thedefault),thenthe\verb!showrepo!operationwillreadpatchinformationfromtherepositoryanddisplaythenumberofpatchesintherepository.The\verb!--no-files!optioncanbeusedtosuppressthisoperation(andimproveperformance).\begin{code}repo_cmd::[DarcsFlag]->[String]->IO()repo_cmdopts_=letput_mode=ifXMLOutput`elem`optsthenshowInfoXMLelseshowInfoUsrinwithRepositoryopts$-\repository->showRepo(putInfoput_mode)repository\end{code}\begin{options}--human-readable, --xml-output\end{options}Bydefault,the\verb!showrepo!displaysoutputinhumanreadableform,butthe\verb!--xml-output!optioncanbeusedtoobtainXML-formattedtofacilitateregularparsingbyexternaltools.\begin{code}-- Some convenience functions to output a labelled text string or an-- XML tag + value (same API). If no value, output is suppressed-- entirely. Borrow some help from Text.Html to perform XML output.typeShowInfo=String->String->StringshowInfoXML::ShowInfoshowInfoXMLti=show$tag(safeTagt)$stringToHtmlisafeTag::String->StringsafeTag[]=[]safeTag(' ':cs)=safeTagcssafeTag('#':cs)="num_"++(safeTagcs)safeTag(c:cs)=toLowerc:safeTagcs-- labelled strings: labels are right-aligned at 14 characters;-- subsequent lines in multi-line output are indented accordingly.showInfoUsr::ShowInfoshowInfoUsrti=(replicate(14-length(t))' ')++t++": "++(concat$intersperse('\n':(replicate16' '))$linesi)++"\n"typePutInfo=String->String->IO()putInfo::ShowInfo->PutInfoputInfomti=unless(nulli)(putStr$mti)-- Primary show-repo operation. Determines ordering of output for-- sub-displays. The `out' argument is one of the above operations to-- output a labelled text string or an XML tag and contained value.showRepo::RepoPatchp=>PutInfo->RepositorypC(rur)->IO()showRepooutr@(Repolocoptsrfrt)=dowhen(XMLOutput`elem`opts)(putStr"<repository>\n")showRepoTypeoutrtwhen(Verbose`elem`opts)(out"Show"$showr)showRepoFormatoutrfout"Root"locshowRepoAuxoutrtshowRepoPrefsoutunless(NoFiles`elem`opts)(numPatchesr>>=(out"Num Patches".show))showRepoMOTDoutrwhen(XMLOutput`elem`opts)(putStr"</repository>\n")-- Most of the actual elements being displayed are part of the Show-- class; that's fine for a Haskeller, but not for the common user, so-- the routines below work to provide more human-readable information-- regarding the repository elements.showRepoType::PutInfo->RepoTypep->IO()showRepoTypeout(DarcsRepository__)=out"Type""darcs"showRepoFormat::PutInfo->RepoFormat->IO()showRepoFormatout(RFrf)=out"Format"$concat$intersperse", "(map(concat.intersperse"|".mapBC.unpack)rf)showRepoAux::PutInfo->RepoTypep->IO()showRepoAuxout(DarcsRepositorypriscs)=doout"Pristine"$showprisout"Cache"$concat$intersperse", "$lines$showcsshowRepoPrefs::PutInfo->IO()showRepoPrefsout=doget_preflist"prefs">>=mapM_prefOutget_preflist"author">>=out"Author".unlinesget_preflist"defaultrepo">>=out"Default Remote".unlineswhereprefOut=uncurryout.(\(p,v)->(p++" Pref",(dropWhileisSpacev))).breakisSpaceshowRepoMOTD::RepoPatchp=>PutInfo->RepositorypC(rur)->IO()showRepoMOTDout(Repoloc___)=get_motdloc>>=out"MOTD".BC.unpack-- Support routines to provide information used by the PutInfo operations above.numPatches::RepoPatchp=>RepositorypC(rur)->IOIntnumPatchesr=read_repor>>=(return.lengthRL.concatRL)\end{code}