]> git.donarmstrong.com Git - wannabuild.git/blob - bin/keep-latest
Merge branch 'edos-debcheck' of git://git.debian.org/users/nomeata/wanna-build into...
[wannabuild.git] / bin / keep-latest
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use WannaBuild; # for version compare
7
8 if (!@ARGV) {
9         print STDERR "Usage: $0 arch Packages1 Packages2 ..\n";
10         print STDERR "\n";
11         print STDERR "This perl scripts reads the Packages files given on the command line and\n";
12         print STDERR "outputs a Packages file which contians each package at most\n";
13         print STDERR "once, using the one with the highest version number.\n";
14         print STDERR "";
15         print STDERR "Since it only looks at Package:, Version: and Architecture:, it works with\n";
16         print STDERR "Sources files as well\n";
17         print STDERR "\n";
18         print STDERR "It throws out any package not arch \"all\" or the given architecture.\n";
19         print STDERR "Pass \"source\" to keep all entries.\n";
20
21         exit 1;
22 }
23
24 my %version;
25 my %data;
26
27 my $arch = shift @ARGV;
28
29 local($/) = ""; # read in paragraph mode
30 while (<>) {
31         my( $version, $name, $architecture );
32         $architecture="none"; # better to keep an entry too much than to delete an entry
33         /^Package:\s*(\S+)$/mi and $name = $1;
34         /^Version:\s*(\S+)$/mi and $version = $1;
35         /^Architecture:\s*(\S+)$/mi and $architecture = $1;
36         if (!defined $name or !defined $version) {
37                 warn "Stanza without Package or Version\n";
38                 next;
39         }
40         if ($arch ne "source" && defined $architecture && $architecture ne "all" && $architecture ne $arch) {
41                 next;
42         }
43         my $key = $name;
44
45         if ((!exists $version{$key}) or version_less($version{$key},$version)) {
46                 $version{$key} = $version;
47                 $data{$key} = $_;
48         }
49 }
50
51 foreach (values %data) {
52         s/\n*$/\n\n/;# always one empty line to separate stanzas
53         print;
54 }
55