- #!/usr/bin/perl
- # Read some old clients and map them into something else
- $oldproj=$ARGV[0];
- $oldprojrev=$ARGV[1];
- $newproj=$ARGV[2];
- $newprojrev=$ARGV[3];
- $site=$ARGV[4];
- if($site ne "") {
- $dosite=1;
- print "Site is $site\n";
- }
- $projvar=$ENV{"PROJECT"};
- if($site eq "force") {
- $dosite="";
- $extend="-f";
- }
- print "Old: $oldproj old rev: $oldprojrev\n";
- print "New: $newproj new rev: $newprojrev\n";
- $searchstring=":".$oldproj."_".$oldprojrev."_top";
- $cmd="p4 clients | grep '$searchstring ' > /tmp/cmap.$$";
- #print "$cmd\n";
- system($cmd);
- if($dosite eq 1) {
- $source=$oldproj."_".$oldprojrev;
- $target=$newproj."_".$newprojrev."_".$site;
- } else {
- $source=$oldproj."_".$oldprojrev."_top";
- $target=$newproj."_".$newprojrev."_top";
- }
- #print "$source, $target\n";
- # Get the branch roots
- $sclient=$source."_client";
- $tclient=$target."_client";
- $cmd="p4 client -o $sclient";
- open(CMD,"$cmd|") || die;
- while(<CMD>) {
- if(/^Root/) {
- ($ig,$sroot)=split;
- }
- }
- $cmd="p4 client -o $tclient";
- open(CMD,"$cmd|") || die;
- while(<CMD>) {
- if(/^Root/) {
- ($ig,$troot)=split;
- }
- }
- if($sroot eq $ENV{PWD}) {
- print "Error: Source branch client not found, root points to PWD\n";
- exit 1;
- }
- if($troot eq $ENV{PWD}) {
- print "Error: Target branch client not found, root points to PWD\n";
- exit 1;
- }
- print "Source root is $sroot\n";
- print "Target root is $troot\n";
- open(CL,"</tmp/cmap.$$");
- while(<CL>) {
- (@cdata)=split;
- $tplate=$cdata[1];
- $tplate_root=$cdata[4];
- #print "Template client is $tplate\n";
- $newc=$tplate;
- $ntarget=$target;
- $newc=~ s/$source/$ntarget/g;
- print "New client is $newc\n";
- # Check to see if it exists
- $cmd="p4 clients | grep $newc>/dev/null ";
- system($cmd);
- #print "$cmd\n";
- # Good exit means it exists, don't futz with an existing client
- if ($? eq 0 && !($newc =~ /_tapeout/)) {
- print "Syncing existing client\n";
- $cmd="p4 -c $newc sync > /dev/null";
- system($cmd);
- next;
- }
- if($dosite eq 1) {
- print "no site support!\n";
- exit 1;
- #$newroot=~ s/$oldproj\/$oldprojrev/$site\/$newproj\/$newprojrev/g;
- }
- $cmd="p4 -c $tplate client -o";
- open(CMD, "$cmd|") || die ;
- open(CMDOUT, ">/tmp/cbout.$$") || die ;
- while(<CMD>) {
- if(/^Client/) {
- print CMDOUT "Client: $newc\n\n";
- }
- if(/^Description/ && $dosite eq 1) {
- $dstring="Description: \n\t$newproj $newprojrev site:$site cds library\n";
- print $dstring;
- print CMDOUT $dstring;
- } else {
- if(/^Description/) {
- print CMDOUT "Description: \n\t$newproj $newprojrev cds library\n";
- }}
- if(/^Root/) {
- s/$sroot/$troot/;
- print CMDOUT "$_";
- }
- if(/^View/) {
- print CMDOUT "$_\n";
- }
- if(/^\t\-{0,1}\/\/depot/) {
- s/$source/$target/g;
- s/$tplate/$newc/g;
- print CMDOUT $_;
- }
- }
- close(CMD);
- close(CMDOUT);
- $cmd="p4 -c $newc client -i < /tmp/cbout.$$ > /dev/null";
- system($cmd);
- # let's make sure we have some files in the client
- # and delete the client if the files are empty
- $cmd="p4 -s -c $newc sync -n";
- $emptyclient=0;
- open(P4C, "$cmd|") || die "Could not exec $cmd\n";
- while(<P4C>) {
- if( /error: No such file/) {
- # delete it
- $emptyclient=1;
- }
- }
- close(P4C);
- if($emptyclient eq 1) {
- print "Deleting empty or unbranched client $newc\n";
- $cmd="p4 client -d $newc";
- system($cmd);
- }
- #let the autosyncer sync the remote sites
- if($dosite ne 1) {
- if(!$newc =~ /_tapeout/) {
- $cmd="p4 -c $newc sync $extend > /dev/null";
- system($cmd);
- } }
- }
- close(CL);
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5093 | Hari Krishna Dara |
Populating perforce branch. I will be adding p4admin files to it. |
20 years ago | |
//guest/perforce_software/cdsp4/release/2.2/Utils/projclientmapper | |||||
#2 | 2891 | Shiv Sikand | Better error checking for non-existent project roots | 22 years ago | |
#1 | 1705 | Shiv Sikand | Added missing utilities for branch management | 23 years ago |