pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/lintpkgsrc/files lintpkgsrc: clean up and con...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/b3d284d3505f
branches:  trunk
changeset: 382723:b3d284d3505f
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Aug 03 20:32:55 2022 +0000

description:
lintpkgsrc: clean up and condense comparison of package versions

One less 'eval' to worry about.

diffstat:

 pkgtools/lintpkgsrc/files/lintpkgsrc.pl  |  64 +++++++++++---------------------
 pkgtools/lintpkgsrc/files/t/pkgversion.t |   5 +-
 2 files changed, 25 insertions(+), 44 deletions(-)

diffs (117 lines):

diff -r 8a868698fc1c -r b3d284d3505f pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Wed Aug 03 20:14:16 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Wed Aug 03 20:32:55 2022 +0000
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.47 2022/08/03 20:14:16 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.48 2022/08/03 20:32:55 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -297,12 +297,13 @@
        return $pkgname;
 }
 
-sub convert_to_standard_pkgversion(@) {
-       my ($elem, @temp);
+sub split_pkgversion($) {
+       my ($pkgversion) = @_;
 
        # See pkg_install/lib/dewey.c.
-       # 'nb' has already been handled when we are here.
-       foreach $elem (@_) {
+       my (@temp);
+       my $nb = ($pkgversion =~ s/^(.*)nb(\d+)$/$1/) ? +$2 : 0;
+       foreach my $elem (split(/(\D+)/, lc($pkgversion))) {
                if ($elem =~ /\d/) {
                        push(@temp, $elem);
                } elsif ($elem eq "pl" || $elem eq "." || $elem eq "_") {
@@ -318,50 +319,29 @@
                        push(@temp, ord($elem) - ord("a") + 1);
                }
        }
+       push(@temp, $nb);
        @temp;
 }
 
-sub pkgversioncmp_extract($$) {
-       my ($match, $val) = @_;
-       my ($cmp, @matchlist, @vallist);
+sub pkgversioncmp($$$) {
+       my ($va, $op, $vb) = @_;
 
-       @matchlist = convert_to_standard_pkgversion(split(/(\D+)/, lc($match)));
-       @vallist = convert_to_standard_pkgversion(split(/(\D+)/, lc($val)));
-       $cmp = 0;
-       while ($cmp == 0 && (@matchlist || @vallist)) {
-               $cmp = ((shift @matchlist || 0) <=> (shift @vallist || 0));
-       }
-       $cmp;
-}
-
-# Package version number matching.
-# Also handles 'nb<N>' suffix (checked iff values otherwise identical).
-sub pkgversioncmp($$$) {
-       my ($match, $test, $val) = @_;
-       my ($cmp, $match_nb, $val_nb);
-
-       $match_nb = $val_nb = 0;
-       if ($match =~ /(.*)nb(.*)/) {
-               # Handle nb<N> suffix
-               $match = $1;
-               $match_nb = $2;
+       my @a = split_pkgversion($va);
+       my @b = split_pkgversion($vb);
+       my $cmp = 0;
+       while ($cmp == 0 && (@a || @b)) {
+               $cmp = (shift @a || 0) <=> (shift @b || 0);
        }
 
-       if ($val =~ /(.*)nb(.*)/) {
-               # Handle nb<N> suffix
-               $val = $1;
-               $val_nb = $2;
+       if ($op eq '<') {
+               $cmp < 0;
+       } elsif ($op eq '<=') {
+               $cmp <= 0;
+       } elsif ($op eq '>') {
+               $cmp > 0;
+       } else {
+               $cmp >= 0;
        }
-
-       $cmp = pkgversioncmp_extract($match, $val);
-
-       if (!$cmp) {
-               # Iff otherwise identical, check nb suffix
-               $cmp = pkgversioncmp_extract($match_nb, $val_nb);
-       }
-
-       debug("eval pkgversioncmp $cmp $test 0\n");
-       eval "$cmp $test 0";
 }
 
 # Return a copy of $line in which trivial variable expressions are replaced
diff -r 8a868698fc1c -r b3d284d3505f pkgtools/lintpkgsrc/files/t/pkgversion.t
--- a/pkgtools/lintpkgsrc/files/t/pkgversion.t  Wed Aug 03 20:14:16 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/pkgversion.t  Wed Aug 03 20:32:55 2022 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: pkgversion.t,v 1.4 2022/08/03 18:51:56 rillig Exp $
+# $NetBSD: pkgversion.t,v 1.5 2022/08/03 20:32:55 rillig Exp $
 
 use strict;
 use warnings;
 use Test;
 
-BEGIN { plan tests => 5, onfail => sub { die } }
+BEGIN { plan tests => 6, onfail => sub { die } }
 
 require('../lintpkgsrc.pl');
 
@@ -13,3 +13,4 @@
 ok(pkgversioncmp('3.4', '>=', '3.4.0.0.0'), 1);
 ok(pkgversioncmp('3.4nb13', '>=', '3.4'), 1);
 ok(pkgversioncmp('3.4nb13', '<', '3.4'), '');
+ok(pkgversioncmp('3.4nb13', '>', '3.4nb5'), 1);



Home | Main Index | Thread Index | Old Index