]> git.donarmstrong.com Git - debbugs.git/blob - examples/debian/versions/merge-versions.pl
the versions database is rebuilt each time
[debbugs.git] / examples / debian / versions / merge-versions.pl
1 #! /usr/bin/perl -w
2 use strict;
3 use File::Find;
4 use Debbugs::Versions;
5 use Debbugs::Versions::Dpkg;
6
7 my %pkgs;
8
9 sub search {
10     return unless -f;
11     my ($pkg) = split /_/;
12     push @{$pkgs{$pkg}}, "$File::Find::dir/$_";
13 }
14
15 find(\&search, 'cl-data');
16
17 for my $pkg (sort keys %pkgs) {
18     print STDERR "$pkg\n";
19     my $tree = Debbugs::Versions->new(\&Debbugs::Versions::Dpkg::vercmp);
20     for my $file (@{$pkgs{$pkg}}) {
21         unless (open FILE, "< $file") {
22             warn "can't open $file: $!\n";
23             next;
24         }
25         $tree->load(*FILE);
26         close FILE;
27     }
28     my $pkghash = substr $pkg, 0, 1;
29     unless (-d "pkg/$pkghash") {
30         unless (mkdir "pkg/$pkghash") {
31             warn "can't mkdir pkg/$pkghash: $!\n";
32             next;
33         }
34     }
35     unless (open OUT, "> pkg/$pkghash/$pkg") {
36         warn "can't open pkg/$pkghash/$pkg for writing: $!\n";
37         next;
38     }
39     $tree->save(*OUT);
40     close OUT;
41 }