pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/lintpkgsrc/files



Module Name:    pkgsrc
Committed By:   rillig
Date:           Wed Aug  3 20:32:55 UTC 2022

Modified Files:
        pkgsrc/pkgtools/lintpkgsrc/files: lintpkgsrc.pl
        pkgsrc/pkgtools/lintpkgsrc/files/t: pkgversion.t

Log Message:
lintpkgsrc: clean up and condense comparison of package versions

One less 'eval' to worry about.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r1.4 -r1.5 pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
diff -u pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.47 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.48
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.47 Wed Aug  3 20:14:16 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Wed Aug  3 20:32:55 2022
@@ -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 @@ sub canonicalize_pkgname($) {
        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 @@ sub convert_to_standard_pkgversion(@) {
                        push(@temp, ord($elem) - ord("a") + 1);
                }
        }
+       push(@temp, $nb);
        @temp;
 }
 
-sub pkgversioncmp_extract($$) {
-       my ($match, $val) = @_;
-       my ($cmp, @matchlist, @vallist);
-
-       @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);
+       my ($va, $op, $vb) = @_;
 
-       $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;
-       }
-
-       $cmp = pkgversioncmp_extract($match, $val);
-
-       if (!$cmp) {
-               # Iff otherwise identical, check nb suffix
-               $cmp = pkgversioncmp_extract($match_nb, $val_nb);
+       if ($op eq '<') {
+               $cmp < 0;
+       } elsif ($op eq '<=') {
+               $cmp <= 0;
+       } elsif ($op eq '>') {
+               $cmp > 0;
+       } else {
+               $cmp >= 0;
        }
-
-       debug("eval pkgversioncmp $cmp $test 0\n");
-       eval "$cmp $test 0";
 }
 
 # Return a copy of $line in which trivial variable expressions are replaced

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.4 pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.5
--- pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.4 Wed Aug  3 18:51:56 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t     Wed Aug  3 20:32:55 2022
@@ -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'), 1)
 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