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