]> git.deb.at Git - deb/packages.git/commitdiff
Support "changelog:" short links
authorFrank Lichtenheld <frank@lichtenheld.de>
Sun, 15 Apr 2007 00:28:12 +0000 (02:28 +0200)
committerFrank Lichtenheld <frank@lichtenheld.de>
Sun, 15 Apr 2007 00:28:12 +0000 (02:28 +0200)
Generate a map file for mod_rewrite since we need to
map binary packages to source packages.

bin/create_changelogs_map [new file with mode: 0755]
conf/apache.conf.sed.in
cron.d/400changelogs_map [new file with mode: 0755]

diff --git a/bin/create_changelogs_map b/bin/create_changelogs_map
new file mode 100755 (executable)
index 0000000..fbee3f2
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use DB_File;
+
+use lib './lib';
+
+use Deb::Versions;
+
+unless (@ARGV == 2) {
+       die "Usage: create_changelogs_map <db_dir> <changelogs_map_file>\n";
+}
+
+my ($dbdir, $outfile) = @ARGV;
+
+tie my %src_packages, 'DB_File', "$dbdir/sources_small.db",
+    O_RDONLY, 0666, $DB_BTREE
+    or die "couldn't tie DB $dbdir/sources_small.db: $!";
+tie my %src2bin, 'DB_File', "$dbdir/sources_packages.db",
+    O_RDONLY, 0666, $DB_BTREE
+    or die "couldn't open $dbdir/sources_packages.db: $!";
+
+open my $out, '>', "$outfile.new"
+    or die "couldn't open $outfile.new: $!";
+
+sub get_dir_from_name {
+    my $name = shift;
+
+    if ($name =~ /^(lib.)/o) {
+       return "$1/$name";
+    } else {
+       return substr( $name, 0, 1 )."/$name";
+    }
+}
+
+use Data::Dumper;
+my %bin;
+while (my ($source, $data) = each %src_packages) {
+    my @src = map { [ split(/\s+/) ] } split( /\0/, $data );
+    my $newest = (sort( { version_cmp($b->[-1],$a->[-1]) } @src))[0];
+    my ($section, $version) = @{$newest}[2,5];
+    my $directory = get_dir_from_name($source);
+#    warn "src=$source sect=$section v=$version dir=$directory\n";
+
+    my $bin_data = $src2bin{$source};
+    unless ($bin_data) {
+       warn "no binary data found for $source\n";
+       # source packages without binaries have most
+       # likely been succeded
+       next;
+    }
+
+    print $out "$source\tpool/$section/$directory/current/changelog\n";
+
+    my @bin = map { [ split(/\s+/) ] } split( /\0/, $bin_data );
+    my %seen;
+    foreach (@bin) {
+       my ($pkg, $ver) = @{$_}[2,3];
+       next if $seen{"$pkg/$ver"}++; # weed out multiple arches/suites faster
+       if ($bin{$pkg}
+           && ($bin{$pkg}{source} ne $source)
+           && (version_cmp($bin{$pkg}{version},$ver) > 0)) {
+           warn "ignore $pkg/$ver from $source for ".
+               "$pkg/$bin{$pkg}{version} from $bin{$pkg}{source}\n";
+           next;
+       } else {
+           $bin{$pkg} = { version => $ver, source => $source,
+                          target => "$section/$directory" };
+       }
+    }
+}
+
+while (my ($pkg, $data) = each %bin) {
+#    warn "pkg=$pkg v=$data->{version} src=$data->{source} tgt=$data->{target}\n";
+    print $out "$pkg\tpool/$data->{target}/current/changelog\n";
+}
+
+close $out or warn $!;
+rename("$outfile.new", $outfile);
index 36032d7b2c9be8fe45ff4e2f60ce49ea4c03ad8c..2b6913b8aa267e5a61dc1f8456637b6bb47acddb 100644 (file)
    RewriteLog /var/log/apache2/rewrite.log
    RewriteLogLevel 0
 
+   RewriteMap changelog-url txt:%TOPDIR%/files/changelogs-map
+
    RewriteRule ^/cgi-bin/search_packages.pl(.*)$ /search$1
    RewriteRule ^/cgi-bin/search_contents.pl(.*)$ /search$1
    RewriteRule ^/unstable/newpkg_([a-z]+)\.[a-z]+\.rdf /unstable/$1/newpkg?format=rss [R=permanent,L]
 #   RewriteRule ^/$ http://www.debian.org/distrib/packages
    RewriteRule ^/$ /index.html [L]
    RewriteRule ^/([^/+]*)([+])([^/]*)$ "/$1%%{%}2B$3" [N]
+   RewriteRule ^/changelog:(.+)$  http://%SITE%/changelogs/${changelog-url:$1} [R,L,NE]
    RewriteRule ^/src:([^/]+)$ /source/$1 [R,L,NE]
 
    RewriteRule ^/(.+)$ /cgi-bin/dispatcher.pl/$1 [L,PT]
diff --git a/cron.d/400changelogs_map b/cron.d/400changelogs_map
new file mode 100755 (executable)
index 0000000..71469d2
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+. `dirname $0`/../config.sh
+
+cd "$topdir"
+
+date
+./bin/create_changelogs_map "$filesdir/db/" "$filesdir/changelogs-map"
+date