p4perl スクリプトとファイルが同じ p4 クライアントに属している場合に、p4perl を使用してファイルを追加/削除/チェックイン/チェックアウトする方法を知っています。ただし、p4perl スクリプトとファイルが別の p4 クライアントに属している場合、どうすればよいかわかりません。
どうにかして $p4->FetchClient() を呼び出す必要があると思います。しかし、私はそれを行う方法を正確に知りません。
以下は、同じ p4 クライアントでファイルをチェックアウトできる実験的なコードです。
use strict;
use P4; # a p4perl module
**#my $p4root = "A P4 root dir" e.g. '//projects/...'
# File '$f1' is under a different p4 client root, e.g. $p4root
#my $f1 = $ENV{HOME}.'/work/aFile_ToBe_Checkedout_From_P4.pl';**
# File '$f2' is under the same p4 client root as this tool $0 is in
my $f2 = './runANI.pl';
&showFileMode($f2);
my $p4 = new P4;
$p4->Connect() or die( "Failed to connect to Perforce Server" );
**#$p4->RunEdit($f1); # To check out file '$f1'. It does not work
#&reportP4err($p4);**
$p4->RunEdit($f2); # To check out file '$f2'. It works!!
&reportP4err($p4);
&showFileMode($f2);
exit;
sub showFileMode {
my ($file) = @_;
my @properties = stat($file);
my $mode = $properties[2];
my $modeInDecimal = $mode & 07777;
my $modeInOctal = sprintf("%04o", $modeInDecimal);
if($modeInOctal eq '0555') {
print "File '$file' is checked in with a mode: $modeInOctal\n";
}
elsif($modeInOctal eq '0755') {
print "File '$file' is checked out with a mode: $modeInOctal\n";
}
}
sub reportP4err {
my ($p4) = @_;
if ($p4->ErrorCount()) {
print "In report_p4_errors()\n";
foreach my $e ($p4->Errors()) {
print "P4 Error MSG: $e\n";
}
die "P4 error, exiting";
}
}
サンプル実行:
% ./testP4perl.pl
File './runANI.pl' is checked in with a mode: 0555
File './runANI.pl' is checked out with a mode: 0755