以下のスクリプトは、Linuxでperlスクリプトを使用して実行されます。必要に応じて、WindowsやPerl以外のスクリプト言語を使用して適応できると確信しています。
管理者ユーザーとして、と入力し
p4 triggers
ます。
スクリプトの行の下にこれを追加しTriggers:
ます。
Trigger_name change-content //... "/<path_to_trigger_script>/<script_name> %changelist% %serverhost% %serverport% %user%"
はTrigger_name
任意です。は//...
すべてのバージョン管理されたファイルを意味しますが、必要に応じてこれを変更できます。囲まれ%
ているものはすべて、PERFORCEに固有の特別な変数名であり、これらがスクリプトの引数になります。これらはあなたが必要とするすべてでなければなりません。囲まれているもの<>
はすべて可変であり、環境によって異なることに注意してください。
さて、スクリプト自体について。これは私が書いたものです。
#!/usr/bin/perl
# ----- CHECK 1 : Make sure files NOT identical
# get variables passed in through triggers call 'p4 triggers'
$ChangeNum = $ARGV[0]; #change number
$Server = $ARGV[1];
$Port = $ARGV[2];
$User = $ARGV[3];
$p4 = "<path_to_p4_exec>/p4 -p $Port ";
# get list of files opened under the submitted changelist
@files = `$p4 opened -a -c $ChangeNum | cut -f1 -d"#"`;
# go through each file and compare to predecessor
# although workspace should be configured to not submit unchanged files
# this is an additional check
foreach $file (@files)
{
chomp($file);
# get sum of depot file, the #head version
$depotSum = `$p4 print -q $file\#head | sum`;
# get sum of the recently submitted file, use @=$ChangeNum to do this
$clientSum = `$p4 print -q $file\@=$ChangeNum | sum`;
chomp $depotSum;
chomp $clientSum;
# if 2 sums are same, issue error
if ( $depotSum eq $clientSum )
{
# make sure this file is opened for edit and not for add/delete
if ( `$p4 describe $ChangeNum | grep "edit"` )
{
printf "\nFile $file identical to predecessor!";
exit( 1 );
}
}
}