Changeset 11


Ignore:
Timestamp:
Nov 2, 2022, 12:00:09 AM (2 years ago)
Author:
chronos
Message:
  • Modified: Remove pristine files instead of zero their content.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33svnzero.dbg
        44SVNZero.lps
         5SVNZero.res
        56heaptrclog.trc
        67Languages/*.mo
  • trunk/Install/deb/debian/control

    r9 r11  
    99Package: svnzero
    1010Architecture: any
    11 Depends: ${shlibs:Depends}, ${misc:Depends}, libsqlite3
     11Depends: ${shlibs:Depends}, ${misc:Depends}, libsqlite3-0
    1212Description: Subversion zero pristine wrapper.
    1313HomePage: https://app.zdechov.net/svnzero
  • trunk/SVNZero.lpr

    r10 r11  
    4343      AddNew('Delete update', TTestCaseDeleteUpdate);
    4444      AddNew('Delete update duplicate files', TTestCaseDeleteUpdateDuplicateFiles);
     45
    4546      for I := 0 to Count - 1 do
    4647      if Items[I] is TTestCaseSvn then begin
  • trunk/USvnZero.pas

    r9 r11  
    44
    55uses
    6   Classes, SysUtils, FileUtil, USubversion;
     6  Classes, SysUtils, FileUtil, USubversion, UCommon;
    77
    88type
     
    1818    function CheckErrorOutput(Text: string): Boolean;
    1919    function GetFileInfoByMd5(Md5Hash: string): TSubversionInfo;
     20    function GetFileInfoBySha1(Sha1Hash: string): TSubversionInfo;
    2021    procedure ZeroPristine;
    2122    procedure RestorePristine;
     
    4849  Files: TStrings;
    4950  I: Integer;
    50   Empty: TStringList;
    5151  Dir: string;
    5252  FileName: string;
     
    5454begin
    5555  ZeroedFilesCount := 0;
    56   Empty := TStringList.Create;
     56  Dir := GetPristineDir('.');
     57  if DirectoryExists(Dir) then
    5758  try
    58     Dir := GetPristineDir('.');
    59     if DirectoryExists(Dir) then
    60     try
    61       Files := FindAllFiles(Dir, '*' + SvnBaseExt);
    62       for I := 0 to Files.Count - 1 do begin
    63         FileName := Files[I];
    64         if FileSize(FileName) > 0 then
    65         begin
    66           MakeFileWriteable(FileName);
    67           Empty.SaveToFile(FileName);
    68           Inc(ZeroedFilesCount);
    69         end;
    70       end;
    71     finally
    72       Files.Free;
     59    Files := FindAllFiles(Dir, '*' + SvnBaseExt);
     60    for I := 0 to Files.Count - 1 do begin
     61      FileName := Files[I];
     62      DeleteFile(FileName);
     63      MakeFileWriteable(FileName);
     64      Inc(ZeroedFilesCount);
    7365    end;
    7466  finally
    75     Empty.Free;
     67    Files.Free;
    7668  end;
    7769  //StandardOutput := StandardOutput + Format(SZeroedFilesCount, [ZeroedFilesCount]) + LineEnding;
     
    183175  Info: TSubversionInfo;
    184176  Md5Hash: string;
     177  Sha1Hash: string;
    185178const
    186179  StartText = 'expected:';
     180  StartText2 = 'svn: E000002: Can''t open file ''';
    187181begin
    188182  Result := False;
    189   if Pos(': Checksum mismatch', Text) > 0 then begin
     183  I := Pos(StartText2, Text);
     184  if I > 0 then begin
     185    Sha1Hash := Copy(Text, I + Length(StartText2), MaxInt);
     186    I := Pos('.svn-base', Sha1Hash);
     187    if I > 0 then
     188      Delete(Sha1Hash, I, MaxInt);
     189    I := LastPos(DirectorySeparator, Sha1Hash);
     190    if I > 0 then
     191      Delete(Sha1Hash, 1, I);
     192
     193    Info := GetFileInfoBySha1(Sha1Hash);
     194    ExportedFileName := GetSvnDir('.') + DirectorySeparator + 'tmp' +
     195      DirectorySeparator + 'ExportedFile.bin';
     196    PristineFileName := GetPristineDir('.') + DirectorySeparator + Copy(Info.Checksum, 1, 2) +
     197      DirectorySeparator + Info.Checksum + '.svn-base';
     198    Subversion.Execute(['export', '-r', Info.Revision, '--force', Info.URL, ExportedFileName]);
     199    MakeFileWriteable(PristineFileName);
     200    CopyFile(ExportedFileName, PristineFileName);
     201    Subversion.Execute(['cleanup']);
     202    Result := True;
     203  end;
     204
     205(*  if Pos(': Checksum mismatch', Text) > 0 then begin
    190206    I := Pos(StartText, Text);
    191207    if I > 0 then begin
     
    206222      Result := True;
    207223    end;
    208 
    209224 {   I := Pos('''', Text);
    210225    if I > 0 then begin
     
    228243    }
    229244  end;
     245*)
    230246end;
    231247
     
    273289end;
    274290
     291function TSvnZero.GetFileInfoBySha1(Sha1Hash: string): TSubversionInfo;
     292var
     293  Database: TSQLite3Database;
     294  Statement: TSQLite3Statement;
     295begin
     296  Database := TSQLite3Database.Create;
     297  try
     298    Database.Open(GetSvnDir('.') + DirectorySeparator + 'wc.db');
     299    Result.Checksum := Sha1Hash;
     300
     301    Statement := Database.Prepare('SELECT repos_path,changed_revision FROM NODES WHERE checksum="$sha1$' + Result.Checksum + '" LIMIT 1');
     302    try
     303      while Statement.Step = SQLITE_ROW do begin
     304        Result.Path := Statement.ColumnText(0);
     305        Result.Revision := Statement.ColumnText(1);
     306      end;
     307    finally
     308      Statement.Free;
     309    end;
     310
     311    Statement := Database.Prepare('SELECT root FROM REPOSITORY LIMIT 1');
     312    try
     313      while Statement.Step = SQLITE_ROW do begin
     314        Result.URL := Statement.ColumnText(0) + '/' + Result.Path;
     315      end;
     316    finally
     317      Statement.Free;
     318    end;
     319
     320    if Result.Checksum.StartsWith('$sha1$') then
     321      Result.Checksum := Copy(Result.Checksum, 7);
     322  finally
     323    Database.Free;
     324  end;
     325end;
     326
    275327end.
    276328
Note: See TracChangeset for help on using the changeset viewer.