Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
#!/usr/bin/php -q
2
<?php
3
/* vim: set noai expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
4
/**
5
 * Script to generate changelog file
6
 *
7
 * Relies on svn2cl
8
 * Echoes on STDOUT
9
 *
10
 * PHP version 5
11
 *
12
 * @category  System
13
 * @package   System_Daemon
14
 * @author    Kevin <kevin@vanzonneveld.net>
15
 * @copyright 2008 Kevin van Zonneveld (http://kevin.vanzonneveld.net)
16
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD Licence
17
 * @version   SVN: Release: $Id: changelog_gen.php 218 2009-04-25 10:29:41Z kevin $
18
 * @link      http://trac.plutonia.nl/projects/system_daemon
19
 */
20
 
21
$workspace_dir        = realpath(dirname(__FILE__)."/..");
22
$cmd_reqs             = array();
23
$cmd_reqs["svn2cl"]   = "subversion-tools";
24
$map_authors          = array();
25
$map_authors["kevin"] = "Kevin van Zonneveld <kevin@vanzonneveld.net>";
26
 
27
// check if commands are available
28
foreach ($cmd_reqs as $cmd=>$package) {
29
    exec("which ".$cmd, $o, $r);
30
    if ($r) {
31
        echo $cmd." is not available. ";
32
        echo "Please first install the ".$package;
33
        die("\n");
34
    }
35
}
36
 
37
if (isset($argv[1]) && is_numeric($argv[1])) {
38
    $rev = "--revision=HEAD:".$argv[1];
39
 
40
}
41
 
42
// collect data
43
$cmd  = "";
44
$cmd .= "svn up ".$workspace_dir;
45
exec($cmd, $o, $r);
46
if ($r) {
47
    die("Executing: ".$cmd." failed miserably\n");
48
}
49
 
50
$cmd  = "";
51
$cmd .= "svn2cl -i --stdout --group-by-day ".$rev." --linelen=90000 ".$workspace_dir;
52
exec($cmd, $o, $r);
53
if ($r) {
54
    die("Executing: ".$cmd." failed miserably\n");
55
}
56
 
57
// divide blocks
58
$blocks    = array();
59
$cur_block = false;
60
foreach ($o as $i=>$line_raw) {
61
    if (preg_match('/^(\d{4}-\d{2}-\d{2})(\s*)(.*)/', $line_raw, $match)) {
62
        // prepare new block
63
        $date      = trim($match[1]);
64
        $author    = trim($match[3]);
65
        $author    = str_replace(array_keys($map_authors),
66
            array_values($map_authors), $author);
67
        $cur_block = $date . " ". $author;
68
 
69
        // don't record the date header itsself
70
        continue;
71
    }
72
 
73
    $line = trim($line_raw);
74
 
75
    // don't record empty lines
76
    if (!$line) continue;
77
    if (!$cur_block) continue;
78
 
79
    // extract comment + revision
80
    preg_match('/^[^\[]+(\[r\d+\])(.*)/', $line, $match);
81
    $revision = trim($match[1]);
82
    $comment  = trim($match[2]);
83
    if (!$revision && $old_revision) {
84
        // fallback to old revision
85
        $revision = $old_revision;
86
    }
87
    if (!$comment) {
88
        $comment = $line;
89
    }
90
 
91
    // remove the file which the comment is about
92
    $comment = preg_replace('/^([^:])+:(\s+)/', '', $comment);
93
    $comment = trim($comment);
94
 
95
    // don't record empty lines
96
    if (!$comment) continue;
97
 
98
    if (!substr($comment, 0, 7) == "http://") {
99
        $comment = ucfirst($comment);
100
    }
101
 
102
    // record what's left
103
    $blocks[$cur_block][$comment][] = $revision;
104
 
105
    // nescesary for fallback in case newlines are used for commit comments
106
    $old_revision = $revision;
107
}
108
 
109
// simplify blocks
110
foreach ($blocks as $date=>$block_arr) {
111
    if (isset($blocks[$date]) && is_array($blocks[$date])) {
112
        foreach ($blocks[$date] as $comm=>$revs) {
113
            $blocks[$date][$comm] = reset($revs);
114
        }
115
    }
116
}
117
 
118
// print blocks
119
$cnt = 1;
120
foreach ($blocks as $date=>$block_arr) {
121
    if ($cnt != 1) {
122
        echo "\n";
123
    }
124
    echo $date."\n\n";
125
    foreach ($blocks[$date] as $comm=>$rev) {
126
        echo "        ".$rev." ".$comm."\n";
127
    }
128
    $cnt++;
129
}
130
echo "\n";
131
?>