1
{ Classes for interpreting the output of svn commands
3
Copyright (C) 2007 Vincent Snijders vincents@freepascal.org
5
This library is free software; you can redistribute it and/or modify it
6
under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or (at your
8
option) any later version with the following modification:
10
As a special exception, the copyright holders of this library give you
11
permission to link this library with independent modules to produce an
12
executable, regardless of the license terms of these independent modules,and
13
to copy and distribute the resulting executable under terms of your choice,
14
provided that you also meet, for each linked independent module, the terms
15
and conditions of the license of that module. An independent module is a
16
module which is not derived from or based on this library. If you modify
17
this library, you may extend this exception to your version of the library,
18
but you are not obligated to do so. If you do not wish to do so, delete this
19
exception statement from your version.
21
This program is distributed in the hope that it will be useful, but WITHOUT
22
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
26
You should have received a copy of the GNU Library General Public License
27
along with this library; if not, write to the Free Software Foundation,
28
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41
function ExecuteSvnCommand(const Command: string; Output: TStream): integer;
42
function ExecuteSvnCommand(const Command: string): integer;
43
procedure DumpStream(const AStream: TStream);
46
SvnExecutable: string;
50
procedure InitializeSvnExecutable;
52
if FileExists(SvnExecutable) then exit;
54
SvnExecutable := GetEnvironmentVariable('ProgramFiles') + '\Subversion\bin\svn.exe';
56
if not FileExists(SvnExecutable) then
57
SvnExecutable := FindDefaultExecutablePath('svn');
58
if not FileExists(SvnExecutable) then
59
raise Exception.Create('No svn executable found');
62
function ExecuteSvnCommand(const Command: string; Output: TStream): integer;
66
function ReadOutput: boolean;
67
// returns true if output was actually read
71
Buffer: array[0..BufSize-1] of byte;
75
while SvnProcess.Output.NumBytesAvailable>0 do begin
76
ReadBytes := SvnProcess.Output.Read(Buffer, BufSize);
77
Output.Write(Buffer, ReadBytes);
82
function GetOutput: string;
84
SetLength(Result, Output.Size);
85
Output.Seek(0,soBeginning);
86
Output.Read(Result[1],Length(Result));
89
if SvnExecutable='' then InitializeSvnExecutable;
91
SvnProcess := TProcess.Create(nil);
93
SvnProcess.CommandLine := SvnExecutable + ' ' + Command;
94
SvnProcess.Options := [poUsePipes];
95
SvnProcess.ShowWindow := swoHIDE;
97
while SvnProcess.Running do begin
98
if not ReadOutput then
102
Result := SvnProcess.ExitStatus;
103
if Result<>0 then begin
104
Raise Exception.CreateFmt(
105
'svn %s failed: Result %d' + LineEnding + '%s',
106
[Command, Result, GetOutput]);
113
function ExecuteSvnCommand(const Command: string): integer;
115
Output: TMemoryStream;
117
Output := TMemoryStream.Create;
119
Result := ExecuteSvnCommand(Command, Output);
125
procedure DumpStream(const AStream: TStream);
129
lines := TStringList.Create;
130
AStream.Position := 0;
131
lines.LoadFromStream(AStream);