summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2008-11-29 02:19:38 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2008-11-29 02:19:38 -0800
commit6e99286277af84e850548f651f9ecdd88e455080 (patch)
tree1024a888b63c751248c38fae89b322e224ba8331 /PatchIndexer.pm
parentRename for understanding. (diff)
downloadmysql-extras-6e99286277af84e850548f651f9ecdd88e455080.tar.gz
mysql-extras-6e99286277af84e850548f651f9ecdd88e455080.tar.bz2
mysql-extras-6e99286277af84e850548f651f9ecdd88e455080.zip
Add ability to select a subset of patches easily for testing.
Diffstat (limited to 'PatchIndexer.pm')
-rw-r--r--PatchIndexer.pm80
1 files changed, 78 insertions, 2 deletions
diff --git a/PatchIndexer.pm b/PatchIndexer.pm
index 3d5f3e3..b3db2ed 100644
--- a/PatchIndexer.pm
+++ b/PatchIndexer.pm
@@ -1,6 +1,6 @@
#!/usr/bin/perl
package PatchIndexer;
-#use Data::Dumper;
+use Data::Dumper;
use Clone qw(clone);
use warnings;
use strict;
@@ -8,7 +8,7 @@ use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter AutoLoader);
-@EXPORT = qw( parseIndex printIndex );
+@EXPORT = qw( parseIndex printIndex selectPatches );
sub parseIndex {
my $fh = shift;
@@ -109,3 +109,79 @@ sub printIndex {
}
return $os;
}
+
+sub selectPatches {
+ my (@index, $pn, $pv, @newindex);
+
+ $_ = shift;
+ @index = @{ $_ };
+
+ $pn = shift;
+ {
+ $_ = shift;
+ my @_pv = split /\./, $_;
+ until($#_pv >= 3) { push @_pv, 0; };
+ $pv = join('.', @_pv);
+ }
+
+ printf "PN: %s\n", $pn;
+ printf "PV: %s\n", $pv;
+ INDEX: foreach my $i (@index) {
+ my ($match_pn, $match_pv);
+ $match_pn = $match_pv = 0;
+ TESTPN: foreach my $testpn ( @{ $i->{pn} } ) {
+ printf("testing pn='%s' against '%s' ", $pn, $testpn);
+ if("$pn" eq "$testpn") {
+ printf("PASS\n");
+ $match_pn = 1;
+ last TESTPN;
+ } else {
+ printf("FAIL\n");
+ }
+ }
+ TESTPV: foreach my $testpv ( @{ $i->{ver} } ) {
+ my @v = @$testpv;
+ printf("testing pv='%s' against '%s'-'%s' ", $pv, $v[0], $v[1]);
+ if(pvGte($pv,$v[0]) and pvLte($pv,$v[1])) {
+ printf("PASS\n");
+ $match_pv = 1;
+ last TESTPV;
+ } else {
+ printf("FAIL\n");
+ }
+ }
+ if($match_pn == 1 and $match_pv == 1) {
+ printf "match on %s\n", $i->{patch};
+ push @newindex, $i;
+ } else {
+ printf "no match on %s\n", $i->{patch};
+ }
+ }
+ return @newindex;
+}
+
+sub pvCmp {
+ my (@v1, @v2);
+ @v1 = split(/\./, shift);
+ @v2 = split(/\./, shift);
+ for(my $i = 0; $i < 4; $i++) {
+ if($v1[$i] > $v2[$i]) {
+ return 1;
+ } elsif($v1[$i] < $v2[$i]) {
+ return -1;
+ }
+ }
+ return 0;
+}
+sub pvGt {
+ return pvCmp(shift, shift) > 0;
+}
+sub pvLt {
+ return pvCmp(shift, shift) < 0;
+}
+sub pvGte {
+ return pvCmp(shift, shift) >= 0;
+}
+sub pvLte {
+ return pvCmp(shift, shift) <= 0;
+}