]> git.donarmstrong.com Git - wannabuild.git/commitdiff
bin/keep-latest
authorJoachim Breitner <nomeata@debian.org>
Wed, 29 Jul 2009 13:53:36 +0000 (15:53 +0200)
committerJoachim Breitner <nomeata@debian.org>
Wed, 29 Jul 2009 13:53:36 +0000 (15:53 +0200)
Usage: ./bin/keep-latest Packages1 Packages2 ..

This perl scripts reads the Packages files given on the command line and
outputs a Packages file which contians each package exactly once, using
the one with the highest version number.
Since it only looks at Package: and Version:, it works with Sources
files as well

bin/keep-latest [new file with mode: 0755]

diff --git a/bin/keep-latest b/bin/keep-latest
new file mode 100755 (executable)
index 0000000..eabcc10
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use WannaBuild; # for version compare
+
+if (!@ARGV) {
+       print STDERR "Usage: $0 Packages1 Packages2 ..\n";
+       print STDERR "\n";
+       print STDERR "This perl scripts reads the Packages files given on the command line and\n";
+       print STDERR "outputs a Packages file which contians each package exactly once, using the\n";
+       print STDERR "one with the highest version number.\n";
+       print STDERR "";
+       print STDERR "Since it only looks at Package: and Version:, it works with Sources files\n";
+       print STDERR "as well\n";
+       exit 1;
+}
+
+my %version;
+my %data;
+
+local($/) = ""; # read in paragraph mode
+while (<>) {
+       my( $version, $name );
+       /^Package:\s*(\S+)$/mi and $name = $1;
+       /^Version:\s*(\S+)$/mi and $version = $1;
+       if (!defined $name or !defined $version) {
+               warn "Stanza without Package or Version\n";
+               next;
+       }
+
+       if ((!exists $version{$name}) or version_less($version{name},$version)) {
+               $version{$name} = $version;
+               $data{$name} = $_;
+       }
+}
+
+foreach (values %data) {
+       s/\n*$/\n\n/;# always one empty line to separate stanzas
+       print;
+}
+