#!/usr/bin/perl -w # # VSS to Perforce converter, phase III: construct Perforce depot # # Copyright 1998 Perforce Software. All rights reserved. # Written by James Strickland, April 1998 # # This script uses the metadata produced by earlier phases to direct a loop # which extracts VSS revisions and performs the required Perforce commands # to construct a Perforce depot corresponding to the (improved) VSS data. require 5.0; use strict; use integer; use lib '.'; use convert; use Change; # open all our input files my $msg="can't open for read"; open(FILES, "<$convert::metadata_dir/files") or die $msg; open(LABELS, "<$convert::metadata_dir/labels") or die $msg; open(CHANGES, "<$convert::metadata_dir/changes") or die $msg; open(MAPPING, ">$convert::metadata_dir/mapping.ns") or die "can't open for write: $!"; # variables to be initialized with metadata read from files my (%file_type, # maps archive -> file type # e.g. "$/foo" -> "text" %labels, # maps "revision archive" -> list of labels # e.g. "1 $/foo" -> "itworks","bobsyouruncle" %filesinlabel, # maps label name -> list of "file#rev" %added, # maps depot file -> true/false # e.g. "//depot/foo" -> 1 ); # initialize %file_type while(<FILES>) { chomp; my ($file_type,$file) = split(/ /,$_,2); $file_type{$file} = $file_type; } close(FILES); # initialize %label and run p4 label once for each label which is not a # "delete" label my %created; while(<LABELS>) { chomp; my ($revision,$label,$file) = split(/ /,$_,3); my $index = "$revision $file"; $labels{$index} = defined($labels{$index}) ? [ @{$labels{$index}} , $label ] : [ $label ]; my $comment = ''; $comment .= <LABELS> while ($comment !~ /\*{10}\n/); $comment =~ s/\*{10}\n$//; next if($created{$label}); my $form=convert::run("p4 label -o $label"); # label names cannot contain spaces $comment =~ s@\n@\n\t@gs; $form =~ s@(\nDescription:\s*)\n\s+\S[^\n]*\n@$1\n\t$comment@s; convert::run("p4 label -i",$form); $created{$label}=1; } close(LABELS); undef %created; # we're finished with this hash, so free up the space # print timestamp print "Depot creation started " . scalar(localtime()) . "\n"; # For each change, # - retrieve revisions from VSS using 'get' # - mark files as added or edited with 'p4 add' or 'p4 edit', # followed by 'p4 submit' # - update list of file#rev associated with any pertinent labels my ($c,$op); while( $c = get Change(\*CHANGES) ) { my ($change_number,@checkins); my $index; foreach $index (@{$c->changelist}) { my $p4rev; my ($revision,$vss_file) = split(/ /,$index,2); my ($client_rel_dir,$client_file) = convert::p4dir_and_file( $vss_file); my $client_dir = convert::join_paths( $convert::client_root, $client_rel_dir ); # create all needed directories on the path convert::emkdir($client_dir); # for p4 - could use $client_file, but I'd rather make sure we use # the same string that's written out to the mapping file my $depot_file = convert::join_paths("//depot", $client_rel_dir, $client_file ); # get the file from VSS convert::get_vss_file($vss_file,($file_type{$vss_file} eq "tempobj") ? "" : $revision,$client_dir,$client_file); # see if the file is indeed there now if (-f "${client_dir}/${client_file}") { # schedule p4 add or edit operation # depending on whether file has already been added push(@checkins, [ $vss_file,$revision,$depot_file ] ); my $operation; if($added{$depot_file}) { convert::run("p4 edit \"$depot_file\"") =~ /#(\d+) - opened for edit/ or die "p4 edit $depot_file failed"; $p4rev=$1 +1; } else { convert::run("p4 add -t $file_type{$vss_file} \"$depot_file\"") =~ /opened for add/ or die "p4 add $depot_file failed"; $added{$depot_file}=1; $p4rev=1; } # check if this revision is labelled if(exists($labels{$index})) { for (@{$labels{$index}}) { $filesinlabel{$_} = defined($filesinlabel{$_}) ? [ @{$filesinlabel{$_}} , "$depot_file#$p4rev" ] : [ "$depot_file#$p4rev" ]; } } } else { # the file isn't there - the ss get failed if ($convert::skip_ss_get_errors) { print STDERR "ERROR: VSS file not found: ${vss_file}#${revision}\n"; } else { die "get_vss_file() revision $revision to $client_dir/$client_file failed"; } } } # submit the change, and write out the association between VSS # archive and revision number and Perforce file and change number $change_number = $c->submit; # submit the change my $checkin; foreach $checkin (@checkins) { my ($vss_file,$r,$depot_filename) = @$checkin; # write change number#filename to avoid confusion with filename#revision print MAPPING "$r#$change_number#$depot_filename#$vss_file\n"; # NOTE: $vss_file has to go last since it can contain # characters } } # now do the labelling for (keys(%filesinlabel)) { convert::run("p4 -x - labelsync -l $_",join("\n",@{$filesinlabel{$_}})."\n"); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#31 | 16012 | Robert Cowham | Rename/move project to conform to new Workshop naming structure. | ||
#30 | 12422 | Robert Cowham | - Handle workspace with option revertunchanged. | ||
#29 | 6404 | Robert Cowham |
- Convert to official P4Perl - Avoid appending to logfile.log - Tidy up label markers - Remove name clash on p4exec function |
||
#28 | 6326 | Robert Cowham | - Change label end of comment marker from 10 asterisks to avoid problems | ||
#27 | 6244 | Robert Cowham |
- Merge in changes to cope with previously illegal chars in filenames %, *, #, @ (requires 2004.2 server and above) |
||
#26 | 6241 | Robert Cowham |
- Removed unused module Date::Dump - Updated docs to refer to right version of P4Perl |
||
#25 | 5860 | Robert Cowham | - Improved logging slightly - new summary log file sumlogfile.log created | ||
#24 | 5802 | Robert Cowham | - Set P4Perl API level to 57 (2005.1) to avoid future incompatibilities. | ||
#23 | 5689 | Robert Cowham | - Fix bug where non-windows servers not recognised as a result of previous change. | ||
#22 | 5682 | Robert Cowham | Remove use of DB_File module as seems unreliable. | ||
#21 | 5681 | Robert Cowham |
- Fix compatibility problem with 2005.1 server - Added tests for all servers back to 2003.2 - Log more info about options used - Clarify the vss_user/password rather than put in ss_options |
||
#20 | 5652 | Robert Cowham |
- Add more troubleshooting help to readme.html. - Update to use P4Perl 3.5313 - Added new module utils.pm to detect and fail if wrong P4Perl version used. |
||
#19 | 5306 | Robert Cowham |
- Minor fix of error handling for non-scalar values - allow for depot_root to be empty - change convert.pl to use P4Perl only |
||
#18 | 5302 | Robert Cowham | Fix error handling for some circumstances | ||
#17 | 5075 | Robert Cowham |
- Use ->Connect() rather than Init() (version 3.4804 of the released P4Perl). - Add troubleshooting help. |
||
#16 | 4936 | Robert Cowham | Be specific about version of P4Perl to use | ||
#15 | 4641 | Robert Cowham | Updated to cope with changes to P4Perl - call MergeErrors when setting up. | ||
#14 | 4389 | Robert Cowham | - Remove unused code for not using P4Perl in mkdepot.pl | ||
#13 | 4387 | Robert Cowham | Move label file writing outside submit loop to improve speed. | ||
#12 | 4213 | Robert Cowham |
Make more robust when dealing with errors. Output progress when reading VSS history. |
||
#11 | 3926 | Robert Cowham | P4Perl is now required for the scripts to run. | ||
#10 | 3925 | Robert Cowham | Problems as per Michael Shields when not using P4Perl. | ||
#9 | 3919 | Robert Cowham | Fix problem with labels when DB_File not used. | ||
#8 | 3891 | Robert Cowham | Fixed problem with restart capability and p4perl combo not working. | ||
#7 | 3878 | Robert Cowham | Ooops - missing eval when looking for p4.pm ! | ||
#6 | 3797 | Robert Cowham |
Remove warnings. Trim whitespace from ends of lines in config.ini entries |
||
#5 | 3795 | Robert Cowham | Avoid warnings (and work with Perl 5.8). | ||
#4 | 3639 | Robert Cowham |
Changed filetype and inserted ID string. Fixed typo. |
||
#3 | 3609 | Robert Cowham |
Integrate in changes for: - Use of DB_File for large hashes (if available) - Reworking of label algorithm - MUCH faster - Use of P4Perl (if available) - much faster - Use of VSS OLE Automation (if available) - sometimes faster See README.txt and Performance section for details. |
||
#2 | 2165 | Robert Cowham | Merged in changes from Guest branch | ||
#1 | 2160 | Robert Cowham | Main version from .zip file from http://www.perforce.com/perforce/loadsupp.html#conv page |