#!/usr/bin/perl -w # # spacecheck.perl # # Checks filenames at submit trigger time to ensure that no file names # are submitted with spaces. # # p4 opened -ac --- gives list of files associated with a cl# my $change; my $p4="/usr/local/bin/p4"; # add any port/user info ############################################################################ ## # Init - initialize the script # # ARGV[0] = change # ############################################################################ ## sub Init { my $nf=@ARGV; $change=""; if ($nf == 1) { $change=$ARGV[0]; } else { print "insufficient arguments: \n"; die "insufficient arguments: \n"; } } ############################################################################ ## # Error ############################################################################ ## sub Error { ($es)=@_; print "\nSubmit Policy violation\n\n"; print "Error: $es\n\n"; print "Use 'p4 change $change' to edit description\n"; exit 1; } ############################################################################ ## # Process - Process the information ############################################################################ ## sub Process { $cmd="$p4 opened -ac $change"; unless (open(CMD, "$cmd |")) { print "can't open cmd=[$cmd]"; die "can't open cmd=[$cmd]"; } @files=(); while () { chomp; if (/(.*)\#\d+ - (add|edit|integrate|branch) change \d+/) { my $file = $1; if ($file =~ /\s/) { push(@files, $file); } } } unless (close(CMD)) { print "can't close cmd=[$cmd]"; die "can't close cmd=[$cmd]"; } if (scalar(@files)) { Error("Spaces not allowed in filenames:" . join("\n", "", @files)); } } ############################################################################ ## # MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN # ############################################################################ ## Init(); Process(); exit 0;