#!/usr/bin/perl -w
use lib '.';
use Getopt::Long;
use P4::Modules;
($CLIENT, $ROOT, $MODULES, $EXTRAS) = ('c2p', '', '', '');
($OPTIONS, $bfile, $file) = ('rmdir', '', '');
my $help = 0;
(my $cmd = $0) =~ s/.*\///;
sub usage {
print <<_EOF_;
Usage: $cmd -b branch -c client -e extra -f file -m modules -o options -r root
$cmd -h
-b file file listing branch mappings (no default)
-c client create/update this client (def. $CLIENT)
-e extra one extra client view mapping (no default)
-f file the modules file to use (def. system installed)
-h show usage
-m modules modules to map from the perforce depots (def. all modules)
-o options perforce client options (def. $OPTIONS)
-r root perforce client root directory (no default)
_EOF_
exit $_[0] || 0;
}
usage(0) unless @ARGV;
GetOptions('branch=s' => \$bfile,
'client=s' => \$CLIENT,
'extra=s' => \$EXTRAS,
'file=s' => \$file,
'help' => \$help,
'modules=s' => \$MODULES,
'options=s' => \$OPTIONS,
'root=s' => \$ROOT) || usage(1);
usage(0) if $help;
!$bfile and die "no branch file specified\n";
my $config = shift;
require $config if $config;
my $mod = P4::Modules->new($file);
$client_spec = <<_EOF_;
Client: $CLIENT
Description:
Automatically generated client for cvs2p4 migration.
Root: $ROOT
Options: $OPTIONS
View:
_EOF_
open BRANCHES, "<$bfile" or die "can't open $bfile: $!\n";
while (<BRANCHES>) {
chomp;
next if /^#/;
next if /^\s*$/;
my ($p4branch, $cvsbranch) = split /\s+/;
$p4branch =~ s|/$||;
$p4branch =~ s|^/|| unless $p4branch =~ m|^//|;
$cvsbranch = $p4branch unless $cvsbranch;
my %map = $mod->client($p4branch, $MODULES, "$CLIENT/$cvsbranch");
$client_spec .= join("\n", map { "\t$_ $map{$_}" } keys %map) . "\n";
}
close BRANCHES;
$client_spec .= join("\n", map { "\t$_" } split /\n+/, $EXTRAS) . "\n";
print "$client_spec";