Changeset 3 for trunk/SVNZero.lpr


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

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.