#!/p4/common/perl/bin/perl -w #------------------------------------------------------------------------------ # Call this as a Perforce trigger. Sample Triggers table entry: # # Triggers: # SetWSRoot form-out client "/p4/common/bin/triggeres/SetWSRoot.pl %formfile%" # # See 'p4 help triggers' for more info. use strict; use File::Copy; $#ARGV == 0 or die "\nError: Bad usage!\n"; my $FormFile=$ARGV[0]; my $NewFormFile="$FormFile" . ".new"; my $FormValid=0; my $FormExists=0; my $OnWindows=0; my $WSName = "Unset"; my $WSShortName = "Unset"; my $WSRootBase = "/p4/ws"; my $WSRoot; my $User = "Unset"; open (CSPEC, "<$FormFile") or die "Error: Could not read form file [$FormFile]: $!\n"; open (NEW_CSPEC, ">$NewFormFile") or die "Error: Could not write new form file [$NewFormFile]: $!\n"; while () { if (/^Client:/) { $FormValid = 1; $WSName = $_; chomp $WSName; $WSName =~ s/^Client:\s*//; } if (/^Update:/) { $FormExists = 1; last; } if (/^Owner:/) { $User = $_; chomp $User; $User =~ s/^Owner:\s*//; } if (/^Root:/) { if (/^Root:.*:/) { $OnWindows = 1; last; } $WSShortName = $WSName; if ($WSName =~ /^$User\./) { $WSShortName =~ s/^$User\.//; } $WSRoot = "$WSRootBase/$User/$WSShortName\n"; s/^Root:.*/Root: $WSRoot/g; } print NEW_CSPEC; } close (CSPEC); close (NEW_CSPEC); exit 0 if ($FormExists or $OnWindows); die "Error: Invalid form in form file; no Client: field." unless $FormValid; move ("$NewFormFile", "$FormFile") or die "Failed to update form file [$FormFile]."; exit 0;