Changeset 316

Show
Ignore:
Timestamp:
06/26/2007 07:02:16 PM
Author:
luedi
Message:

#51: correctly encode text files, if the "svn:eol-style" is set to "native"
#54: generate a new UUID for each Dumpfile.pm
#53: optionally generate MD5 checksums for "Text-content"
#55: detect and remove unnecessary UNPIN/PIN activities
#56: detect and remove temporary .NET checkins

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/script/Vss2Svn/Dumpfile.pm

    r312 r316  
    1111 
    1212use File::Copy; 
     13use Digest::MD5; 
     14use Data::UUID; 
    1315 
    1416our %gHandlers = 
     
    3234our %gDeleted = (); 
    3335our %gVersion = (); 
     36our $gTmpDir; 
     37 
     38############################################################################### 
     39#  SetTempDir 
     40############################################################################### 
     41sub SetTempDir { 
     42    my($class, $dir) = @_; 
     43 
     44    $gTmpDir = $dir; 
     45}  #  End SetTempDir 
    3446 
    3547############################################################################### 
     
    3749############################################################################### 
    3850sub new { 
    39     my($class, $fh, $autoprops) = @_; 
     51    my($class, $fh, $autoprops, $md5) = @_; 
    4052 
    4153    my $self = 
     
    4860         repository => Vss2Svn::Dumpfile::SanityChecker->new(), 
    4961         auto_props => $autoprops, 
     62         do_md5 => $md5, 
    5063        }; 
    5164 
     
    5871 
    5972    print $fh "SVN-fs-dump-format-version: 2\n\n"; 
     73     
     74    my $ug    = new Data::UUID; 
     75    my $uuid = $ug->to_string( $ug->create() ); 
     76     
     77    print $fh "UUID: $uuid\n\n"; 
    6078 
    6179    $self = bless($self, $class); 
     
    770788    } 
    771789 
     790    my $md5; 
     791    $md5 = Digest::MD5->new if $self->{do_md5}; 
     792 
     793    # convert CRLF -> LF before calculating the size and compute the md5 
     794    if(!defined $text && defined $file) { 
     795        my ($input, $output); 
     796        my $style = $props->{'svn:eol-style'}; 
     797        if (defined $style && $style eq 'native') { 
     798            open ($input, "<:crlf", $file); 
     799            my $tmpFile = "$gTmpDir/crlf_to_lf.tmp.txt"; 
     800            open ($output, ">", $tmpFile); 
     801            binmode ($output); 
     802 
     803            while(<$input>) { 
     804                $md5->add($_) if $self->{do_md5}; 
     805                print $output $_; 
     806            } 
     807             
     808            close $input; 
     809            close $output; 
     810            $file = $tmpFile; 
     811        } 
     812        else { 
     813            open ($input, "<", $file); 
     814            binmode ($input); 
     815            $md5->addfile($input) if $self->{do_md5}; 
     816            close $input;             
     817        } 
     818    } else { 
     819        $md5->add($text) if $self->{do_md5}; 
     820    }        
     821     
     822    my $digest = $md5->hexdigest if $self->{do_md5}; 
     823#    print "digest: $digest\n"; 
     824 
    772825    if(!defined $text && defined $file) { 
    773826        $textlen = -s $file; 
     
    783836    if ($textlen > 0) { 
    784837        print $fh "Text-content-length: $textlen\n"; 
     838        print $fh "Text-content-md5: $digest\n" if $self->{do_md5}; 
    785839    } 
    786840 
  • trunk/script/devnotes.txt

    r293 r316  
    1313Config::Ini 
    1414Text::Glob 
     15Digest::MD5 
     16Data::UUID 
    1517 
    1618SQLITE SCHEMA 
  • trunk/script/vss2svn.pl

    r315 r316  
    7171            # Merge data from move actions  
    7272            MERGEMOVEDATA => {handler => \&MergeMoveData, 
    73                                 next    => 'BUILDACTIONHIST'}, 
     73                                next    => 'REMOVETMPCHECKIN'}, 
     74 
     75            # Remove temporary check ins 
     76            REMOVETMPCHECKIN => {handler => \&RemoveTemporaryCheckIns, 
     77                                 next    => 'MERGEUNPINPIN'}, 
     78 
     79            # Remove unnecessary Unpin/pin activities 
     80            MERGEUNPINPIN => {handler => \&MergeUnpinPinData, 
     81                                 next    => 'BUILDACTIONHIST'}, 
    7482 
    7583            # Take the history of physical actions and convert them to VSS 
     
    774782 
    775783############################################################################### 
     784# RemoveTemporaryCheckIns 
     785# remove temporary checkins that where create to detect MS VSS capabilities 
     786############################################################################### 
     787sub RemoveTemporaryCheckIns { 
     788    my($sth, $rows, $row); 
     789    $sth = $gCfg{dbh}->prepare('SELECT * FROM PhysicalAction ' 
     790                               . 'WHERE comment = "Temporary file created by Visual Studio .NET to detect Microsoft Visual SourceSafe capabilities."' 
     791                               . '      AND actiontype = "ADD"' 
     792                               . '      AND itemtype = 2');             # only delete files, not projects 
     793    $sth->execute(); 
     794 
     795    # need to pull in all recs at once, since we'll be updating/deleting data 
     796    $rows = $sth->fetchall_arrayref( {} ); 
     797 
     798    foreach $row (@$rows) { 
     799        my $physname = $row->{physname}; 
     800         
     801        my $sql = 'SELECT * FROM PhysicalAction WHERE physname = ?'; 
     802        my $update = $gCfg{dbh}->prepare($sql); 
     803         
     804        $update->execute( $physname ); 
     805 
     806                    # need to pull in all recs at once, since we'll be updating/deleting data 
     807                    my $recs = $update->fetchall_arrayref( {} ); 
     808                 
     809                    foreach my $rec (@$recs) { 
     810          print "Remove action_id $rec->{action_id}, $rec->{physname}, $rec->{actiontype}, $rec->{itemname}\n"; 
     811          print "       $rec->{comment}\n" if defined ($rec->{comment}); 
     812          &DeleteChildRec($rec->{action_id}); 
     813        } 
     814                } 
     815 
     816    1; 
     817} 
     818 
     819############################################################################### 
     820#  MergeUnpinPinData 
     821############################################################################### 
     822sub MergeUnpinPinData { 
     823    my($sth, $rows, $row, $r, $next_row); 
     824    my $sql = 'SELECT * FROM PhysicalAction ORDER BY timestamp ASC, ' 
     825                . 'itemtype ASC, priority ASC, parentdata ASC, sortkey ASC, action_id ASC'; 
     826    $sth = $gCfg{dbh}->prepare($sql); 
     827    $sth->execute(); 
     828  
     829    # need to pull in all recs at once, since we'll be updating/deleting data 
     830    $rows = $sth->fetchall_arrayref( {} ); 
     831  
     832    return if ($rows == -1); 
     833    return if (@$rows < 2); 
     834  
     835    my @delchild = (); 
     836  
     837    for $r (0 .. @$rows-2) { 
     838        $row = $rows->[$r]; 
     839        $next_row = $rows->[$r+1]; 
     840         
     841        if ($row->{actiontype} eq 'PIN'  
     842            && !defined $row->{version}    # UNPIN 
     843            && $next_row->{actiontype} eq 'PIN'  
     844            && defined $next_row->{version}   # PIN 
     845            && $row->{physname} eq $next_row->{physname} 
     846            && $row->{parentphys} eq $next_row->{parentphys} 
     847            && $next_row->{timestamp} - $row->{timestamp} < 60 
     848            && $next_row->{action_id} - $row->{action_id} == 1) { 
     849                print "found UNPIN/PIN combination for $row->{parentphys}/$row->{physname}" 
     850                    . "($row->{itemname}) @ ID $row->{action_id}\n"  if $gCfg{verbose}; 
     851                push (@delchild, $row->{action_id}); 
     852            } 
     853          
     854    } 
     855  
     856    my $id; 
     857    foreach $id (@delchild) { 
     858        &DeleteChildRec($id); 
     859    } 
     860  
     861    1; 
     862  
     863}  #  End MergeUnpinPinData 
     864 
     865############################################################################### 
    776866#  DeleteChildRec 
    777867############################################################################### 
     
    9511041 
    9521042    my $autoprops = Vss2Svn::Dumpfile::AutoProps->new($gCfg{auto_props}) if $gCfg{auto_props}; 
    953     my $dumpfile = Vss2Svn::Dumpfile->new($fh, $autoprops); 
     1043    my $dumpfile = Vss2Svn::Dumpfile->new($fh, $autoprops, $gCfg{do_md5}); 
     1044    Vss2Svn::Dumpfile->SetTempDir($gCfg{tempdir}); 
    9541045 
    9551046REVISION: 
     
    10741165Dumpfile     : $gCfg{dumpfile} 
    10751166VSS Encoding : $gCfg{encoding} 
     1167Auto Props   : $gCfg{auto_props} 
     1168 
    10761169 
    10771170VSS2SVN ver  : $VERSION 
     
    17071800    GetOptions(\%gCfg,'vssdir=s','tempdir=s','dumpfile=s','resume','verbose', 
    17081801               'debug','timing+','task=s','revtimerange=i','ssphys=s', 
    1709                'encoding=s','trunkdir=s','auto_props=s'); 
     1802               'encoding=s','trunkdir=s','auto_props=s', 'md5'); 
    17101803 
    17111804    &GiveHelp("Must specify --vssdir") if !defined($gCfg{vssdir}); 
     
    18681961    --task <task>     : specify the task to resume; task is one of the following 
    18691962                        INIT, LOADVSSNAMES, FINDDBFILES, GETPHYSHIST, 
    1870                         MERGEPARENTDATA, BUILDACTIONHIST, IMPORTSVN 
     1963                        MERGEPARENTDATA, MERGEMOVEDATA, REMOVETMPCHECKIN,  
     1964                        MERGEUNPINPIN, BUILDACTIONHIST, IMPORTSVN 
    18711965 
    18721966    --verbose         : Print more info about the items being processed 
     
    18781972                        converted repository (default = "/") 
    18791973    --auto_props      : Specify an autoprops ini file to use, e.g. 
    1880                         --auto_props="c:/Dokumente und Einstellungen/user/Anwendungsdaten/Subversion/config"  
     1974                        --auto_props="c:/Dokumente und Einstellungen/user/Anwendungsdaten/Subversion/config" 
     1975    --md5             : generate md5 checksums 
    18811976EOTXT 
    18821977 

PumaCode.org recommends CVSDude for fast, professional Subversion and Trac hosting:

CVSDude.com

These ads are automatically generated by Google. Revenue from these ads helps to pay for hosting this site; however, these ads do not constitute an endorsement by PumaCode.org.