[lintian] 01/02: c/fields.pm: Remove some duplicate calls to $info->field
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit 640e5d1cec9efa694fc8128aa94084f718082f92
Author: Niels Thykier <niels@thykier.net>
Date: Tue Feb 24 21:56:44 2015 +0100
c/fields.pm: Remove some duplicate calls to $info->field
Replace:
if (defined $info->field(X)) {
my $y = $info->field(X);
...;
}
with
if (my $y = $info->field(X)) {
...;
}
The latter is slightly shorter and avoids a duplicate lookup. Note
that I have generally not done this for "negative" tests, where we
check for the absence of the field in the "if".
Signed-off-by: Niels Thykier <niels@thykier.net>
---
checks/fields.pm | 50 ++++++++++++++------------------------------------
1 file changed, 14 insertions(+), 36 deletions(-)
diff --git a/checks/fields.pm b/checks/fields.pm
index dd58d12..b0575de 100644
--- a/checks/fields.pm
+++ b/checks/fields.pm
@@ -232,8 +232,7 @@ sub run {
#---- Format
if ($type eq 'source') {
- my $format = $info->field('format');
- if (defined($format)) {
+ if (my $format = $info->field('format')) {
my $supported = 0;
foreach my $f (@supported_source_formats){
if($format =~ /^\s*$f\s*\z/){
@@ -348,8 +347,7 @@ sub run {
#---- Multi-Arch
- if (defined $info->field('multi-arch')){
- my $march = $info->field('multi-arch');
+ if (my $march = $info->field('multi-arch')){
unfold('multi-arch', \$march);
tag 'unknown-multi-arch-value', $pkg, $march
unless $march =~ m/^(?:no|foreign|allowed|same)$/o;
@@ -418,9 +416,7 @@ sub run {
#---- Subarchitecture (udeb)
- if (defined $info->field('subarchitecture')) {
- my $subarch = $info->field('subarchitecture');
-
+ if (my $subarch = $info->field('subarchitecture')) {
unfold('subarchitecture', \$subarch);
}
@@ -469,15 +465,10 @@ sub run {
#---- Source
- if (not defined $info->field('source')) {
- # Optional in binary packages, required in source packages, but we
- # cannot check it as dpkg-source(1) refuses to unpack source packages
- # without this field (and fields indirectly depends on unpacked). So
- # "pass"...
- 1;
- } else {
- my $source = $info->field('source');
-
+ # Optional in binary packages, required in source packages, but we
+ # cannot check it as dpkg-source(1) refuses to unpack source packages
+ # without this field (and fields indirectly depends on unpacked)...
+ if (my $source = $info->field('source')) {
unfold('source', \$source);
if ($type eq 'source') {
@@ -503,9 +494,7 @@ sub run {
#---- Essential
- if (defined $info->field('essential')) {
- my $essential = $info->field('essential');
-
+ if (my $essential = $info->field('essential')) {
unfold('essential', \$essential);
tag 'essential-in-source-package' if ($type eq 'source');
@@ -597,8 +586,7 @@ sub run {
#--- Homepage
- if (defined $info->field('homepage')) {
- my $homepage = $info->field('homepage');
+ if (my $homepage = $info->field('homepage')) {
my $orig = $homepage;
unfold('homepage', \$homepage);
@@ -639,9 +627,7 @@ sub run {
#---- Installer-Menu-Item (udeb)
- if (defined $info->field('installer-menu-item')) {
- my $menu_item = $info->field('installer-menu-item');
-
+ if (my $menu_item = $info->field('installer-menu-item')) {
unfold('installer-menu-item', \$menu_item);
$menu_item =~ /^\d+$/ or tag 'bad-menu-item', $menu_item;
@@ -1176,9 +1162,7 @@ sub run {
#----- Origin
- if (defined $info->field('origin')) {
- my $origin = $info->field('origin');
-
+ if (my $origin = $info->field('origin')) {
unfold('origin', \$origin);
tag 'redundant-origin-field' if lc($origin) eq 'debian';
@@ -1186,9 +1170,7 @@ sub run {
#----- Bugs
- if (defined $info->field('bugs')) {
- my $bugs = $info->field('bugs');
-
+ if (my $bugs = $info->field('bugs')) {
unfold('bugs', \$bugs);
tag 'redundant-bugs-field'
@@ -1197,9 +1179,7 @@ sub run {
#----- Python-Version
- if (defined $info->field('python-version')) {
- my $pyversion = $info->field('python-version');
-
+ if (my $pyversion = $info->field('python-version')) {
unfold('python-version', \$pyversion);
my @valid = (
@@ -1240,9 +1220,7 @@ sub run {
#----- Dm-Upload-Allowed
- if (defined $info->field('dm-upload-allowed')) {
- my $dmupload = $info->field('dm-upload-allowed');
-
+ if (my $dmupload = $info->field('dm-upload-allowed')) {
tag 'dm-upload-allowed-is-obsolete';
unfold('dm-upload-allowed', \$dmupload);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: