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:           Thu Aug 11 07:18:47 UTC 2022

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

Log Message:
lintpkgsrc: cleanup: split PkgDb::pkgver into separate subroutines


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r1.11 -r1.12 pkgsrc/pkgtools/lintpkgsrc/files/t/packages.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.73 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.74
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.73 Thu Aug 11 07:07:26 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Thu Aug 11 07:18:47 2022
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.73 2022/08/11 07:07:26 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.74 2022/08/11 07:18:47 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -123,17 +123,16 @@ sub pkgvers_all($self) {
        map { $_->pkgver } $self->pkgs;
 }
 
-# pkgver($pkgbase) returns all PkgVers of the given pkgbase, sorted by
-# version in decreasing alphabetical(!) order.
-#
-# pkgver($pkgbase, $pkgversion) returns the package, or undef.
-sub pkgver($self, $pkgbase = undef, $pkgversion = undef) {
+# All PkgVers of the given pkgbase, sorted by version in decreasing
+# alphabetical(!) order.
+sub pkgvers_by_pkgbase($self, $pkgbase) {
+       my $pkgs = $self->{$pkgbase};
+       defined $pkgs ? $pkgs->pkgver : ();
+}
+
+sub pkgver($self, $pkgbase, $pkgversion) {
        my $pkgs = $self->{$pkgbase};
-       defined $pkgs && defined $pkgversion
-           ? $pkgs->pkgver($pkgversion)
-           : defined $pkgs
-           ? $pkgs->pkgver
-           : ();
+       defined $pkgs ? $pkgs->pkgver($pkgversion) : undef;
 }
 
 # pkgs() returns all Pkgs, sorted by pkgbase.
@@ -834,8 +833,9 @@ sub package_globmatch($pkgmatch) {
                # (package)(cmp)(pkgversion)
                my ($test, @pkgvers);
 
+               # TODO: rename $matchpkgname to be more accurate.
                ($matchpkgname, $test, $matchver) = ($1, $2, $3);
-               if (@pkgvers = $pkgdb->pkgver($matchpkgname)) {
+               if (@pkgvers = $pkgdb->pkgvers_by_pkgbase($matchpkgname)) {
                        foreach my $pkgver (@pkgvers) {
                                if ($test eq '-') {
                                        if ($pkgver->pkgversion eq $matchver) {
@@ -1388,7 +1388,7 @@ sub remove_distfiles($pkgsrcdir, $pkgdis
        my @installed;
        foreach my $pkgname (sort @pkgs) {
                if ($pkgname =~ /^([^*?[]+)-([\d*?[].*)/) {
-                       foreach my $pkgver ($pkgdb->pkgver($1)) {
+                       foreach my $pkgver ($pkgdb->pkgvers_by_pkgbase($1)) {
                                next if $pkgver->var('dir') =~ /-current/;
                                push @installed, $pkgver;
                                last;
@@ -1557,7 +1557,7 @@ sub check_outdated_installed_packages($p
                print $_;
                next unless $pkgname =~ /^([^*?[]+)-([\d*?[].*)/;
 
-               foreach my $pkgver ($pkgdb->pkgver($1)) {
+               foreach my $pkgver ($pkgdb->pkgvers_by_pkgbase($1)) {
                        next if $pkgver->var('dir') =~ /-current/;
                        push @update, $pkgver;
                        last;

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.11 pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.12
--- pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.11  Thu Aug 11 07:07:27 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t       Thu Aug 11 07:18:47 2022
@@ -1,4 +1,4 @@
-# $NetBSD: packages.t,v 1.11 2022/08/11 07:07:27 rillig Exp $
+# $NetBSD: packages.t,v 1.12 2022/08/11 07:18:47 rillig Exp $
 
 use strict;
 use warnings;
@@ -56,10 +56,10 @@ sub test_pkgdb() {
        my $actual = join(', ', map { $_->pkgname } $pkgdb->pkgvers_all);
        ok($actual, 'base-8.0, base-1.0, other-5.7');
 
-       $actual = join(', ', map { $_->pkgname } $pkgdb->pkgver('base'));
+       $actual = join(', ', map { $_->pkgname } $pkgdb->pkgvers_by_pkgbase('base'));
        ok($actual, 'base-8.0, base-1.0');
 
-       $actual = join(', ', map { $_->pkgname } $pkgdb->pkgver('unknown'));
+       $actual = join(', ', map { $_->pkgname } $pkgdb->pkgvers_by_pkgbase('unknown'));
        ok($actual, '');
 
        ok($pkgdb->pkgver('base', '1.0')->pkgname, 'base-1.0');
@@ -93,7 +93,7 @@ sub test_package_variables() {
        ok($versions, '2.0, 1.5, 1.10, 1.0');
 
        # The versioned packages are sorted in decreasing alphabetical order.
-       my @pkgvers = $pkgdb->pkgver('pkgbase');
+       my @pkgvers = $pkgdb->pkgvers_by_pkgbase('pkgbase');
        ok(join(', ', map { $_->pkgversion } @pkgvers), '2.0, 1.5, 1.10, 1.0');
        ok($pkgvers[0], $pkgbase_2_0);
        ok($pkgvers[3], $pkgbase_1_0);



Home | Main Index | Thread Index | Old Index