]> git.donarmstrong.com Git - bugscan.git/blob - bugdiff
merge changes from dla bugscan
[bugscan.git] / bugdiff
1 #!/usr/bin/perl
2 # vim: ts=8 sw=8 nowrap
3
4 # Compare two buglist status-files
5
6 use Getopt::Std;
7 require scanlib;
8 require bugcfg;
9 use strict;
10 use warnings;
11
12 my $Version             = "BugDiff 1.0\nCopyright (C) Wichert Akkerman <wakkerma\@debian.org>\n";
13 my $html                        = 0;
14
15 my (%removed, %new);
16
17 sub ShowVersion() {
18         print "$Version\n";
19         exit 0;
20 }
21
22 sub ShowUsage() {
23         print <<EOF;
24 Usage:
25   $0 [-V] [-h] [-H] <status1> <status2>
26 Options:
27   -V    show version
28   -h    show some (hopefully) helpfull information
29   -H    produce HTML output
30   -n    list newly opened bugs
31   -c    list closed bugs
32   -s    show statistics
33 EOF
34         exit 0;
35 }
36
37 sub closedbugs() {
38         if ($html) {
39                 if (%removed) {
40                         print "<h2>Closed/downgraded release-critical bugs</h2>\n";
41                         print "<ul>\n";
42                         for my $p (sort keys %removed) {
43                                 print "  <li><em>" . &scanlib::wwwname($p) . ":</em>\n";
44                                 for $b (sort @{$removed{$p}}) {
45                                         print &scanlib::wwwnumber($b) . " ";
46                                 }
47                                 print "\n";
48                         }
49                         print "</ul>\n";
50                 }
51         } else {
52                 print "Closed/downgraded release-critical bugs:\n" if (scalar keys %removed>0);
53                 for my $p (sort keys %removed) {
54                         print "   $p: ";
55                         print join(", ", sort @{$removed{$p}});
56                         print "\n";
57                 }
58         }
59 }
60
61
62 sub openedbugs() {
63         if ($html) {
64                 if (%new) {
65                         print "<h2>Opened/upgraded release-critical bugs</h2>\n";
66                         print "<ul>\n";
67                         for my $p (sort keys %new) {
68                                 print "  <li><em>" . &scanlib::wwwname($p) . ":</em>\n";
69                                 for $b (sort @{$new{$p}}) {
70                                         print &scanlib::wwwnumber($b) . " ";
71                                 }
72                                 print "\n";
73                         }
74                         print "</ul>\n";
75                 }
76         } else {
77                 print "Opened/upgraded release-critical bugs:\n" if (%new);
78                 for my $p (sort keys %new) {
79                         print "   $p: ";
80                         print join(", ", sort @{$new{$p}});
81                         print "\n";
82                 }
83         }
84 }
85
86 sub statistics($$) {
87         my ($opened, $closed) = @_;
88
89         if ($html) {
90                 print "<STRONG>" . ($closed ? $closed : "NO") . "</STRONG> release-critical bugs were closed and ";
91                 print "<STRONG>" . ($opened ? $opened : "NONE") . "</STRONG> were opened.<P>\n";
92         } else {
93                 print "" . ($closed ? $closed : "NO") . " release-critical bugs were closed ";
94                 print "and " . ($opened ? $opened : "NONE") . " were opened.\n\n";
95         }
96 }
97
98 our ($opt_V, $opt_h, $opt_H, $opt_n, $opt_c, $opt_s);
99 getopts('VhHncs');
100 ShowUsage if ($opt_h or ($#ARGV != 1));
101 ShowVersion if ($opt_V);
102 $html=1 if ($opt_H);
103
104 scanlib::readstatus($ARGV[0]);
105 my %oldbugs=%scanlib::packagelist;
106 %scanlib::packagelist=();
107
108 scanlib::readstatus($ARGV[1]);
109
110 my $closed=0;
111 for my $p (keys %oldbugs) {
112         for $b (@{$oldbugs{$p}}) {
113                 if (!defined($scanlib::packagelist{$p}) || scalar grep { $_ == $b } @{$scanlib::packagelist{$p}} == 0) { 
114                         push @{$removed{$p}}, $b;
115                         $closed++;
116                 }
117         }
118 }
119
120 my $opened=0;
121 for my $p (keys %scanlib::packagelist) {
122         for $b (@{$scanlib::packagelist{$p}}) {
123                 if (!defined($oldbugs{$p}) || scalar grep { $_ == $b } @{$oldbugs{$p}} == 0) { 
124                         push @{$new{$p}}, $b;
125                         $opened++;
126                 }
127         }
128 }
129
130 statistics($opened, $closed) if ($opt_s);
131 closedbugs if ($opt_c);
132 openedbugs if ($opt_n);
133
134 exit 0;
135