%Copyright(C)2003DavidRoundy%%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.\subsection{darcsdist}\begin{code}moduleDarcs.Commands.Dist(dist)whereimportSystem.Directory(setCurrentDirectory)importWorkaround(getCurrentDirectory)importSystem.Exit(ExitCode(..))importSystem.Cmd(system)importSystem.FilePath.Posix(takeFileName,(</>))importData.Char(isAlphaNum)importControl.Monad(when)importDarcs.Commands(DarcsCommand(DarcsCommand,command_name,command_help,command_description,command_extra_args,command_extra_arg_help,command_command,command_prereq,command_get_arg_possibilities,command_argdefaults,command_advanced_options,command_basic_options),nodefaults)importDarcs.Arguments(DarcsFlag(Verbose,DistName),distname_option,working_repo_dir,match_one,store_in_memory,fixSubPaths)importDarcs.Match(get_nonrange_match,have_nonrange_match)importDarcs.Repository(amInRepository,withRepoReadLock,($-),--withRecorded,createPartialsPristineDirectoryTree)importDarcs.Repository.Prefs(get_prefval)importDarcs.Lock(withTemp,withTempDir,readBinFile)importDarcs.RepoPath(toFilePath)importDarcs.Utils(withCurrentDirectory)importExec(exec,Redirect(..))\end{code}\options{dist}\haskell{dist_help}\begin{code}dist_description::Stringdist_description="Create a distribution tarball."dist_help::Stringdist_help="The `darcs dist' command creates a compressed archive (a `tarball') in\n"++"the repository's root directory, containing the recorded state of the\n"++-- FIXME: _ is escaped to appease TeX while we wait for reST."working tree (unrecorded changes and the \\_darcs directory are\n"++"excluded).\n"++"\n"++"If a predist command is set (see `darcs setpref'), that command will\n"++"be run on the tarball contents prior to archiving. For example,\n"++-- FIXME: &s are escaped to appease TeX while we wait for reST."autotools projects would set it to `autoconf \\&\\& automake'.\n"++"\n"++"By default, the tarball (and the top-level directory within the\n"++"tarball) has the same name as the repository, but this can be\n"++"overridden with the --dist-name option.\n"-- FIXME: this is tedious and ugly.{-
++ "\n" ++
"Suppose you use a version numbering scheme `major.minor.patch', and\n" ++
"you tag each release `major.minor'. You can then calculate the\n" ++
"version number by taking the newest tag and appending a dot and the\n" ++
"number of patches since that tag. If you use the directory name as\n" ++
"the project name, you can make tarballs of the form name-version.tgz\n" ++
"using the following shell script:\n" ++
"\n" ++
" major_minor=$(darcs show tags | head -1) &&\n" ++
" patch_level=$(($(darcs changes --count --from-tag .) - 1)) &&\n" ++
" version=$major_minor.$patch_level &&\n" ++
" project=${PWD##*/} &&\n" ++
" darcs dist --dist-name \"$project\"-\"$version\".tar.gz\n"
-}dist::DarcsCommanddist=DarcsCommand{command_name="dist",command_help=dist_help,command_description=dist_description,command_extra_args=0,command_extra_arg_help=[],command_command=dist_cmd,command_prereq=amInRepository,command_get_arg_possibilities=return[],command_argdefaults=nodefaults,command_advanced_options=[],command_basic_options=[distname_option,working_repo_dir,match_one,store_in_memory]}dist_cmd::[DarcsFlag]->[String]->IO()dist_cmdoptsargs=withRepoReadLockopts$-\repository->dodistname<-get_dist_nameoptsverb<-return$Verbose`elem`optspredist<-get_prefval"predist"formerdir<-getCurrentDirectorypath_list<-ifnullargsthenreturn[""]elsemaptoFilePath`fmap`fixSubPathsoptsargsresultfile<-return(formerdir</>distname++".tar.gz")withTemp$\tarfile->withTempDir"darcsdist"$\tempdir->dosetCurrentDirectory(formerdir)withTempDir(toFilePathtempdir</>takeFileNamedistname)$\ddir->doifhave_nonrange_matchoptsthenwithCurrentDirectoryddir$get_nonrange_matchrepositoryoptselsecreatePartialsPristineDirectoryTreerepositorypath_list(toFilePathddir)casepredistofNothing->returnExitSuccessJustpd->systempdsetCurrentDirectory(toFilePathtempdir)exec"tar"["-cf","-",safename$takeFileName$toFilePathddir](Null,Filetarfile,AsIs)whenverb$withTemp$\tar_listing->doexec"tar"["-tf","-"](Filetarfile,Filetar_listing,Stdout)to<-readBinFiletar_listingputStrtoexec"gzip"["-c"](Filetarfile,Fileresultfile,AsIs)putStrLn$"Created dist as "++resultfilewheresafenamen@(c:_)|isAlphaNumc=nsafenamen="./"++nguess_repo_name::IOStringguess_repo_name=dopwd<-getCurrentDirectoryif'/'`elem`pwdthenreturn$reverse$takeWhile(/='/')$reversepwdelsereturn"cantguessreponame"get_dist_name::[DarcsFlag]->IOStringget_dist_name(DistNamedn:_)=returndnget_dist_name(_:fs)=get_dist_namefsget_dist_name_=guess_repo_name\end{code}