eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q'
if 0;
# THE PRECEEDING STUFF EXECS perl via $PATH
# -*-Fundamental-*-
# $Id: //depot/clients/atg/cvs2p4/main/bin/dbdump#2 $
#
# Richard Geiger
#
require 5.000;
use Carp; # ...or flounder. (This will fail unless 'perl' is a perl5!)
$| = 1;
($Myname = $0) =~ s%^.*/%%;
$Mydir = $0;
$Mydir = '../lib' unless ($Mydir =~ s#bin/[^/]*$#lib#);
require "$Mydir/util.pl";
sub usage
{
print <<_EOF_;
Usage: $Myname [ -c hints -v ] conversiondir
-c hints list the codelines to check for label revisions
-v increase the verbosity (can use multiple times)
-h print this message
_EOF_
exit $_[0];
}
sub verbose {
my $level = @_ > 1 ? shift : 1;
print @_, "\n" if $level <= $V;
}
# Parsing functions
sub find_match {
my ($cvsrev, $label, $realbr) = @_;
my $p4rev = '';
if ($HINTS{$label}) {
my $key = '';
for my $codeline (@{$HINTS{$label}}) {
$key = "$codeline$cvsrev";
$p4rev = $CVSREV{$key}, last if $CVSREV{$key};
}
if ($p4rev) {
verbose 2, "codeline match $key: $p4rev";
}
}
unless ($p4rev) {
$p4rev = $CVSREV{"$realbr$cvsrev"};
verbose 2, "literal match $realbr$cvsrev: $p4rev";
$NOGUESS{$label}->{"$realbr$cvsrev"} = $p4rev if $cfile;
}
die "no match found for $label $realbr $cvsrev\n" unless $p4rev;
return $p4rev;
}
sub convert {
my ($label) = @_;
open(CL, "<$CVSLabels/$label") or die "can't open CVS label $label: $!";
open(PL, ">$P4Labels/$label") or die "can't open P4 label $label: $!";
while (<CL>) {
chomp;
my ($cvsrev, $realbr) = split "$S";
verbose "mapping: $cvsrev $realbr";
print PL find_match($cvsrev, $label, $realbr), "\n";
}
close CL;
close PL;
}
# option switch variables get defaults here...
$V = 0;
$cfile = '';
$help = 0;
use Getopt::Long;
GetOptions(
"codelines=s" => \$cfile,
"help" => \$help,
"v+" => \$V
) || usage(1);
$help && usage(0);
$Convdir = shift || usage(1);
$Revlog = "$Convdir/revlog";
$CVSLabels = "$Convdir/labels/cvs";
$P4Labels = "$Convdir/labels/p4";
# Read in the codeline maps
#
if ($cfile) {
open HINTS, "<$cfile" or die "can't open codeline hints $cfile: $!";
while (<HINTS>) {
chomp;
next if /^#/;
next if /^\s*$/;
verbose "using codeline hint: $_";
my ($label, @codelines) = split /\s+/;
$HINTS{$label} = [ @codelines ];
}
close HINTS;
}
# Read in the revisions
#
%CVSREV = ();
%NOGUESS = ();
open REVLOG, "<$Revlog" or die "can't open $Revlog: $!";
while (<REVLOG>) {
my ($p4rev, $br, $cvsrev) = split "$S";
verbose 3, "using: $p4rev $br $cvsrev";
$CVSREV{"$br$cvsrev"} = $p4rev;
}
close REVLOG;
# loop over each cvs label file and convert them
#
opendir(CVSLABELS, $CVSLabels) or die "can't open directory $CVSLabels: $!";
for my $label (readdir(CVSLABELS)) {
next if $label =~ /\.\.?/;
verbose "converting $label";
convert($label);
}
closedir(CVSLABELS);
# mention labels that may have unwanted mappings
#
for my $label (keys %NOGUESS) {
print STDERR "some files in $label didn't find a codeline match\n";
if ($V > 1) {
print STDERR "They were:\n";
while (my ($cvs, $p4) = each %{$NOGUESS{$label}}) {
print STDERR " $cvs\n $p4\n";
}
}
}