File: debbugs-makeversions

package info (click to toggle)
debbugs 2.6.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,800 kB
  • sloc: perl: 19,270; makefile: 81; sh: 75
file content (197 lines) | stat: -rwxr-xr-x 5,192 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
#! /usr/bin/perl -w
# Extract version information from an existing non-versioned database by
# guesswork, based on Version: pseudo-headers and closing mails that look
# like Debian changelogs. The latter in particular is somewhat heuristic.

use strict;
use Debbugs::Log;
use Debbugs::MIME;

if (@ARGV != 2) {
    print <<EOF;
Usage: $0 db-directory versions-directory

EOF
    exit 0;
}

sub getbuginfo ($)
{
    my $log = shift;
    #print "Processing $log ...\n";

    open LOG, "< $log" or die "Can't open $log: $!";
    my @records = read_log_records(*LOG);
    close LOG;

    my (@found_versions, @fixed_versions);
    my (%found_versions, %fixed_versions);

    for my $record (@records) {
	if ($record->{type} eq 'html') {
	    # Reassigns zap the found and fixed version list. Reopens will
	    # zap the fixed list too in the full deployment, but doing that
	    # here causes problems in case of accidental reopens and
	    # recloses.
	    if ($record->{text} =~ /assigned/) {
		@found_versions = ();
		%found_versions = ();
		@fixed_versions = ();
		%fixed_versions = ();
	    }
	    next;
	}

	next unless $record->{type} eq 'autocheck' or
		    $record->{type} eq 'incoming-recv';
	my $decoded = Debbugs::MIME::parse($record->{text});
	next unless defined $decoded;

	# Was it sent to -done or -close?
	my $closing = 0;
	my $firstreceived = $decoded->{header}[0];
	if ($firstreceived =~ /\(at [^)]*-(?:done|close)\)/) {
	    $closing = 1;
	}

	# Get Version: pseudo-headers.
	my $i;
	my ($source, $sourcever, $ver);
	for ($i = 0; $i < @{$decoded->{body}}; ++$i) {
	    last if $decoded->{body}[$i] !~ /^(\S+):\s*(.*)/;
	    my ($fn, $fv) = (lc $1, $2);
	    if ($fn eq 'source') {
		$source = $fv;
	    } elsif ($fn eq 'source-version' and
		     $fv =~ /^(\d[^,\s]*(?:[,\s]+|$))+/) {
		$sourcever = $fv;
	    } elsif ($fn eq 'version' and $fv =~ /^(\d[^,\s]*(?:[,\s]+|$))+/) {
		# Deal with reportbug brain-damage.
		next if $fv =~ /^unavailable/i;
		$fv =~ s/;.*//;
		$fv =~ s/ *\(.*\)//;
		$ver = $fv;
	    }
	}

	my @parsedvers;
	if (defined $ver) {
	    push @parsedvers, split /[,\s]+/, $ver;
	} elsif (defined $source and defined $sourcever) {
	    push @parsedvers, map "$source/$_", split /[,\s]+/, $sourcever;
	}

	if ($closing) {
	    for my $v (@parsedvers) {
		push @fixed_versions, $v
		    unless exists $fixed_versions{$v};
		$fixed_versions{$v} = 1;
		@found_versions = grep { $_ ne $v } @found_versions;
		delete $found_versions{$v};
	    }
	} else {
	    for my $v (@parsedvers) {
		push @found_versions, $v
		    unless exists $found_versions{$v};
		$found_versions{$v} = 1;
		@fixed_versions = grep { $_ ne $v } @fixed_versions;
		delete $fixed_versions{$v};
	    }
	}

	if ($closing) {
	    # Look for Debian changelogs.
	    for (; $i < @{$decoded->{body}}; ++$i) {
		if ($decoded->{body}[$i] =~
			/(\w[-+0-9a-z.]+) \(([^\(\) \t]+)\) \S+; urgency=\S+/i) {
		    my ($p, $v) = ($1, $2);
		    push @fixed_versions, "$p/$v"
			unless exists $fixed_versions{"$p/$v"};
		    $fixed_versions{"$p/$v"} = 1;
		    @found_versions = grep { $_ ne "$p/$v" } @found_versions;
		    delete $found_versions{"$p/$v"};
		    last;
		}
	    }
	}
    }

    return (\@found_versions, \@fixed_versions);
}

sub mergeinto ($$)
{
    my ($target, $source) = @_;
    my %seen = map { $_ => 1 } @$target;
    for my $v (@$source) {
	next if exists $seen{$v};
	push @$target, $v;
	$seen{$v} = 1;
    }
}

my ($db, $verdb) = @ARGV[0, 1];
opendir DB, $db or die "Can't opendir $db: $!";
unless (-d $verdb) {
    mkdir $verdb or die "Can't mkdir $verdb: $!";
}

while (defined(my $dir = readdir DB)) {
    next if $dir =~ /^\.\.?$/ or not -d "$db/$dir";
    opendir HASH, "$db/$dir" or die "Can't opendir $db/$dir: $!";

    while (defined(my $file = readdir HASH)) {
	next unless $file =~ /\.log$/;
	next if -z "$db/$dir/$file";
	(my $bug = $file) =~ s/\..*//;

	$bug =~ /(..)$/;
	my $bughash = $1;
	#next if -e "$verdb/$bughash/$bug.versions" and
	#	(stat "$verdb/$bughash/$bug.versions")[9] >=
	#	    (stat "$db/$dir/$file")[9];

	print "Processing $bug ...\n" if $ENV{DEBBUGS_VERBOSE};

	open STATUS, "$db/$dir/$bug.status" or next;
	<STATUS> for 1 .. 6;	# done is field 7
	chomp (my $done = <STATUS>);
	<STATUS>;		# mergedwith is field 9
	chomp (my $mergedwith = <STATUS>);
	close STATUS;

	my ($found_versions, $fixed_versions) = getbuginfo("$db/$dir/$file");

	if (length $mergedwith) {
	    for my $merge (split ' ', $mergedwith) {
		$merge =~ /(..)$/;
		my $mergehash = $1;
		my ($mfound, $mfixed) =
		    getbuginfo("$db/$mergehash/$merge.log");
		mergeinto($found_versions, $mfound);
		mergeinto($fixed_versions, $mfixed);
	    }
	}

	@$fixed_versions = () unless length $done;

	for my $out ($bug, (split ' ', $mergedwith)) {
	    $out =~ /(..)$/;
	    my $outhash = $1;

	    unless (-d "$verdb/$outhash") {
		mkdir "$verdb/$outhash" or die "Can't mkdir $verdb/$outhash: $!";
	    }

	    open VERSIONS, "> $verdb/$outhash/$out.versions"
		or die "Can't open $verdb/$outhash/$out.versions: $!";
	    print VERSIONS "Found-in: @$found_versions\n";
	    print VERSIONS "Fixed-in: @$fixed_versions\n";
	    close VERSIONS;
	}
    }

    closedir HASH;
}

closedir DB;