Subversion Repositories php_utils

Compare Revisions

Regard whitespace Rev 82 → Rev 83

/trunk/svn_utils.inc.php
2,8 → 2,8
 
/*
* PHP svn functions
* Copyright 2021 Daniel Marschall, ViaThinkSoft
* Revision 2021-12-15
* Copyright 2021 - 2023 Daniel Marschall, ViaThinkSoft
* Revision 2023-04-21
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
61,6 → 61,44
}
 
// We couldn't get the revision info
return false;
// Try parsing the binary file. It is a bit risky though...
return get_svn_revision_without_sqlite3($dir);
}
 
function get_svn_revision_without_sqlite3($svn_path, $base='trunk') {
$fil = file_get_contents($svn_path.'/.svn/wc.db');
preg_match_all('@('.preg_quote($base,'@').'/[a-z0-9!"#$%&\'()*+,.\/:;<=>?\@\[\] ^_`{|}~-]+)(..)normal(file|dir)@', $fil, $m, PREG_SET_ORDER);
 
$files = array();
foreach ($m as list($dummy, $fil, $revision)) {
$val = hexdec(bin2hex($revision));
 
$tmp = explode("$base/", $fil);
$fil = end($tmp);
 
if (!file_exists($svn_path."/$base/$fil")) continue; // deleted files (deleted rows?!) might be still in the binary
 
if (!isset($files[$fil])) $files[$fil] = -1;
if ($files[$fil] < $val) $files[$fil] = $val;
}
 
$arr = array_values($files);
 
/*
foreach ($files as $name => $val) {
if ($val != 1228) echo "DEBUG Unexpected: $val / $fil\n";
}
*/
 
$num = count($arr);
$middleVal = floor(($num - 1) / 2);
if($num % 2) {
$median = $arr[$middleVal];
} else {
$lowMid = $arr[$middleVal];
$highMid = $arr[$middleVal + 1];
$median = (($lowMid + $highMid) / 2);
}
 
return $median;
}