感謝@pitseeker
我創建了一個Perl的包裝「P4S」的檢查參數,並調用轉發給真正的「P4提交」。
#!/usr/bin/perl
use warnings;
use strict;
use Capture::Tiny 'capture_merged';
die "Description and file is required!\n" if @ARGV < 2;
my ($description, @files) = @ARGV;
if (-f $description) {
die "It looks like you forgot the description before the filenames";
}
my $cmd;
my %summary;
print `date`;
for my $file (@files) {
if (! -f $file) {
$summary{$file} = "File $file not found!";
next;
}
my $pwd = `pwd`;
chomp $pwd;
# print p4 filelog to screen
print `ls -l $file`;
$cmd = "p4 filelog $file | head -n 2";
$cmd = "p4 fstat -T 'headRev' $file";
print $cmd . "\n";
my $filelog = `$cmd`;
print "$filelog" . "\n";
$cmd = "p4 diff -sa $file";
my ($merged, $status) = Capture::Tiny::capture_merged {system($cmd)};
if (! $merged) {
$summary{$file} = "Skipped since the local file does not differ from p4";
next;
}
# p4 submit
$cmd = "p4 submit -r -d \"$description\" $file";
print $cmd . "\n";
($merged, $status) = Capture::Tiny::capture_merged {system($cmd)};
chomp $merged;
print $merged . "\n";
if ($merged =~ /No files to submit from the default changelist/) {
$summary{$file} = "$merged (You may need to 'p4 add' or 'p4 edit' this file)";
next;
}
$summary{$file} = "Success";
}
if (scalar @files > 0) {
print "\nSummary:\n";
for my $file (@files) {
printf "%s %s\n", $file, $summary{$file};
}
}
一個相當簡單的方法:打開文件並且不打算提交它們時,運行'p4 change'並將這些文件放在單獨編號的更改列表中。沒有文件名的'p4 submit -d'只會提交在默認更改列表中打開的文件,因此您編號的更改列表中的文件將不會被提交。 –
Perforce管理員可以使用Perforce代理阻止提交,但這是用戶空間中的一個難題。由於這個原因,我個人主要回去提交沒有-d。 – Matt
在用戶空間中,您可以編寫一個包裝來檢查參數,並將調用轉發給實際的「p4」或拒絕提交(如果您沒有給出想要提供的參數) – pitseeker