6 # Hack to work on merkel where suexec is in place
8 if ($ENV{HTTP_HOST} eq 'merkel.debian.org') {
9 unshift @INC, qw(/home/don/perl/usr/share/perl5 /home/don/perl/usr/lib/perl5 /home/don/source);
10 $ENV{DEBBUGS_CONFIG_FILE}="/home/don/config_internal";
17 use CGI::Alert 'don@donarmstrong.com';
19 use Debbugs::Config qw(:config);
20 use Debbugs::CGI qw(htmlize_packagelinks html_escape cgi_parameters);
21 use Debbugs::Versions;
22 use Debbugs::Versions::Dpkg;
23 use Debbugs::Packages qw(getversions makesourceversions);
24 use HTML::Entities qw(encode_entities);
25 use File::Temp qw(tempdir);
30 my %img_types = (svg => 'image/svg+xml',
34 my $q = new CGI::Simple;
36 my %cgi_var = cgi_parameters(query => $q,
37 single => [qw(package format ignore_boring width height)],
38 default => {package => 'xterm',
48 # we want to first load the appropriate file,
49 # then figure out which versions are there in which architectures,
52 for my $dist (@{$config{distributions}}) {
53 $versions{$dist} = [getversions($cgi_var{package},$dist)];
54 # make version_to_dist
55 foreach my $version (@{$versions{$dist}}){
56 push @{$version_to_dist{$version}}, $dist;
60 if (defined $cgi_var{width}) {
61 $cgi_var{width} =~ /(\d+)/;
64 if (defined $cgi_var{height}) {
65 $cgi_var{height} =~ /(\d+)/;
66 $cgi_var{height} = $1;
69 if (defined $cgi_var{format}) {
70 $cgi_var{format} =~ /(png|svg|jpg|gif)/;
71 $cgi_var{format} = $1 || 'png';
74 $cgi_var{format} = 'png';
77 # then figure out which are affected.
78 # turn found and fixed into full versions
79 @{$cgi_var{found}} = makesourceversions($cgi_var{package},undef,@{$cgi_var{found}});
80 @{$cgi_var{fixed}} = makesourceversions($cgi_var{package},undef,@{$cgi_var{fixed}});
81 my @interesting_versions = makesourceversions($cgi_var{package},undef,keys %version_to_dist);
83 # We need to be able to rip out leaves which the versions that do not affect the current versions of unstable/testing
85 @sources{map {m{(.+)/}; $1} @{$cgi_var{found}}} = (1) x @{$cgi_var{found}};
86 @sources{map {m{(.+)/}; $1} @{$cgi_var{fixed}}} = (1) x @{$cgi_var{fixed}};
87 @sources{map {m{(.+)/}; $1} @interesting_versions} = (1) x @interesting_versions;
88 my $version = Debbugs::Versions->new(\&Debbugs::Versions::Dpkg::vercmp);
89 foreach my $source (keys %sources) {
90 my $srchash = substr $source, 0, 1;
91 my $version_fh = new IO::File "$config{version_packages_dir}/$srchash/$source", 'r';
92 $version->load($version_fh);
94 # Here, we need to generate a short version to full version map
96 foreach my $key (keys %{$version->{parent}}) {
97 my ($short_version) = $key =~ m{/(.+)$};
98 next unless length $short_version;
99 # we let the first short version have presidence.
100 $version_map{$short_version} = $key if not exists $version_map{$short_version};
102 # Turn all short versions into long versions
103 for my $found_fixed (qw(found fixed)) {
104 $cgi_var{$found_fixed} =
107 if ($_ !~ m{/}) { # short version
110 else { # long version
113 } @{$cgi_var{$found_fixed}}
116 my %all_states = $version->allstates($cgi_var{found},$cgi_var{fixed});
118 my $dot = "digraph G {\n";
119 if (defined $cgi_var{width} and defined $cgi_var{height}) {
120 $dot .= qq(size="$cgi_var{width},$cgi_var{height}";\n);
122 my %state = (found => ['fillcolor="salmon"',
126 absent => ['fillcolor="grey"',
129 fixed => ['fillcolor="chartreuse"',
134 # TODO: Allow collapsing versions which are at the same state and not
136 foreach my $key (keys %all_states) {
137 my ($short_version) = $key =~ m{/(.+)$};
138 next if $cgi_var{ignore_boring} and (not defined $all_states{$key}
139 or $all_states{$key} eq 'absent');
140 next if $cgi_var{ignore_boring} and not version_relevant($version,$key,\@interesting_versions);
141 my @attributes = @{$state{$all_states{$key}}};
142 if (length $short_version and exists $version_to_dist{$short_version}) {
143 push @attributes, 'label="'.$key.'\n'."(".join(', ',@{$version_to_dist{$short_version}}).")\"";
145 my $node_attributes = qq("$key" [).join(',',@attributes).qq(]\n);
146 $dot .= $node_attributes;
148 foreach my $key (keys %{$version->{parent}}) {
149 next if not defined $version->{parent}{$key};
150 next if $cgi_var{ignore_boring} and $all_states{$key} eq 'absent';
151 next if $cgi_var{ignore_boring} and (not defined $all_states{$version->{parent}{$key}}
152 or $all_states{$version->{parent}{$key}} eq 'absent');
153 # Ignore branches which are not ancestors of a currently distributed version
154 next if $cgi_var{ignore_boring} and not version_relevant($version,$key,\@interesting_versions);
155 $dot .= qq("$key").'->'.qq("$version->{parent}{$key}" [dir="back"])."\n" if defined $version->{parent}{$key};
159 my $temp_dir = tempdir(CLEANUP => 1);
161 if (not defined $cgi_var{dot}) {
162 my $dot_fh = new IO::File "$temp_dir/temp.dot",'w' or
163 die "Unable to open $temp_dir/temp.dot for writing: $!";
164 print {$dot_fh} $dot or die "Unable to print output to the dot file: $!";
165 close $dot_fh or die "Unable to close the dot file: $!";
166 system('dot','-T'.$cgi_var{format},"$temp_dir/temp.dot",'-o',"$temp_dir/temp.$cgi_var{format}") == 0
167 or print "Content-Type: text\n\nDot failed." and die "Dot failed: $?";
168 my $img_fh = new IO::File "$temp_dir/temp.$cgi_var{format}", 'r' or
169 die "Unable to open $temp_dir/temp.$cgi_var{format} for reading: $!";
170 print "Content-Type: $img_types{$cgi_var{format}}\n\n";
175 print "Content-Type: text\n\n";
180 my %_version_relevant_cache;
181 sub version_relevant {
182 my ($version,$test_version,$relevant_versions) = @_;
183 for my $dist_version (@{$relevant_versions}) {
184 print STDERR "Testing $dist_version against $test_version\n";
185 return 1 if $version->isancestor($test_version,$dist_version);