3 # Plot the history of a debian package from the changelog, displaying
4 # when each release of the package occurred, and who made each release.
5 # To make the graph a little more interesting, the debian revision of the
6 # package is used as the y axis.
8 # Pass this program the changelog(s) you wish to be plotted.
10 # Copyright 1999 by Joey Hess <joey@kitenet.net>
11 # Modifications copyright 2003 by Julian Gilbey <jdg@debian.org>
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 use File::Temp qw/ tempfile /;
35 eval { require Date::Parse; import Date::Parse (); };
37 my $progname = basename($0);
38 if ($@ =~ /^Can\'t locate Date\/Parse\.pm/) {
39 die "$progname: you must have the libtimedate-perl package installed\nto use this script\n";
41 die "$progname: problem loading the Date::Parse module:\n $@\nHave you installed the libtimedate-perl package?\n";
47 my $progname = basename($0);
48 my $modified_conf_msg;
52 Usage: plotchangelog [options] changelog ...
53 -v --no-version Do not show package version information.
54 -m --no-maint Do not show package maintainer information.
55 -u --urgency Use larger points for higher urgency uploads.
56 -l --linecount Make the Y axis be number of lines in the
58 -b --bugcount Make the Y axis be number of bugs closed
60 -c --cumulative With -l or -b, graph the cumulative number
61 of lines or bugs closed.
62 -g "commands" Pass "commands" on to gnuplot, they will be
63 --gnuplot="commands" added to the gnuplot script that is used to
65 -s file --save=file Save the graph to the specified file in
67 -d --dump Dump gnuplot script to stdout.
68 --verbose Outputs the gnuplot script.
69 --help Show this message.
70 --version Display version and copyright information.
71 --noconf Don\'t read devscripts configuration files
73 At most one of -l and -b (or their long equivalents) may be used.
75 Default settings modified by devscripts configuration files:
80 my $versioninfo = <<"EOF";
81 This is $progname, from the Debian devscripts package, version ###VERSION###
82 This code is copyright 1999 by Joey Hess <joey\@kitenet.net>.
83 Modifications copyright 1999-2003 by Julian Gilbey <jdg\@debian.org>
84 This program comes with ABSOLUTELY NO WARRANTY.
85 You are free to redistribute this code under the terms of the
86 GNU General Public License, version 2 or later.
89 my ($no_version, $no_maintainer, $gnuplot_commands, $dump,
90 $save_filename, $verbose, $linecount, $bugcount, $cumulative,
91 $help, $showversion, $show_urgency, $noconf)="";
93 # Handle config file unless --no-conf or --noconf is specified
94 # The next stuff is boilerplate
95 my $extra_gnuplot_commands='';
96 if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
97 $modified_conf_msg = " (no configuration files read)";
100 my @config_files = ('/etc/devscripts.conf', '~/.devscripts');
102 'PLOTCHANGELOG_OPTIONS' => '',
103 'PLOTCHANGELOG_GNUPLOT' => '',
105 my %config_default = %config_vars;
109 foreach my $var (keys %config_vars) {
110 $shell_cmd .= "$var='$config_vars{$var}';\n";
112 $shell_cmd .= 'for file in ' . join(" ",@config_files) . "; do\n";
113 $shell_cmd .= '[ -f $file ] && . $file; done;' . "\n";
115 foreach my $var (keys %config_vars) { $shell_cmd .= "echo \$$var;\n" }
116 my $shell_out = `/bin/bash -c '$shell_cmd'`;
117 @config_vars{keys %config_vars} = split /\n/, $shell_out, -1;
119 foreach my $var (sort keys %config_vars) {
120 if ($config_vars{$var} ne $config_default{$var}) {
121 $modified_conf_msg .= " $var=$config_vars{$var}\n";
124 $modified_conf_msg ||= " (none)\n";
125 chomp $modified_conf_msg;
127 if ($config_vars{'PLOTCHANGELOG_OPTIONS'}) {
128 unshift @ARGV, split(' ', $config_vars{'PLOTCHANGELOG_OPTIONS'});
130 $extra_gnuplot_commands=$config_vars{'PLOTCHANGELOG_GNUPLOT'};
134 "no-version|v", \$no_version,
135 "no-maint|m", \$no_maintainer,
136 "gnuplot|g=s", \$gnuplot_commands,
137 "save|s=s", \$save_filename,
139 "urgency|u", \$show_urgency,
140 "verbose", \$verbose,
141 "l|linecount", \$linecount,
142 "b|bugcount", \$bugcount,
143 "c|cumulative", \$cumulative,
145 "version", \$showversion,
146 "noconf" => \$noconf,
147 "no-conf" => \$noconf,
149 or die "Usage: $progname [options] changelog ...\nRun $progname --help for more details\n";
152 die "$progname: --no-conf is only acceptable as the first command-line option!\n";
165 if ($bugcount && $linecount) {
166 die "$progname: can't use --bugcount and --linecount\nRun $progname --help for usage information.\n";
169 if ($cumulative && ! $bugcount && ! $linecount) {
170 warn "$progname: --cumulative without --bugcount or --linecount: ignoring\nRun $progname --help for usage information.\n";
174 die "Usage: $progname [options] changelog ...\nRun $progname --help for more details\n";
178 my ($package, $version, $maintainer, $date, $urgency)=undef;
179 my ($data_tmpfile, $script_tmpfile);
180 my ($data_fh, $script_fh);
183 $data_fh = tempfile("plotdataXXXXXX", UNLINK => 1)
184 or die "cannot create temporary file: $!";
185 fcntl $data_fh, Fcntl::F_SETFD(), 0
186 or die "disabling close-on-exec for temporary file: $!";
187 $script_fh = tempfile("plotscriptXXXXXX", UNLINK => 1)
188 or die "cannot create temporary file: $!";
189 fcntl $script_fh, Fcntl::F_SETFD(), 0
190 or die "disabling close-on-exec for temporary file: $!";
191 $data_tmpfile='/dev/fd/'.fileno($data_fh);
192 $script_tmpfile='/dev/fd/'.fileno($script_fh);
203 open F,"zcat $_|" || die "$_: $!";
206 open F,$_ || die "$_: $!";
211 # Note that some really old changelogs use priority, not urgency.
212 if (/^(\w+.*?)\s+\((.*?)\)\s+.*?;\s+(?:urgency|priority)=(.*)/i) {
217 if ($urgency=~/high/i) {
220 elsif ($urgency=~/medium/i) {
234 elsif (/^ -- (.*?) (.*)/) {
238 # Strip email address.
239 $maintainer=~s/<.*>//;
240 $maintainer=~s/\(.*\)//;
241 $maintainer=~s/\s+$//;
243 elsif (/^(\w+.*?)\s+\((.*?)\)\s+/) {
244 print STDERR qq[Parse error on "$_"\n];
246 elsif ($linecount && /^ /) {
247 $c++; # count changelog size.
249 elsif ($bugcount && /^ /) {
250 # count bugs that were said to be closed.
255 if (defined $package && defined $version &&
256 defined $maintainer && defined $date && defined $urgency) {
257 $data{$package}{$pkgcount{$package}++}=
258 [$linecount || $bugcount ? $c : $version,
259 $maintainer, $date, $urgency];
272 # have to massage the data; based on some code from later on
273 foreach $package (keys %data) {
275 # It's crucial the output is sorted by date.
276 foreach my $i (sort {$data{$package}{$a}[2] <=> $data{$package}{$b}[2]}
277 keys %{$data{$package}}) {
278 $total += $data{$package}{$i}[0];
279 $data{$package}{$i}[0] = $total;
285 set key below title "key" box
286 set timefmt "%m/%d/%Y %H:%M"
292 if ($cumulative) { $header.="set ylabel 'Cumulative changelog length'\n"; }
293 else { $header.="set ylabel 'Changelog length'\n"; }
296 if ($cumulative) { $header.="set ylabel 'Cumulative bugs closed'\n"; }
297 else { $header.="set ylabel 'Bugs closed'\n"; }
300 $header.="set ylabel 'Debian version'\n";
302 if ($save_filename) {
303 $header.="set terminal postscript color solid\n";
304 $header.="set output '$save_filename'\n";
311 # Note that "lines" is used if we are also showing maintainer info,
312 # otherwise we use "linespoints" to make sure points show up for each
314 my $style = $no_maintainer ? "linespoints" : "lines";
316 foreach $package (keys %data) {
317 my $oldmaintainer="";
319 # It's crucial the output is sorted by date.
320 foreach my $i (sort {$data{$package}{$a}[2] <=> $data{$package}{$b}[2]}
321 keys %{$data{$package}}) {
322 my $v=$data{$package}{$i}[0];
323 $maintainer=$data{$package}{$i}[1];
324 $date=$data{$package}{$i}[2];
325 $urgency=$data{$package}{$i}[3];
327 $maintainer=~s/"/\\"/g;
331 # If it's got a debian revision, use that as the y coordinate.
332 if ($v=~m/(.*)-(.*)/) {
340 # Now make sure the version is a real number. This includes making
341 # sure it has no more than one decimal point in it, and getting rid of
342 # any nonnumeric stuff. Otherwise, the "set label" command below could
343 # fail. Luckily, perl's string -> num conversion is perfect for this job.
346 if (lc($maintainer) ne lc($oldmaintainer)) {
347 $oldmaintainer=$maintainer;
350 my ($sec, $min, $hour, $mday, $mon, $year)=localtime($date);
351 my $x=($mon+1)."/$mday/".(1900+$year)." $hour:$min";
353 $maintdata{$oldmaintainer}{$urgency}.="$x\t$y\n";
355 if ($oldversion ne $version && ! $no_version) {
356 # Upstream version change. Label it.
357 $header.="set label '$version' at '$x',$y left\n";
358 $oldversion=$version;
361 $data.="\n\n"; # start new dataset
362 # Add to plot command.
363 $script.="'$data_tmpfile' index $index using 1:3 title '$package' with $style, ";
368 my $title.="set title '";
369 $title.=$#ARGV > 1 ? "Graphing Debian changelogs" :
370 "Graphing Debian changelog";
373 if (! $no_maintainer) {
374 foreach $maintainer (sort keys %maintdata) {
375 foreach $urgency (sort keys %{$maintdata{$maintainer}}) {
376 $data.=$maintdata{$maintainer}{$urgency}."\n\n";
377 $script.="'$data_tmpfile' index $index using 1:3 title \"$maintainer\" with points pointsize ".(1.5 * $urgency).", ";
387 $extra_gnuplot_commands
391 $script.="pause -1 'Press Return to continue.'\n"
392 unless $save_filename || $dump;
395 # Annoyingly, we have to use 2 temp files. I could just send everything to
396 # gnuplot on stdin, but then the pause -1 doesn't work.
397 open (DATA, ">$data_tmpfile") || die "$data_tmpfile: $!";
398 open (SCRIPT, ">$script_tmpfile") || die "$script_tmpfile: $!";
401 open (DATA, ">&STDOUT");
402 open (SCRIPT, ">&STDOUT");
405 print SCRIPT $script;
406 print $script if $verbose && ! $dump;
412 unless (system("gnuplot",$script_tmpfile) == 0) {
413 die "gnuplot program failed (is the gnuplot package installed?): $!\n";