Subversion Repositories php_utils

Rev

Rev 21 | Rev 84 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 83
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * PHP svn functions
4
 * PHP svn functions
5
 * Copyright 2021 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2021 - 2023 Daniel Marschall, ViaThinkSoft
6
 * Revision 2021-12-15
6
 * Revision 2023-04-21
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 59... Line 59...
59
                } catch (Exception $e) {
59
                } catch (Exception $e) {
60
                }
60
                }
61
        }
61
        }
62
 
62
 
63
        // We couldn't get the revision info
63
        // We couldn't get the revision info
-
 
64
        // Try parsing the binary file. It is a bit risky though...
64
        return false;
65
        return get_svn_revision_without_sqlite3($dir);
65
}
66
}
66
 
67
 
-
 
68
function get_svn_revision_without_sqlite3($svn_path, $base='trunk') {
-
 
69
        $fil = file_get_contents($svn_path.'/.svn/wc.db');
-
 
70
        preg_match_all('@('.preg_quote($base,'@').'/[a-z0-9!"#$%&\'()*+,.\/:;<=>?\@\[\] ^_`{|}~-]+)(..)normal(file|dir)@', $fil, $m, PREG_SET_ORDER);
-
 
71
 
-
 
72
        $files = array();
-
 
73
        foreach ($m as list($dummy, $fil, $revision)) {
-
 
74
                $val = hexdec(bin2hex($revision));
-
 
75
 
-
 
76
                $tmp = explode("$base/", $fil);
-
 
77
                $fil = end($tmp);
-
 
78
 
-
 
79
                if (!file_exists($svn_path."/$base/$fil")) continue; // deleted files (deleted rows?!) might be still in the binary
-
 
80
 
-
 
81
                if (!isset($files[$fil])) $files[$fil] = -1;
-
 
82
                if ($files[$fil] < $val) $files[$fil] = $val;
-
 
83
        }
-
 
84
 
-
 
85
        $arr = array_values($files);
-
 
86
 
-
 
87
        /*
-
 
88
        foreach ($files as $name => $val) {
-
 
89
                if ($val != 1228) echo "DEBUG Unexpected: $val / $fil\n";
-
 
90
        }
-
 
91
        */
-
 
92
 
-
 
93
    $num = count($arr);
-
 
94
    $middleVal = floor(($num - 1) / 2);
-
 
95
    if($num % 2) {
-
 
96
        $median = $arr[$middleVal];
-
 
97
    } else {
-
 
98
        $lowMid = $arr[$middleVal];
-
 
99
        $highMid = $arr[$middleVal + 1];
-
 
100
        $median = (($lowMid + $highMid) / 2);
-
 
101
    }
-
 
102
 
-
 
103
    return $median;
-
 
104
}