Changeset 3
- Timestamp:
- Mar 2, 2022, 1:22:13 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SVNZero.lpi
r1 r3 75 75 <IsPartOfProject Value="True"/> 76 76 </Unit> 77 <Unit> 78 <Filename Value="UTest.pas"/> 79 <IsPartOfProject Value="True"/> 80 </Unit> 81 <Unit> 82 <Filename Value="USvnZero.pas"/> 83 <IsPartOfProject Value="True"/> 84 </Unit> 77 85 </Units> 78 86 </ProjectOptions> -
trunk/SVNZero.lpr
r1 r3 7 7 cthreads, 8 8 {$ENDIF} 9 Classes, SysUtils, CustApp, USubversion 9 Classes, SysUtils, CustApp, USubversion, UTest, USvnZero 10 10 { you can add units after this }; 11 11 12 12 type 13 13 14 { TSvnZero }14 { TSvnZeroApp } 15 15 16 TSvnZero = class(TCustomApplication)16 TSvnZeroApp = class(TCustomApplication) 17 17 protected 18 18 procedure DoRun; override; 19 function CheckErrorOutput(Text: string): Boolean; 19 private 20 procedure NormalRun; 20 21 public 21 S ubversion: TSubversion;22 SvnZero: TSvnZero; 22 23 constructor Create(TheOwner: TComponent); override; 23 24 destructor Destroy; override; … … 27 28 { TSvnZero } 28 29 29 procedure TSvnZero.DoRun; 30 var 31 StandardOutput: string; 32 Params: array of string; 33 I: Integer; 30 procedure TSvnZeroApp.DoRun; 34 31 begin 35 StandardOutput := ''; 36 SetLength(Params, ParamCount); 37 for I := 0 to ParamCount - 1 do 38 Params[I] := GetParams(I + 1); 39 40 while True do begin 41 Subversion.Execute(Params); 42 StandardOutput := StandardOutput + Subversion.StandardOutput; 43 if CheckErrorOutput(Subversion.ErrorOutput) then begin 44 end else Break; 32 if HasOption('t', 'test') then begin 33 with TTest.Create do 34 try 35 Run; 36 finally 37 Free; 38 end; 39 end else begin 40 NormalRun; 45 41 end; 46 if StandardOutput <>'' then Write(StandardOutput);47 if Subversion.ErrorOutput <>'' then Write(Subversion.ErrorOutput);48 Subversion.ZeroPristine;49 42 50 43 (* // quick check parameters … … 62 55 Exit; 63 56 end; 64 65 { add your program here }66 57 *) 67 58 … … 70 61 end; 71 62 72 function TSvnZero.CheckErrorOutput(Text: string): Boolean;63 procedure TSvnZeroApp.NormalRun; 73 64 var 74 FileName: string;65 Params: TStringArray; 75 66 I: Integer; 76 67 begin 77 Result := False; 78 if Pos(': Checksum mismatch', Text) > 0 then begin 79 I := Pos('''', Text); 80 if I > 0 then begin 81 FileName := Copy(Text, I + 1, MaxInt); 82 I := Pos('''', FileName); 83 if I > 0 then 84 Delete(FileName, I, MaxInt); 68 Params := Default(TStringArray); 69 SetLength(Params, ParamCount); 70 for I := 0 to ParamCount - 1 do 71 Params[I] := GetParams(I + 1); 85 72 86 Subversion.Execute(['-r', '0', 'update', FileName]); 87 Subversion.Execute(['cleanup']); 88 Result := True; 89 end; 90 end; 73 SVNZero.ExecuteOutput(Params); 91 74 end; 92 75 93 constructor TSvnZero .Create(TheOwner: TComponent);76 constructor TSvnZeroApp.Create(TheOwner: TComponent); 94 77 begin 95 78 inherited; 96 79 StopOnException := True; 97 S ubversion := TSubversion.Create;80 SvnZero := TSvnZero.Create; 98 81 end; 99 82 100 destructor TSvnZero .Destroy;83 destructor TSvnZeroApp.Destroy; 101 84 begin 102 FreeAndNil(S ubversion);85 FreeAndNil(SvnZero); 103 86 inherited; 104 87 end; 105 88 106 procedure TSvnZero .WriteHelp;89 procedure TSvnZeroApp.WriteHelp; 107 90 begin 108 91 { add your help code here } 109 writeln('Usage: ', ExeName, ' -h');92 WriteLn('Usage: ', ExeName, ' -h'); 110 93 end; 111 94 … … 116 99 117 100 var 118 Application: TSvnZero ;101 Application: TSvnZeroApp; 119 102 begin 120 103 {$if declared(UseHeapTrace)} … … 123 106 {$ENDIF} 124 107 125 Application := TSvnZero .Create(nil);108 Application := TSvnZeroApp.Create(nil); 126 109 Application.Title := 'SVN Zero'; 127 110 Application.Run; -
trunk/USubversion.pas
r1 r3 11 11 type 12 12 13 { T Subversion}13 { TExecute } 14 14 15 TSubversion = class 16 private 17 function GetExecutable: string; 18 procedure MakeFileWriteable(FileName: string); 15 TExecute = class 16 protected 17 function GetExecutable: string; virtual; 19 18 public 20 19 StandardOutput: string; 21 20 ErrorOutput: string; 22 procedure ZeroPristine;23 procedure Execute (Parameters: array of string);21 procedure Execute(Parameters: array of string); virtual; 22 procedure ExecuteOutput(Parameters: array of string); 24 23 end; 24 25 { TSubversion } 26 27 TSubversion = class(TExecute) 28 private 29 protected 30 function GetExecutable: string; override; 31 public 32 end; 33 34 { TSubversionAdmin } 35 36 TSubversionAdmin = class(TExecute) 37 protected 38 function GetExecutable: string; override; 39 public 40 end; 41 42 procedure MakeFileWriteable(FileName: string); 25 43 26 44 implementation 27 45 28 { T Subversion}46 { TExecute } 29 47 30 function T Subversion.GetExecutable: string;48 function TExecute.GetExecutable: string; 31 49 begin 32 {$IFDEF UNIX} 33 Result := '/usr/bin/svn'; 34 {$ENDIF} 35 {$IFDEF WINDOWS} 36 Result := 'c:\Program Files\Subversion\bin\svn.exe'; 37 if not FileExists(Result) then 38 Result := 'C:\Program Files\TortoiseSVN\bin\svn.exe'; 39 {$ENDIF} 50 Result := ''; 40 51 end; 41 52 42 procedure TSubversion.MakeFileWriteable(FileName: string); 43 var 44 {$IFDEF WINDOWS} 45 FileAttributes: Integer; 46 {$ENDIF} 47 {$IFDEF UNIX} 48 FileStat: stat; 49 Mode: TMode; 50 {$ENDIF} 51 begin 52 {$IFDEF WINDOWS} 53 FileAttributes := FileGetAttr(FileName); 54 if (FileAttributes and faReadOnly) > 0 then 55 FileSetAttr(FileName, FileAttributes xor faReadOnly); 56 {$ENDIF} 57 {$IFDEF UNIX} 58 fpstat(FileName, FileStat); 59 if (FileStat.st_mode and 200) = 0 then 60 fpchmod(FileName, FileStat.st_mode or 200); 61 {$ENDIF} 62 end; 63 64 procedure TSubversion.ZeroPristine; 65 var 66 Files: TStrings; 67 I: Integer; 68 Empty: TStringList; 69 Dir: string; 70 FileName: string; 71 begin 72 Empty := TStringList.Create; 73 try 74 Dir := GetCurrentDir + DirectorySeparator + '.svn' + 75 DirectorySeparator + 'pristine'; 76 if DirectoryExists(Dir) then 77 try 78 Files := FindAllFiles(Dir, '*.svn-base'); 79 for I := 0 to Files.Count - 1 do begin 80 FileName := Files[I]; 81 if FileSize(FileName) > 0 then 82 begin 83 MakeFileWriteable(FileName); 84 Empty.SaveToFile(FileName); 85 end; 86 end; 87 finally 88 Files.Free; 89 end; 90 finally 91 Empty.Free; 92 end; 93 end; 94 95 procedure TSubversion.Execute(Parameters: array of string); 53 procedure TExecute.Execute(Parameters: array of string); 96 54 var 97 55 Process: TProcess; … … 132 90 end; 133 91 92 procedure TExecute.ExecuteOutput(Parameters: array of string); 93 begin 94 Execute(Parameters); 95 if StandardOutput <> '' then Write(StandardOutput); 96 if ErrorOutput <> '' then Write(ErrorOutput); 97 end; 98 99 { TSubversionAdmin } 100 101 function TSubversionAdmin.GetExecutable: string; 102 begin 103 {$IFDEF UNIX} 104 Result := '/usr/bin/svnadmin'; 105 {$ENDIF} 106 {$IFDEF WINDOWS} 107 Result := 'c:\Program Files\Subversion\bin\svnadmin.exe'; 108 if not FileExists(Result) then 109 Result := 'C:\Program Files\TortoiseSVN\bin\svnadmin.exe'; 110 {$ENDIF} 111 end; 112 113 { TSubversion } 114 115 function TSubversion.GetExecutable: string; 116 begin 117 {$IFDEF UNIX} 118 Result := '/usr/bin/svn'; 119 {$ENDIF} 120 {$IFDEF WINDOWS} 121 Result := 'c:\Program Files\Subversion\bin\svn.exe'; 122 if not FileExists(Result) then 123 Result := 'C:\Program Files\TortoiseSVN\bin\svn.exe'; 124 {$ENDIF} 125 end; 126 127 procedure MakeFileWriteable(FileName: string); 128 var 129 {$IFDEF WINDOWS} 130 FileAttributes: Integer; 131 {$ENDIF} 132 {$IFDEF UNIX} 133 FileStat: stat; 134 {$ENDIF} 135 begin 136 {$IFDEF WINDOWS} 137 FileAttributes := FileGetAttr(FileName); 138 if (FileAttributes and faReadOnly) > 0 then 139 FileSetAttr(FileName, FileAttributes xor faReadOnly); 140 {$ENDIF} 141 {$IFDEF UNIX} 142 FileStat := default(stat); 143 fpstat(FileName, FileStat); 144 if (FileStat.st_mode and 200) = 0 then 145 fpchmod(FileName, FileStat.st_mode or 200); 146 {$ENDIF} 147 end; 148 134 149 end. 135 150
Note:
See TracChangeset
for help on using the changeset viewer.