[SCM] Debian package checker branch, master, updated. 2.5.10-9-g99188a5
The following commit has been merged in the master branch:
commit 99188a5bd6f8cec660894e60316e80d6059e4db0
Author: Niels Thykier <niels@thykier.net>
Date: Tue Jul 10 23:32:03 2012 +0200
L::Collect{,::Source}: Add DEFAULT parameter to {X_,}field
This new optional parameter can be used to determine the default value
if a field is missing. This is useful to avoid having to having to
handle "undef" values in some cases.
Signed-off-by: Niels Thykier <niels@thykier.net>
diff --git a/checks/binaries b/checks/binaries
index 07a2b00..c7476c1 100644
--- a/checks/binaries
+++ b/checks/binaries
@@ -105,9 +105,9 @@ my $uses_numpy_c_abi = 0;
my %SONAME;
-$arch = $info->field('architecture')//'';
-$multiarch = $info->field('multi-arch')//'no';
-my $srcpkg = $proc->pkg_src()//'';
+$arch = $info->field ('architecture', '');
+$multiarch = $info->field ('multi-arch', 'no');
+my $srcpkg = $proc->pkg_src;
foreach my $file (sort keys %{$info->objdump_info}) {
my $objdump = $info->objdump_info->{$file};
diff --git a/checks/changes-file b/checks/changes-file
index 919dd2b..0c7a749 100644
--- a/checks/changes-file
+++ b/checks/changes-file
@@ -43,7 +43,7 @@ if (!$info->field('format')) {
# Description is mandated by dak, but only makes sense if binary
# packages are included. Don't tag pure source uploads.
-if (!$info->field('description') && ($info->field('architecture')//'') ne 'source') {
+if (!$info->field ('description') && $info->field ('architecture', '') ne 'source') {
tag 'no-description-in-changes-file';
}
diff --git a/checks/control-file b/checks/control-file
index 9ab8efe..7536c52 100644
--- a/checks/control-file
+++ b/checks/control-file
@@ -309,7 +309,7 @@ sub check_dev_depends {
# Note, we do not check if the -dev package is
# arch:all as well. The version-substvars check
# handles that for us.
- next if ($info->binary_field ($target, 'architecture')//'') eq 'all'
+ next if $info->binary_field ($target, 'architecture', '') eq 'all'
&& $versions[0] =~ /^\s*=\s*\$\{source:Version\}/;
tag 'weak-library-dev-dependency', "$package on $depends[0]";
}
diff --git a/checks/fields b/checks/fields
index 8ab3dc8..69bb103 100644
--- a/checks/fields
+++ b/checks/fields
@@ -439,7 +439,7 @@ if (not defined $info->field('section')) {
}
}
if ($info->is_transitional) {
- my $pri = $info->field ('priority')//'';
+ my $pri = $info->field ('priority', '');
# Cannot use "unfold" as it could emit a tag for priority,
# which will be duplicated below.
$pri =~ s/\n//;
@@ -735,7 +735,7 @@ if ($type eq 'source') {
my $arch_indep_packages = 0;
my $arch_dep_packages = 0;
foreach my $binpkg (keys %$binpkgs) {
- my $arch = $info->binary_field($binpkg, 'architecture')//'';
+ my $arch = $info->binary_field($binpkg, 'architecture', '');
if ($arch eq 'all') {
$arch_indep_packages++;
} else {
@@ -851,14 +851,14 @@ if ($type eq 'source') {
foreach my $binpkg (keys %$binpkgs) {
if ($binpkg =~ m/-dbg$/) {
push @dbg_pkgs, $binpkg;
- } elsif (($info->binary_field($binpkg, 'architecture')//'') ne 'all') {
+ } elsif ($info->binary_field ($binpkg, 'architecture', '') ne 'all') {
push @arch_dep_pkgs, $binpkg;
}
}
foreach (@dbg_pkgs) {
my $deps;
- $deps = ($info->binary_field($_, 'pre-depends')//'') . ', ';
- $deps .= $info->binary_field($_, 'depends');
+ $deps = $info->binary_field($_, 'pre-depends', '') . ', ';
+ $deps .= $info->binary_field($_, 'depends', '');
tag 'dbg-package-missing-depends', $_
unless (grep {my $quoted_name = qr<\Q$_>; $deps =~ m/(?:\s|,|^)$quoted_name(?:\s|,|\z)/} @arch_dep_pkgs);
}
diff --git a/checks/filename-length b/checks/filename-length
index eef9c1e..423bcaa 100644
--- a/checks/filename-length
+++ b/checks/filename-length
@@ -71,7 +71,7 @@ return if $type ne 'source';
# Reset to work with elements of the dsc file.
$len = 0;
-foreach my $entry (split m/\n/o, $info->field('files')//''){
+foreach my $entry (split m/\n/o, $info->field ('files', '')){
my $filename;
my $flen;
$entry =~ s/^\s++//o;
diff --git a/checks/files b/checks/files
index af293d5..87b0824 100644
--- a/checks/files
+++ b/checks/files
@@ -176,8 +176,8 @@ my %linked_against_libvga;
my $py_support_nver = undef;
my $arch_dep_files = 0;
-my $arch = $info->field ('architecture')//'';
-my $isma_same = ($info->field ('multi-arch')//'') eq 'same';
+my $arch = $info->field ('architecture', '');
+my $isma_same = $info->field ('multi-arch', '') eq 'same';
my $ppkg = quotemeta ($pkg);
# read data from objdump-info file
@@ -198,10 +198,10 @@ foreach my $file (sort keys %{$info->objdump_info}) {
#
# Otherwise set it to the empty string to avoid "unitialized value"
# warnings if we end up using it a bit too carelessly.
-$source_pkg = $proc->pkg_src()//'';
+$source_pkg = $proc->pkg_src;
# Get section if available.
-$pkg_section = $info->field('section')//'';
+$pkg_section = $info->field ('section', '');
# find out which files are scripts
my %script = map {$_ => 1} (sort keys %{$info->scripts});
diff --git a/checks/group-checks b/checks/group-checks
index 4bcd86d..b90ce66 100644
--- a/checks/group-checks
+++ b/checks/group-checks
@@ -109,12 +109,12 @@ sub _check_file_overlap {
for (my $i = 0 ; $i < scalar @sorted ; $i++) {
my $proc = $sorted[$i];
my $pinfo = $proc->info;
- my @p = grep { $_ } split /,/o, $pinfo->field ('provides')//'';
+ my @p = grep { $_ } split /,/o, $pinfo->field ('provides', '');
my $prov = Lintian::Relation->new (join (' |̈́ ', $proc->pkg_name, @p));
for (my $j = $i ; $j < scalar @sorted ; $j++) {
my $other = $sorted[$j];
my $oinfo = $other->info;
- my @op = grep { $_ } split /,/o, $oinfo->field ('provides')//'';
+ my @op = grep { $_ } split /,/o, $oinfo->field ('provides', '');
my $oprov = Lintian::Relation->new (join (' | ', $other->pkg_name, @op));
# poor man's "Multi-arch: same" work-around.
next if $proc->pkg_name eq $other->pkg_name;
diff --git a/checks/nmu b/checks/nmu
index 56bf135..e2ddadb 100644
--- a/checks/nmu
+++ b/checks/nmu
@@ -65,7 +65,7 @@ if ($firstline) {
}
my $version = $info->field('version');
-my $maintainer = canonicalize($info->field('maintainer')//'');
+my $maintainer = canonicalize ($info->field ('maintainer', ''));
my $uploaders = $info->field('uploaders');
my $version_nmuness = 0;
diff --git a/checks/version-substvars b/checks/version-substvars
index e1d1ec0..30564ba 100644
--- a/checks/version-substvars
+++ b/checks/version-substvars
@@ -54,7 +54,7 @@ foreach (keys %$binpkgs) {
my ($pkg1, $pkg1_is_any, $pkg2, $pkg2_is_any, $substvar_strips_binNMU);
$pkg1 = $_;
- $pkg1_is_any = (($info->binary_field($pkg1, 'architecture')//'') ne 'all');
+ $pkg1_is_any = ($info->binary_field($pkg1, 'architecture', '') ne 'all');
foreach my $field (@dep_fields) {
next unless $info->binary_field($pkg1, $field);
@@ -63,8 +63,8 @@ foreach (keys %$binpkgs) {
}
}
- foreach (split(m/,/, ($info->binary_field($pkg1, 'pre-depends')//'').', '.
- ($info->binary_field($pkg1, 'depends')//''))) {
+ foreach (split (m/,/, ($info->binary_field($pkg1, 'pre-depends', '').', '.
+ $info->binary_field ($pkg1, 'depends', '')))) {
next unless m/(\S+)\s*\(\s*(\>)?=\s*\${((?:Source-|source:|binary:)Version)}/x;
my $gt = $2//'';
@@ -79,7 +79,7 @@ foreach (keys %$binpkgs) {
unless ($pkg2 =~ /\$\{\S+\}/);
next;
}
- $pkg2_is_any = (($info->binary_field($pkg2, 'architecture')//'') ne 'all');
+ $pkg2_is_any = ($info->binary_field($pkg2, 'architecture', '') ne 'all');
if ($pkg1_is_any) {
if ($pkg2_is_any and $substvar_strips_binNMU) {
diff --git a/debian/changelog b/debian/changelog
index ae6b29b..de0e226 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -29,6 +29,12 @@ lintian (2.5.11) UNRELEASED; urgency=low
* debian/control:
+ [NT] Add (Build-)Depends on libtext-levenshtein-perl.
+ * lib/Lintian/Collect{/Source}.pm:
+ + [NT] Add optional parameter to field (and X_field)
+ methods that denotes the default value if a field is
+ missing. This avoid some boiler plate for callers
+ of the methods.
+
-- Niels Thykier <niels@thykier.net> Tue, 10 Jul 2012 13:21:56 +0200
lintian (2.5.10) unstable; urgency=low
diff --git a/lib/Lintian/Collect.pm b/lib/Lintian/Collect.pm
index 8e0a340..f106776 100644
--- a/lib/Lintian/Collect.pm
+++ b/lib/Lintian/Collect.pm
@@ -75,21 +75,22 @@ sub base_dir {
# information will be retrieved from the file itself.
# sub field Needs-Info <>
sub field {
- my ($self, $field) = @_;
- return $self->_get_field($field);
+ my ($self, $field, $def) = @_;
+ return $self->_get_field ($field, $def);
}
-# $self->_get_field([$name])
+# $self->_get_field([$name[, $def]])
#
# Method getting the fields; this is the backing method of $self->field
#
# It must return either a field (if $name is given) or a hash, where the keys are
-# the name of the fields.
+# the name of the fields. If $name is given and it is not present, then it will
+# return $def (or undef if $def was not given).
#
# It must cache the result if possible, since field and fields are called often.
# sub _get_field Needs-Info <>
sub _get_field {
- my ($self, $field) = @_;
+ my ($self, $field, $def) = @_;
my $fields;
unless (exists $self->{field}) {
my $base_dir = $self->base_dir();
@@ -111,7 +112,7 @@ sub _get_field {
} else {
$fields = $self->{field};
}
- return $fields->{$field} if $field;
+ return $fields->{$field}//$def if $field;
return $fields;
}
@@ -170,13 +171,16 @@ binary / udeb packages and .changes files.
=over 4
-=item field([FIELD])
+=item field([FIELD[, DEFAULT]])
If FIELD is given, this method returns the value of the control field
FIELD in the control file for the package. For a source package, this
is the *.dsc file; for a binary package, this is the control file in
the control section of the package.
+If FIELD is passed but not present, then this method will return
+DEFAULT (if given) or undef.
+
Otherwise this will return a hash of fields, where the key is the field
name (in all lowercase).
diff --git a/lib/Lintian/Collect/Source.pm b/lib/Lintian/Collect/Source.pm
index a4122fc..136d161 100644
--- a/lib/Lintian/Collect/Source.pm
+++ b/lib/Lintian/Collect/Source.pm
@@ -119,13 +119,13 @@ sub binaries {
return $self->{binaries};
}
-# Returns the value of a source field in d/control or undef
+# Returns the value of a source field in d/control or $def//undef
# if that field is not present.
# sub source_field Needs-Info debfiles
sub source_field {
- my ($self, $field) = @_;
+ my ($self, $field, $def) = @_;
$self->_load_dctrl unless exists $self->{source_field};
- return $self->{source_field}{$field} if $field;
+ return $self->{source_field}{$field}//$def if $field;
return $self->{source_field};
}
@@ -134,13 +134,13 @@ sub source_field {
# inheritance from the settings in the source stanza.
# sub binary_field Needs-Info debfiles
sub binary_field {
- my ($self, $package, $field) = @_;
+ my ($self, $package, $field, $def) = @_;
$self->_load_dctrl unless exists $self->{binary_field};
# Check if the package actually exists, otherwise it may create an
# empty entry for it.
if (exists $self->{binary_field}{$package}) {
- return $self->{binary_field}{$package}{$field} if $field;
+ return $self->{binary_field}{$package}{$field}//$def if $field;
return $self->{binary_field}{$package};
}
return;
@@ -366,12 +366,13 @@ Package-Type as value (which should be either C<deb> or C<udeb>
currently). The debfiles collection script must have been run
to make the F<debfiles/control> file available.
-=item binary_field(PACKAGE[, FIELD])
+=item binary_field(PACKAGE[, FIELD[, DEFAULT]])
-Returns the content of the field FIELD for the binary package PACKAGE in
-the F<debian/control> file, or an undef if the field is not present.
-Inheritance of field values from the source section of the control file is
-not implemented. Only the literal value of the field is returned.
+Returns the content of the field FIELD for the binary package PACKAGE
+in the F<debian/control> file, or DEFAULT (defaulting to undef) if the
+field is not present. Inheritance of field values from the source
+section of the control file is not implemented. Only the literal
+value of the field is returned.
If FIELD is not given, return a hashref mapping field names to their
values. This hashref should not be modified.
@@ -455,11 +456,12 @@ object will be empty (always satisfied and implies nothing).
The same as relation(), but ignores architecture restrictions in the
FIELD field.
-=item source_field([FIELD])
+=item source_field([FIELD[, DEFAULT]])
Returns the content of the field FIELD from source package paragraph
-of the F<debian/control> file, or an undef if the field is not
-present. Only the literal value of the field is returned.
+of the F<debian/control> file, or DEFAULT (defaulting to undef) if the
+field is not present. Only the literal value of the field is
+returned.
If FIELD is not given, return a hashref mapping field names to their
values. This hashref should not be modified.
--
Debian package checker
Reply to: