]> git.donarmstrong.com Git - wannabuild.git/blob - bin/keep-latest
bin/keep-latest: Consider architecture field
[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 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/architecture pair 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         exit 1;
18 }
19
20 my %version;
21 my %data;
22
23 local($/) = ""; # read in paragraph mode
24 while (<>) {
25         my( $version, $name, $architecture );
26         $architecture="none"; # better to keep an entry too much than to delete an entry
27         /^Package:\s*(\S+)$/mi and $name = $1;
28         /^Version:\s*(\S+)$/mi and $version = $1;
29         /^Architecture:\s*(\S+)$/mi and $architecture = $1;
30         if (!defined $name or !defined $version) {
31                 warn "Stanza without Package or Version\n";
32                 next;
33         }
34         my $key = $name."_".$architecture;
35
36         if ((!exists $version{$key}) or version_less($version{$key},$version)) {
37                 $version{$key} = $version;
38                 $data{$key} = $_;
39         }
40 }
41
42 foreach (values %data) {
43         s/\n*$/\n\n/;# always one empty line to separate stanzas
44         print;
45 }
46