&1'); $match = array(); if (preg_match('/\d+/', $output, $match)) { return ($cachedVersion = $match[0]); } $output = @shell_exec('svn info '.escapeshellarg($dir).' 2>&1'); if (preg_match('/Revision:\s*(\d+)/m', $output, $match)) { // do not translate return ($cachedVersion = $match[1]); } // If that failed, try to get the version via access of the database files if (class_exists('SQLite3')) { try { $db = new SQLite3($dir.'.svn/wc.db'); $results = $db->query('SELECT MIN(revision) AS rev FROM NODES_BASE'); while ($row = $results->fetchArray()) { return ($cachedVersion = $row['rev']); } $db->close(); $db = null; } catch (Exception $e) { } } if (class_exists('PDO')) { try { $pdo = new PDO('sqlite:'.$dir.'.svn/wc.db'); $res = $pdo->query('SELECT MIN(revision) AS rev FROM NODES_BASE'); $row = $res->fetch(); if ($row !== false) { return ($cachedVersion = $row['rev']); } $pdo = null; } catch (Exception $e) { } } // We couldn't get the revision info // Try parsing the binary file. It is a bit risky though... return get_svn_revision_without_sqlite3($dir); } // Note: get_svn_revision_without_sqlite3() can be very unstable, so it is highly recommended to install php-sqlite in order to parse the file correctly. function get_svn_revision_without_sqlite3($svn_path, $base='trunk') { if (!empty($svn_path)) $svn_path .= '/'; if (!is_dir($svn_path)) return false; if (!is_dir($svn_path.'/.svn')) $svn_path .= '/../'; $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, $type)) { $val = hexdec(bin2hex($revision)); $tmp = explode("$base/", $fil); $fil = end($tmp); // TODO: Problem: We don't know if it was checked out as / or checked out as /trunk/, or something else! if (!file_exists($svn_path."/$base/$fil") && !file_exists($svn_path."/$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"; } */ if (count($files) == 0) return 1; // should not happen $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; }