#! /usr/bin/perl # # NAME: templatebranch.pl # # DESC: This script uses original branchspec as a template # to make a new branchspec # # Command line equivalent # p4 branch -o OLD | sed '/^Branch:/ c\Branch: NEW' | p4 branch -i # $branchold = shift ARGV; #The original branchspec template. $user = shift ARGV; #The current user. $server = shift ARGV; #ip_address:port of your Perforce server. $branchnew = shift ARGV; #The new branchspec name made from template. $p4 = "p4"; # Absolute path to the p4 cli program. if ($branchold eq $branchnew) { print "\nNew branchspec name must be unique and not already exist.\n\nSelect a branchspec and try again.\n"; exit 1; } $cmd = "\"$p4\" -u $user -p $server branch -o \"$branchold\" | sed '/^Branch:/ c\Branch: \"$branchnew\"' | p4 branch -i |"; open NEWBRNCH, $cmd or die "Cannot run template branchspec command.\n\n"; $count = 0; while () { $count++; } if($count ne 0) { print "\nNew branchspec $branchnew created.\n\nBranch created from $branchold.\n"; } if($count eq 0) { print "\nNo new branchspec created from template.\n"; } exit 0;