Rev 84 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 84 | Rev 87 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * PHP svn functions |
4 | * PHP svn functions |
5 | * Copyright 2021 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2021 - 2023 Daniel Marschall, ViaThinkSoft |
6 | * Revision 2023-04-21 |
6 | * Revision 2023-09-15 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 64... | Line 64... | ||
64 | // We couldn't get the revision info |
64 | // We couldn't get the revision info |
65 | // Try parsing the binary file. It is a bit risky though... |
65 | // Try parsing the binary file. It is a bit risky though... |
66 | return get_svn_revision_without_sqlite3($dir); |
66 | return get_svn_revision_without_sqlite3($dir); |
67 | } |
67 | } |
68 | 68 | ||
- | 69 | // 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. |
|
69 | function get_svn_revision_without_sqlite3($svn_path, $base='trunk') { |
70 | function get_svn_revision_without_sqlite3($svn_path, $base='trunk') { |
70 | if (!empty($svn_path)) $svn_path .= '/'; |
71 | if (!empty($svn_path)) $svn_path .= '/'; |
71 | if (!is_dir($svn_path)) return false; |
72 | if (!is_dir($svn_path)) return false; |
72 | if (!is_dir($svn_path.'/.svn')) $svn_path .= '/../'; |
73 | if (!is_dir($svn_path.'/.svn')) $svn_path .= '/../'; |
73 | 74 | ||
74 | $fil = file_get_contents($svn_path.'/.svn/wc.db'); |
75 | $fil = file_get_contents($svn_path.'/.svn/wc.db'); |
75 | preg_match_all('@('.preg_quote($base,'@').'/[a-z0-9!"#$%&\'()*+,.\/:;<=>?\@\[\] ^_`{|}~-]+)(..)normal(file|dir)@', $fil, $m, PREG_SET_ORDER); |
76 | preg_match_all('@('.preg_quote($base,'@').'/[a-z0-9!"#$%&\'()*+,.\/:;<=>?\@\[\] ^_`{|}~-]+)(..)normal(file|dir)@', $fil, $m, PREG_SET_ORDER); |
76 | 77 | ||
77 | $files = array(); |
78 | $files = array(); |
78 | foreach ($m as list($dummy, $fil, $revision)) { |
79 | foreach ($m as list($dummy, $fil, $revision, $type)) { |
79 | $val = hexdec(bin2hex($revision)); |
80 | $val = hexdec(bin2hex($revision)); |
80 | 81 | ||
81 | $tmp = explode("$base/", $fil); |
82 | $tmp = explode("$base/", $fil); |
82 | $fil = end($tmp); |
83 | $fil = end($tmp); |
83 | 84 | ||
- | 85 | // TODO: Problem: We don't know if it was checked out as / or checked out as /trunk/, or something else! |
|
84 | if (!file_exists($svn_path."/$base/$fil")) continue; // deleted files (deleted rows?!) might be still in the binary |
86 | if (!file_exists($svn_path."/$base/$fil") && !file_exists($svn_path."/$fil")) continue; // deleted files (deleted rows?!) might be still in the binary |
85 | 87 | ||
86 | if (!isset($files[$fil])) $files[$fil] = -1; |
88 | if (!isset($files[$fil])) $files[$fil] = -1; |
87 | if ($files[$fil] < $val) $files[$fil] = $val; |
89 | if ($files[$fil] < $val) $files[$fil] = $val; |
88 | } |
90 | } |
89 | - | ||
90 | $arr = array_values($files); |
91 | $arr = array_values($files); |
91 | 92 | ||
92 | /* |
93 | /* |
93 | foreach ($files as $name => $val) { |
94 | foreach ($files as $name => $val) { |
94 | if ($val != 1228) echo "DEBUG Unexpected: $val / $fil\n"; |
95 | if ($val != 1228) echo "DEBUG Unexpected: $val / $fil\n"; |
95 | } |
96 | } |
96 | */ |
97 | */ |
97 | 98 | ||
- | 99 | if (count($files) == 0) return 1; // should not happen |
|
98 | $num = count($arr); |
100 | $num = count($arr); |
99 | $middleVal = floor(($num - 1) / 2); |
101 | $middleVal = floor(($num - 1) / 2); |
100 | if($num % 2) { |
102 | if ($num % 2) { |
101 | $median = $arr[$middleVal]; |
103 | $median = $arr[$middleVal]; |
102 | } else { |
104 | } else { |