From b0b5a1c4bb4d5957b8706ff40abc0dddfbe9fda8 Mon Sep 17 00:00:00 2001 From: vincents Date: Fri, 1 Oct 2004 11:52:58 +0000 Subject: [PATCH] Added cvsexportlocal tool, to create an cvs export from a local checked out cvs directory tree. git-svn-id: trunk@6095 - --- .gitattributes | 1 + tools/install/cvsexportlocal.pas | 131 +++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 tools/install/cvsexportlocal.pas diff --git a/.gitattributes b/.gitattributes index 57c858e4e5..1dd61c886d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1579,6 +1579,7 @@ tools/install/create_lazarus_deb.sh -text svneol=native#application/x-sh tools/install/create_lazarus_export_tgz.sh -text svneol=native#application/x-sh tools/install/create_lazarus_rpm.sh -text svneol=native#application/x-sh tools/install/create_lazarus_tgz_from_local_dir.sh -text svneol=native#application/x-sh +tools/install/cvsexportlocal.pas svneol=native#text/pascal tools/install/do_nothing.sh -text svneol=native#application/x-sh tools/install/download_and_build_fpc_rpm.sh -text svneol=native#application/x-sh tools/install/file_filter.sh -text svneol=native#application/x-sh diff --git a/tools/install/cvsexportlocal.pas b/tools/install/cvsexportlocal.pas new file mode 100644 index 0000000000..0b66eea738 --- /dev/null +++ b/tools/install/cvsexportlocal.pas @@ -0,0 +1,131 @@ +program cvsexportlocal; + +{$mode objfpc}{$H+} + +uses + Classes, SysUtils, FileUtil; + +var + InputDir: string; + OutputDir: string; + +type + TCvsDirectory = class + private + FDirectories: TStrings; + FDirectory: string; + FFiles: TStrings; + procedure LoadEntries; + public + constructor Create(ADirectory: string); + destructor Destroy; override; + property Files : TStrings read FFiles; + property Directories: TStrings read FDirectories; + end; + +{ TCvsDirectory } + +constructor TCvsDirectory.Create(ADirectory: string); +begin + FDirectory:= ADirectory; + FFiles:= TStringList.Create; + FDirectories := TStringList.Create; + LoadEntries; +end; + +destructor TCvsDirectory.Destroy; +begin + FreeAndNil(FFiles); + FreeAndNil(FDirectories); +end; + +procedure TCvsDirectory.LoadEntries; +var + EntriesPath: string; + Entries: TStrings; + i: integer; + Name: string; + + function IsDirectoryEntry(i: integer): boolean; + begin + result := (Length(Entries[i])>0) and (Entries[i][1]='D') + end; + + function GetNameFromEntry(i: integer): string; + var + FirstSlashPos: integer; + SecondSlashPos: integer; + Entry: string; + begin + Entry := Entries[i]; + FirstSlashPos := Pos('/',Entry); + SecondSlashPos := Pos('/', + Copy(Entry,FirstSlashPos+1,Length(Entry)-FirstSlashPos)); + Result := Copy(Entry, FirstSlashPos + 1, SecondSlashPos-1); + end; +begin + EntriesPath := AppendPathDelim(FDirectory)+'CVS'+DirectorySeparator+'Entries'; + Entries := TStringList.Create; + Entries.LoadFromFile(EntriesPath); + for i := 0 to Entries.Count-1 do begin + Name := GetNameFromEntry(i); + if Length(Name)>0 then + if IsDirectoryEntry(i) then + FDirectories.Add(Name) + else + FFiles.Add(Name); + end; + Entries.Free; +end; + +procedure Init; +begin + InputDir := ExpandFileName(ParamStr(1)); + OutputDir := ExpandFileName(ParamStr(2)); +end; + +procedure CopyCvsDirectory(const SourceDir, DestinationDir: string); +var + CvsDirectory: TCvsDirectory; + i: Integer; + + procedure CopyCvsFile(const FileName: string); + var + SourceFileName: string; + DestinationFileName: string; + begin + SourceFileName := AppendPathDelim(SourceDir)+FileName; + DestinationFileName := AppendPathDelim(DestinationDir)+FileName; + CopyFile(SourceFileName, DestinationFileName, true); + end; +begin + if DirectoryExists(DestinationDir) then + begin + writeln(format('Output directory %s exists. It will be deleted', + [DestinationDir])); + DeleteDirectory(DestinationDir, false); + end; + ForceDirectory(DestinationDir); + + CvsDirectory := TCvsDirectory.Create(SourceDir); + try + for i:= 0 to CvsDirectory.Files.Count-1 do + CopyCvsFile(CvsDirectory.Files[i]); + for i:= 0 to CvsDirectory.Directories.Count-1 do + CopyCvsDirectory(AppendPathDelim(SourceDir)+CvsDirectory.Directories[i], + AppendPathDelim(DestinationDir)+CvsDirectory.Directories[i]); + finally + CvsDirectory.Free; + end; +end; + +procedure Done; +begin +end; + +begin + Init; + CopyCvsDirectory(InputDir, OutputDir); + Done; +end. +