File: generate_changelog.php

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (328 lines) | stat: -rwxr-xr-x 8,144 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?php
/*
  +----------------------------------------------------------------------+
  | ini doc settings updater                                             |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2010 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.0 of the PHP license,       |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_0.txt.                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Authors:    Nuno Lopes <nlopess@php.net>                             |
  +----------------------------------------------------------------------+

  $Id: generate_changelog.php 293138 2010-01-05 10:21:11Z rquadling $
*/


// if run alone, it means debug mode and thus no slow network access
if (empty($included)) {
    $skip_download = true;
}

require_once './cvs-versions.php';
require_once './pecl.php';


/** converts a tag like php_5_0_0 into a version like 5.0.0 */
function tag2version($tag)
{
    global $cvs_versions;

    if (isset($cvs_versions[$tag]))
        return $cvs_versions[$tag];

    if (substr_compare($tag, 'PHP_', 0, 4, true) == 0) {
        return strtr(substr($tag, 4), '_', '.');
    } else { // PECL
        return substr($tag, strpos($tag, '-')+1);
    }
}


/** return the major version of a given release tag */
function major_version($tag)
{
    $v = tag2version($tag);
    return substr($v, 0, strpos($v, '.'));
}


/** returns TRUE if the tag is a PHP release */
function is_php($tag)
{
   return (substr_compare($tag, 'PHP_', 0, 4, true) == 0);
}


/** returns TRUE if the opt is/was present in PHP (i.e. it is not in PECL only) */
function in_php($array)
{
   return is_php(key($array));
}


/** returns the package name of the given array/string */
function pkg_name($array)
{
    $input = is_array($array) ? key($array) : $array;
    preg_match('/^(.+)-\d+(?:\.\d+)+$/S', $input, $m);
    $lowered = $m[1];

    foreach (get_pecl_packages() as $pkg) {
        if (strcasecmp($pkg, $lowered) === 0) {
            return $pkg;
        }
    }
}


/** fetch the local PECL releases of the given pkg name */
function get_local_pecl_releases($array)
{
    static $cache = array();

    $pecl_releases = get_pecl_releases_local();

    $pkg = pkg_name($array);

    if (isset($cache[$pkg])) return $cache[$pkg];

    $pkg_strlen = strlen($pkg);

    foreach ($pecl_releases as $release) {
        if (substr_compare($pkg, $release, 0, $pkg_strlen, true) == 0) {
            $cache[$pkg][] = $release;
        }
    }

    return $cache[$pkg];
}


/** return when the option become available */
function available_since($array)
{
    $ver = null;

    if (in_php($array)) {
        if (!current($array)) {
            foreach ($array as $tag => $val) {
                if ($val) {
                    $ver = 'PHP '. tag2version($tag);
                    break;
                }
            }
        }

    // PECL only
    } else {
        $releases = get_local_pecl_releases($array);

        if (key($array) !== current($releases)) {
            foreach ($releases as $rel) {
                if ($rel === key($array)) {
                    $ver = pkg_name($array) .' '. tag2version($rel);
                    break;
                }
            }
        }
    }

    return $ver ? "Available since $ver." : '';
}


/** check for changes between versions */
function last_version($array)
{
    $majors   = array();
    $last     = null;
    $last_tag = null;
    $last_php = true;
    $output   = '';

    foreach ($array as $tag => $val) {
        if (!$val) continue;
        if (!$last) $last = $val;
        if (!$last_tag) $last_tag = $tag;

        $majorver            = major_version($tag);
        $first_major_release = false;
        $now_php             = is_php($tag);

        if (!$now_php && $last_php) { // now we have PECl stuff. reset the major versions array
            $majors = array();
        }

        if (!isset($majors[$majorver])) {
            $majors[$majorver]   = $val;
            $first_major_release = true;

        } elseif ($majors[$majorver] !== $val) { // the value isnt the same in this major version
            $majors[$majorver] = false;
        }


        // the change is only significant if not comparing between PHP and PECL releases
        if ($val !== $last && ($now_php || !$last_php)) {

            $pkg = is_php($tag) ? 'PHP' : pkg_name($tag);
            if ($output) $output .= ' ';

            if ($first_major_release) {
                if (empty($majors[$majorver-1]) || count($majors) > 2) {
                    $ver = "&lt; $majorver";
                } else {
                    $ver = $majorver-1;
                }
            } else {
                $ver = '&lt;= ' . tag2version($last_tag);
            }

            $output .= "$last in $pkg ". $ver . '.';
        }

        $last     = $val;
        $last_tag = $tag;
        $last_php = $now_php;

    }

    return $output;
}


/** return when the option was removed */
function removed_in($array)
{
    $ver = null;

    if (in_php($array)) {
        $on = false;

        foreach ($array as $tag => $val) {
            if ($val) {
                $on = true;

            } elseif ($on) {
                $ver = 'PHP '. tag2version($tag);
                break;
            }
        }

    // PECL only
    } else {
        $releases = get_local_pecl_releases($array);

        $on = false;
        end($array);

        if (end($releases) !== key($array)) {
            foreach ($releases as $release) {
                if ($release === key($array)) {
                    $on = true;

                } else if ($on) {
                    $ver = pkg_name($array) .' '. tag2version($release);
                    break;
                }
            }
        }
    }


    return $ver ? "Removed in $ver." : '';
}


/** generate the changelog column */
function generate_changelog($array)
{
    $data = array(
        last_version($array),
        available_since($array),
        removed_in($array),
    );


    $str = '';

    foreach ($data as $s) {
        if ($s) {
            $str .= ($str ? ' ' : '') . $s;
        }
    }

    return $str;
}



if (!$idx = sqlite_open('ini_changelog.sqlite', 0666, $error)) {
    die("Couldn't open the DB: $error");
}

$q = sqlite_unbuffered_query($idx, 'SELECT * FROM changelog');

/* This hack is needed because sqlite 2 sort case-sensitive */
while ($row = sqlite_fetch_array($q, SQLITE_ASSOC)) {
    $name = $row['name'];
    unset($row['name']);
    uksort($row, 'strnatcasecmp');
    $info[$name] = $row;
}


$q = sqlite_unbuffered_query($idx, 'SELECT * FROM pecl_changelog');

while ($row = sqlite_fetch_array($q, SQLITE_ASSOC)) {
    $info[$row['name']][$row['package'].'-'.$row['version']] = $row['value'];
}


/** custom sorting callback, so that PHP releases are listed before PECL ones. */
function my_strnatcasecmp($a, $b)
{
    if (is_php($a)) {
        return is_php($b) ? strnatcasecmp($a, $b) : -1;
    } else {
        return is_php($b) ? 1 : strnatcasecmp($a, $b);
    }
}

// sort releases with the callback above
foreach ($info as &$r) {
    uksort($r, 'my_strnatcasecmp');
}


uksort($info, 'strnatcasecmp');

foreach ($info as $name => $row) {
    $changelog[$name] = generate_changelog($row);

    // WARNING: DEBUG STUFF
    if (isset($argv[1]) && $name === $argv[1]) {
        print_r($row);
        var_dump($changelog[$name]);
        exit;
    }
}

// if in debug mode
if (empty($included)) {
    foreach ($changelog as $key => $val) {
        echo "$key : $val\n";
    }
}

sqlite_close($idx);
unset($idx);

?>