Changeset 3


Ignore:
Timestamp:
Mar 2, 2022, 1:22:13 PM (2 years ago)
Author:
chronos
Message:
  • Fixed: Restore zeroed pristine files using svn export from repository.
  • Added: Automated validity tests.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/SVNZero.lpi

    r1 r3  
    7575        <IsPartOfProject Value="True"/>
    7676      </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>
    7785    </Units>
    7886  </ProjectOptions>
  • trunk/SVNZero.lpr

    r1 r3  
    77  cthreads,
    88  {$ENDIF}
    9   Classes, SysUtils, CustApp, USubversion
     9  Classes, SysUtils, CustApp, USubversion, UTest, USvnZero
    1010  { you can add units after this };
    1111
    1212type
    1313
    14   { TSvnZero }
     14  { TSvnZeroApp }
    1515
    16   TSvnZero = class(TCustomApplication)
     16  TSvnZeroApp = class(TCustomApplication)
    1717  protected
    1818    procedure DoRun; override;
    19     function CheckErrorOutput(Text: string): Boolean;
     19  private
     20    procedure NormalRun;
    2021  public
    21     Subversion: TSubversion;
     22    SvnZero: TSvnZero;
    2223    constructor Create(TheOwner: TComponent); override;
    2324    destructor Destroy; override;
     
    2728{ TSvnZero }
    2829
    29 procedure TSvnZero.DoRun;
    30 var
    31   StandardOutput: string;
    32   Params: array of string;
    33   I: Integer;
     30procedure TSvnZeroApp.DoRun;
    3431begin
    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;
    4541  end;
    46   if StandardOutput <>'' then Write(StandardOutput);
    47   if Subversion.ErrorOutput <>'' then Write(Subversion.ErrorOutput);
    48   Subversion.ZeroPristine;
    4942
    5043(*  // quick check parameters
     
    6255    Exit;
    6356  end;
    64 
    65   { add your program here }
    6657 *)
    6758
     
    7061end;
    7162
    72 function TSvnZero.CheckErrorOutput(Text: string): Boolean;
     63procedure TSvnZeroApp.NormalRun;
    7364var
    74   FileName: string;
     65  Params: TStringArray;
    7566  I: Integer;
    7667begin
    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);
    8572
    86       Subversion.Execute(['-r', '0', 'update', FileName]);
    87       Subversion.Execute(['cleanup']);
    88       Result := True;
    89     end;
    90   end;
     73  SVNZero.ExecuteOutput(Params);
    9174end;
    9275
    93 constructor TSvnZero.Create(TheOwner: TComponent);
     76constructor TSvnZeroApp.Create(TheOwner: TComponent);
    9477begin
    9578  inherited;
    9679  StopOnException := True;
    97   Subversion := TSubversion.Create;
     80  SvnZero := TSvnZero.Create;
    9881end;
    9982
    100 destructor TSvnZero.Destroy;
     83destructor TSvnZeroApp.Destroy;
    10184begin
    102   FreeAndNil(Subversion);
     85  FreeAndNil(SvnZero);
    10386  inherited;
    10487end;
    10588
    106 procedure TSvnZero.WriteHelp;
     89procedure TSvnZeroApp.WriteHelp;
    10790begin
    10891  { add your help code here }
    109   writeln('Usage: ', ExeName, ' -h');
     92  WriteLn('Usage: ', ExeName, ' -h');
    11093end;
    11194
     
    11699
    117100var
    118   Application: TSvnZero;
     101  Application: TSvnZeroApp;
    119102begin
    120103  {$if declared(UseHeapTrace)}
     
    123106  {$ENDIF}
    124107
    125   Application := TSvnZero.Create(nil);
     108  Application := TSvnZeroApp.Create(nil);
    126109  Application.Title := 'SVN Zero';
    127110  Application.Run;
  • trunk/USubversion.pas

    r1 r3  
    1111type
    1212
    13   { TSubversion }
     13  { TExecute }
    1414
    15   TSubversion = class
    16   private
    17     function GetExecutable: string;
    18     procedure MakeFileWriteable(FileName: string);
     15  TExecute = class
     16  protected
     17    function GetExecutable: string; virtual;
    1918  public
    2019    StandardOutput: string;
    2120    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);
    2423  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
     42procedure MakeFileWriteable(FileName: string);
    2543
    2644implementation
    2745
    28 { TSubversion }
     46{ TExecute }
    2947
    30 function TSubversion.GetExecutable: string;
     48function TExecute.GetExecutable: string;
    3149begin
    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 := '';
    4051end;
    4152
    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);
     53procedure TExecute.Execute(Parameters: array of string);
    9654var
    9755  Process: TProcess;
     
    13290end;
    13391
     92procedure TExecute.ExecuteOutput(Parameters: array of string);
     93begin
     94  Execute(Parameters);
     95  if StandardOutput <> '' then Write(StandardOutput);
     96  if ErrorOutput <> '' then Write(ErrorOutput);
     97end;
     98
     99{ TSubversionAdmin }
     100
     101function TSubversionAdmin.GetExecutable: string;
     102begin
     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}
     111end;
     112
     113{ TSubversion }
     114
     115function TSubversion.GetExecutable: string;
     116begin
     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}
     125end;
     126
     127procedure MakeFileWriteable(FileName: string);
     128var
     129  {$IFDEF WINDOWS}
     130  FileAttributes: Integer;
     131  {$ENDIF}
     132  {$IFDEF UNIX}
     133  FileStat: stat;
     134  {$ENDIF}
     135begin
     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}
     147end;
     148
    134149end.
    135150
Note: See TracChangeset for help on using the changeset viewer.