Here is my rough first pass at a Perl wrapper around p4 commands.
It would be most useful if you had a LOT of files to check in.
The form editor is NOT invoked.
#
# p4checkoutfiles.pl -
#
# Will check out all files in current directory.
# Print newly-created changelist number to display, for p4submitfiles.pl.
# Optional command line parameter for Description, e.g. "Modifications from 07/25/2011".
#
# USAGE:
# 1. Copy this script to a new folder.
# 2. Copy all files to be checked in to this same folder.
# 3. Run this script to check out all the files, as follows:
#
# p4checkoutfiles.pl <clientspec> <changelist_description>
#
# For example:
#
# p4checkoutfiles.pl ClientSpec-Mike "Modifications from 07/25/2011".
#
#
# 4. Manually copy these files over their older versions, in the correct workspace directory.
# 5. Run p4checkinfiles.pl.
#
#
use strict;
use warnings;
################################################################################
# Save any command line parameters in local variables.
################################################################################
my $Client = shift;
die unless $Client;
my $ChangelistDescription = shift;
################################################################################
# Read default p4 form from pipe that executes p4 change command.
################################################################################
my $DefaultChangelistForm = "";
my $PrintDefaultChangelistCommand = "p4 change -o |";
open (PRINTDEFAULTCHANGELISTCOMMAND, $PrintDefaultChangelistCommand);
while (<PRINTDEFAULTCHANGELISTCOMMAND>)
{
if (($_ !~ "Client") &&
($_ !~ "User") &&
($_ !~ "Status"))
{
$DefaultChangelistForm .= $_;
}
}
# print "\$DefaultChangelistForm is: " . $DefaultChangelistForm;
close PRINTDEFAULTCHANGELISTCOMMAND;
################################################################################
# Swap in any command line parameter for Description
################################################################################
if ($ChangelistDescription)
{
$DefaultChangelistForm =~ s/<enter description here>/$ChangelistDescription/
}
################################################################################
# Write modified form values to disk, to be read by following p4 change -i.
################################################################################
open (FORMFORNEWCHANGELIST, ">formfornewchangelist.txt");
print FORMFORNEWCHANGELIST $DefaultChangelistForm;
close (FORMFORNEWCHANGELIST);
################################################################################
# Create new changelist using FORMFORNEWCHANGELIST.
# Read new changelist number from pipe that creates new changelist.
################################################################################
print "Creating new changelist...\n";
my $NewChangeList = "";
my $NewChangeListNumber = "";
my $CreateNewChangeListCommand = "";
$CreateNewChangeListCommand = "p4 -c ";
$CreateNewChangeListCommand .= $Client;
$CreateNewChangeListCommand .= " change -i < formfornewchangelist.txt |";
open (CREATENEWCHANGELISTCOMMAND, $CreateNewChangeListCommand);
while (<CREATENEWCHANGELISTCOMMAND>)
{
if ($_ =~ "created")
{
# Save new change list number for below.
$NewChangeListNumber = $_;
print $_;
}
}
close CREATENEWCHANGELISTCOMMAND;
################################################################################
# Save new changelist number to disk file newchangelistnumber.txt.
################################################################################
# Just parse numbers from string.
if ($NewChangeListNumber =~ /(\d+)/)
{
$NewChangeListNumber = $1;
}
open (NEWCHANGELISTNUMBER, ">newchangelistnumber.txt");
print NEWCHANGELISTNUMBER $NewChangeListNumber;
close (NEWCHANGELISTNUMBER);
################################################################################
# Read workspace root from pipe that executes p4 client command.
################################################################################
my $WorkspaceRoot = "";
my $PrintClientCommand = "p4 client -o ";
$PrintClientCommand .= $Client;
$PrintClientCommand .= " |";
open (PRINTCLIENTCOMMAND, $PrintClientCommand);
while (<PRINTCLIENTCOMMAND>)
{
# Save workspace root for edit command, below.
if ($_ =~ "Root:")
{
$WorkspaceRoot = $_;
# Just parse stuff after Root:
if ($WorkspaceRoot =~ /Root:\s*(.*)/)
{
$WorkspaceRoot = $1;
}
}
}
close PRINTCLIENTCOMMAND;
die unless length($WorkspaceRoot) > 0;
# print "WorkspaceRoot is: " . $WorkspaceRoot;
################################################################################
# For each file (other than newchangelistnumber.txt),
# check out that file into newly-created changelist.
# NOTE: THIS CODE ASSUMES THE FILES HAVE ALREADY BEEN ADDED TO PERFORCE.
# Enhancement: Fix above constraint.
################################################################################
print "Checking out all files in this subdirectory already in Perforce...\n";
my $directory = '.';
opendir (DIR, $directory) or die $!;
while (my $file = readdir(DIR))
{
# We only want files
next unless (-f "$directory/$file");
# Skip text files.
next if ($file =~ m/\.txt$/);
# Skip Perl files.
next if ($file =~ m/\.pl$/);
my $CheckOutFileCommand = "";
$CheckOutFileCommand = "p4 -c ";
$CheckOutFileCommand .= $Client;
$CheckOutFileCommand .= " edit ";
$CheckOutFileCommand .= " -c " . $NewChangeListNumber . " ";
$CheckOutFileCommand .= $WorkspaceRoot . "\\" . $file;
$CheckOutFileCommand .= " | ";
open (CHECKOUTFILECOMMAND, $CheckOutFileCommand);
while (<CHECKOUTFILECOMMAND>)
{
print $_;
}
close CHECKOUTFILECOMMAND;
}
closedir(DIR);