From: Joachim Breitner Date: Wed, 29 Jul 2009 13:53:36 +0000 (+0200) Subject: bin/keep-latest X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=08c7734af06cb4e2f4eb4117accf1e586d2a7dc0;p=wannabuild.git bin/keep-latest 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 --- diff --git a/bin/keep-latest b/bin/keep-latest new file mode 100755 index 0000000..eabcc10 --- /dev/null +++ b/bin/keep-latest @@ -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; +} +