-- Copyright (C) 2003-2004 Jan Scheffczyk and David Roundy---- 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.moduleDarcs.PopulationData(Population(..),PopTree(..),Info(..),setPopState,notModified,setState,DirMark(..),getPopFrom)whereimportDarcs.Patch.InfoimportDarcs.Utils(withCurrentDirectory)importSystem.Directory(doesDirectoryExist,getDirectoryContents)importqualifiedData.ByteString.Char8asBCimportqualifiedData.ByteStringasB(ByteString)-- | the population of a darcs repository (simpler Slurpy)dataPopulation=Pop{popState::PatchInfo-- ^ the state when last modified,popTree::PopTree-- ^ the directory listing}deriving(Show,Eq)setPopState::PatchInfo->Population->PopulationsetPopStatei(Pop_tr)=Popitr-- | directory listingdataPopTree=PopDir!Info![PopTree]|PopFile!Infoderiving(Ord,Eq)-- | info of a directory memberdataDirMark=AddedFile|RemovedFile|MovedFileString|ModifiedFile|DullFile|AddedDir|RemovedDir|MovedDir!String|DullDirderiving(Ord,Eq)dataInfo=Info{nameI::!B.ByteString,-- ^ name of the elementmodifiedByI::!PatchInfo,-- ^ last patch modifying this elementmodifiedHowI::!DirMark,-- ^ how was it modifiedcreatedByI::!(MaybePatchInfo),-- ^ this can be unknown when restored backwards!creationNameI::!(MaybeB.ByteString)-- ^ the original name of the element}deriving(Ord,Eq)-- | was an Info record not modified?notModified::Info->BoolnotModifiedi=(modifiedHowIi==DullFile)||(modifiedHowIi==DullDir)-- | set the modifier for an Info recordsetState::Info->PatchInfo->InfosetStateipinfo=i{modifiedByI=pinfo}instanceShowPopTreewhereshows=showPop""sshowPop::String->PopTree->StringshowPopindent(PopDirifs)=indent++showi++"\n"++unlines(map(showPop(' ':indent))fs)showPopindent(PopFilei)=indent++showiinstanceShowInfowhereshowi=show(nameIi)++" "++show(modifiedHowIi)++" at state "++show(modifiedByIi)instanceShowDirMarkwhereshowAddedFile="File added"showRemovedFile="File removed"show(MovedFiles)="File moved to "++sshowModifiedFile="File modified"showDullFile="File old"showAddedDir="Dir added"showRemovedDir="Dir removed"show(MovedDirs)="Dir moved from "++sshowDullDir="Dir old"-- | read the population from a given directory @dirname@-- all folders and documents get the given time @t@---- This needs to be here in order to avoid a circular dependency-- between Population and Pristine.getPopFrom::FilePath->PatchInfo->IOPopulationgetPopFromthe_directorypinfo=withCurrentDirectorythe_directory$dopopT<-getPopFrom_helper"."return(PoppinfopopT)wheregetPopFrom_helper::FilePath->IOPopTreegetPopFrom_helperdirname=doisdir<-doesDirectoryExistdirnameletn=BC.packdirnameifisdirthendofnames<-getDirectoryContentsdirnamesl<-withCurrentDirectorydirname(sequence$mapgetPopFrom_helper$filternot_hiddenfnames)leti=Info{nameI=n,modifiedByI=pinfo,modifiedHowI=DullDir,createdByI=Justpinfo,creationNameI=Justn}return$PopDirislelsedoleti=Info{nameI=n,modifiedByI=pinfo,modifiedHowI=DullFile,createdByI=Justpinfo,creationNameI=Justn}return$PopFileinot_hidden::FilePath->Boolnot_hidden('.':_)=Falsenot_hidden('_':_)=Falsenot_hidden_=True