#!/usr/bin/perl -w # # Visual SourceSafe to Perforce converter, top level wrapper (calls all other scripts) # # Copyright 1998 Perforce Software. All rights reserved. # Written by James Strickland, April 1998 # Maintained by Robert Cowham, since 2000 # # $Id: //guest/ashish_melanta/perforce/utils/vsstop4/main/convert.pl#1 $ # require 5.0; use strict; use lib '.'; $| = 1; # don't buffer output use convert; use utils; unlink("sumlogfile.log"); convert::log("START=======================================\n"); print_status("Starting run. " . scalar(localtime()) . "\n"); print_status("Script version: " . read_version() . "\n"); print_status("Perl version: " . $] . "\n"); if (!defined($ENV{'SSDIR'})) { print "The environment variable SSDIR must be defined!\n"; exit(1); } # Check for P4 module installed and get a new object my $p4 = utils::p4api; # Check for parameter to avoid asking questions my $confirm = shift(@ARGV); $confirm = "" if (!defined($confirm)); $p4->SetPort($convert::p4port); $p4->SetClient($convert::p4client); $p4->SetUser($convert::p4user); $p4->Connect() or die( "Failed to connect to Perforce Server: $convert::p4port $!\n" ); my $p4form = utils::p4api; $p4form->SetPort($convert::p4port); $p4form->SetClient($convert::p4client); $p4form->SetUser($convert::p4user); $p4form->ParseForms(); $p4form->Connect() or die( "Failed to connect to Perforce Server: $convert::p4port $!\n" ); # check that p4 is operational, warn if version does not support -f print "Running p4 info.\n"; my $p4info = utils::p4exec($p4, "info"); convert::log($p4info); # note: p4 info prints errors to stderr, so we deduce an error from the lack # of output saying anything about the server if( $p4info !~ m@server@si) { print "\np4 info returned an error which must be fixed before proceeding. Check the installation section of the Perforce manual. Most likely you haven't started a Perforce server or you haven't set P4PORT to point to the server. You can obtain Perforce documentation from http://www.perforce.com\n\n"; print "Here's what p4 info returned:\n$p4info" if($p4info); exit(1); } if( $p4info =~ m@\nServer version:\s+[^\s]+/([0-9]+) @s) { my $change_number = $1; my $magic_number = 4761; # first release of 97.3 if( $change_number < $magic_number ) { print "Detected Perforce server version with change number $change_number. The VSS converter requires a 97.3 or later server. You can download Perforce from http://www.perforce.com/\n"; exit(2); } } else { # Server version line not recognized print "The Perforce server version was not detected - either you have a really old version (you can get the latest version from http://www.perforce.com) or the format of the output of p4 info has changed and no one updated this script to match (in which case, we'd appreciate it if you let us know - send email to support\@perforce.com). The VSS converter requires a 97.3 or later server. You can download Perforce from http://www.perforce.com/ "; if ($confirm !~ /\-[yY]/) { print "Do you wish to proceed with your existing server? (y/n) "; exit(3) if(<STDIN> !~ /y/); } } utils::log_ss_version; # check that the depot is empty print "Checking that the repository is empty.\n"; if(utils::p4exec($p4, "changes -m 1", 1) || utils::p4exec($p4, "labels", 1)) { my $port = $p4info; $port =~ s@.*\nServer address:\s*(\S+).*@$1@s; print "The Perforce repository stored by the server at '$port' is not empty! Running this import process will import changes with earlier timestamps than existing changes in the repository. Be careful!! "; if ($confirm !~ /-[yY]/) { print "Are you sure you want to proceed? "; exit(4) if(<STDIN> !~ /y/); } } # Check if we are being asked to ignore changes - dangerous!! if($convert::start_time != 0) { print "************* WARNING You have specified a start_time before which to ignore changelists. This is potentially dangerous because if you have not correctly specified the time stamp, you will get duplicate changelists! "; print "Are you sure you want to proceed? "; exit(4) if(<STDIN> !~ /y/); } # Check that the user has superuser or admin protections if(!utils::p4exec($p4, "protect -o", 0)) { print "You do not have superuser permissions for this Perforce repository. The converter updates the date and time on imported changelists which requires superuser or administrator permissions. "; print "Are you sure you want to proceed? "; exit(4) if(<STDIN> !~ /y/); } # Timestamp print_status("Conversion started " . scalar(localtime()) . "\n"); # set up user name and client $ENV{P4PORT} = $convert::p4port; $ENV{P4USER} = $convert::p4user; $ENV{P4CLIENT} = $convert::p4client; print_status("\nUsing port/client/user '$ENV{P4PORT}/$ENV{P4CLIENT}/$ENV{P4USER}'.\n\n"); my $client_view = "//$convert::depot/$convert::depot_root... //$ENV{P4CLIENT}/$convert::depot_root...\n"; print_status("...creating/updating client $ENV{P4CLIENT} with:\n"); print_status(" root $convert::client_root.\n"); print_status(" view $client_view\n"); # Update the root and view my $form = $p4form->FetchClient($ENV{P4CLIENT}); my @view; push @view, $client_view; $form->{"Root"} = $convert::client_root; $form->{'View'} = \@view; my @result = $p4form->SaveClient($form); convert::log("Client update:\n".join("\n", @result)); utils::p4errors_print($p4form, "Updating client ".$ENV{P4CLIENT}, 1); # check no opened files... print_status("Checking for no opened files.\n"); if(utils::p4exec($p4, "opened", 1)) { print "************************** ERROR You have a variety of opened files in the client workspace - conversion cannot proceed. Please revert them (in workspace $convert::p4client) and try again: "; print utils::p4exec($p4, "opened"); exit(4); } if ($convert::bypass_metadata) { # If a bypass is requested, verify that the files are there. $convert::bypass_metadata = -f "$convert::metadata_dir/files" && -f "$convert::metadata_dir/labels_summary" && -f "$convert::metadata_dir/changes"; } if ($convert::bypass_metadata) { print "BYPASSING the re-creation of the metadata/ files.\n"; } else { print_status("Extracting metadata... " . scalar(localtime()) . "\n"); print_status("...from all VSS projects at and below $convert::root\n"); print_status("...in VSS Repository $ENV{'SSDIR'}\n\n"); runcmd("perl readhist.pl"); # Sort the metadata print_status("Sorting the metadata. " . scalar(localtime()) . "\n"); runcmd("perl sortmeta.pl"); # Improve the metadata - group changes, etc. print_status("Improving the metadata. " . scalar(localtime()) . "\n"); runcmd("perl improve.pl"); } # And now, what you've all been waiting for.. print_status("Creating the Perforce depot. " . scalar(localtime()) . "\n"); runcmd("perl mkdepot.pl"); # Some post-processing print_status("Sorting the mapping file. " . scalar(localtime()) . "\n"); runcmd("perl sortmap.pl"); # Verification step if ($convert::perform_verify) { print_status("\nVerifying the result. " . scalar(localtime()) . "\n"); runcmd("perl verify.pl"); } # Timestamp print_status("Conversion finished " . scalar(localtime()) . "\n"); exit(0); sub runcmd { my $cmd = shift; my $result = system($cmd); if ($result) { die "***** Failed to run command: $cmd\n"; } } sub print_status { my $msg = shift; print $msg; convert::log($msg); convert::sum_log($msg); } sub read_version { my $version = open(INPUT, "< CHANGELOG.txt") or die "Couldn't open CHANGELOG.txt for reading: $!\n"; while (<INPUT>) { if (/\$Id/) { $version = $_; last; } } close(INPUT); return $version; } #eof
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5974 | Ashish Melanta | Pulling in the Perforce utils into my guest branch | ||
//guest/perforce_software/utils/vsstop4/main/convert.pl | |||||
#16 | 5860 | Robert Cowham | - Improved logging slightly - new summary log file sumlogfile.log created | ||
#15 | 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 |
||
#14 | 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. |
||
#13 | 5315 | Robert Cowham |
- Output script version. Changed warning message. - Converted README.txt to README.html |
||
#12 | 5307 | Robert Cowham |
Fix problem with detecting open files. Print status stuff to log too. |
||
#11 | 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 |
||
#10 | 4024 | Robert Cowham | Make slightly more robust - ignore VSS prompts for input by using the -I- flag to commands. | ||
#9 | 4000 | Robert Cowham |
Remove changes for non-P4Perl version. Improved Web page with download links. |
||
#8 | 3926 | Robert Cowham | P4Perl is now required for the scripts to run. | ||
#7 | 3925 | Robert Cowham | Problems as per Michael Shields when not using P4Perl. | ||
#6 | 3639 | Robert Cowham |
Changed filetype and inserted ID string. Fixed typo. |
||
#5 | 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. |
||
#4 | 3558 | Robert Cowham |
Fixed bug with French date formats. Autoupdate client root and view based on config.ini entries. |
||
#3 | 3556 | Robert Cowham |
Added extra check on time stamp formats. Tidied up readme - will only run on Windows now. Updated comments in config.ini |
||
#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 |