我如何可以访问所提交的文件从一个颠复预先提交钩在Perl?
-
18-09-2019 - |
题
我需要做到以下几点:
写预先提交钩在Perl
钩应该检查的所有文件正在致力于存在一些文字,以及失败,如果该案文不被发现
基本上,我需要一个例子Perl钩,读取文件的承诺。
我真的在寻找一些优雅的解决方案与最少量的代码。
注:钩应该使用 svnlook
或者其他更好的方式来查找文件。
解决方案
预提交钩:
my $repos = shift;
my $txn = shift;
foreach my $line (`$svnlook changed -t $txn "$repos"`)
{
chomp($line);
if ($line !~ /^([AUD]).\s\s(.+)$/)
{
print STDERR "Can't parse [$line].\n";
exit(1);
}
else
{
my $action = $1;
my $file = $2;
chomp($file);
#If path has trailing slash, then it is a folder and we want to skip folders
if($file =~ /\/$/)
{
next;
}
my $fileContent = `$svnlook cat -t $txn "$repos" "$file"`;
if ($action =~ /[AU]/)
{
my @lines = split(/\n/, $fileContent );
#Check for whatever you need in this file's content
}
}
}
不隶属于 StackOverflow