我正在我的服务器上构建一个简单的更改检测程序。文件的合法更改来自 Beanstalk SVN 部署,它们在我的报告中代表噪音。我想从报告中排除这些文件。
通过一个漫长而复杂的过程,我可以通过 Beanstalk API 提取受影响的文件名和相关的存储库和修订,并将它们写入一个多维数组。文件名位于最低维度。当然,如果有意义的话,我可以用其他方式处理这些数据。根据我的开发人员的工作方式,他们可能会在一天中多次提交对同一个文件的更改。
部署到多个服务器:开发、生产、备份等。
每个文件我需要的是它更改的最后一个(最高)修订号。
我的数组遵循下面代码段的格式。请注意,相同的文件列在元素 1、3、5 中,但修订版不同。我需要从中构建一个数组['filename(unique)']['last-revision']。我知道我可以使用蛮力循环并替换现有文件的修订号,如果它大于当前值。我的数据集的大小足够小,可以做到这一点没问题。我只是在向社区寻求更优雅的东西。
有什么建议么?到目前为止,数组片段下方是我的蛮力代码。
[484680] => Array (
[0] => Array (
[revision] => 25924
[file] => Array (
[0] => trunk/shq/includes/mysqliClass/manageMstCash.php
[1] => trunk/shq/includes/forms/cash_report_for_clerk.php
))
[1] => Array (
[revision] => 25923
[file] => Array (
[0] => trunk/shq/includes/mysqliClass/manageInvoiceLineItems.php
))
[3] => Array (
[revision] => 25921
[file] => Array (
[0] => trunk/shq/includes/mysqliClass/manageInvoiceLineItems.php
))
[5] => Array (
[revision] => 25919
[file] => Array (
[0] => trunk/shq/includes/mysqliClass/manageInvoiceLineItems.php
))
...)
第一切蛮力最大修订分配:
foreach($cs as $repos) {
foreach($repos as $repo) {
foreach($repo['file'] as $file) {
$x = $file;
$rev = $repo['revision'];
if(isset($afb[$x]['revision'])) { // we have existing revision for filename
if ($rev > $afb[$x]['revision']) {
$afb[$x]['revision'] = $rev;
$afb[$x]['time'] = $repo['time'];
} // no else - it's already set and the last revision
} else { // $afb[filename] not set - create it
$afb[$x]['revision'] = $rev;
$afb[$x]['time'] = $repo['time'];
}
}
} # end foreach repo
} # end foreach changeset
感谢您的输入!