This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=f506e5dbc94393e9b5a8783d992815dca8ea7a2b

commit f506e5dbc94393e9b5a8783d992815dca8ea7a2b
Author: Guillem Jover <[email protected]>
AuthorDate: Tue Feb 21 02:21:48 2023 +0100

    perl: Use fixed string comparisons for field name matches
    
    We can replace all these regex comparisons with fixed string matches,
    including the ones that are case-insensitive as the fields are always
    normalized to their preferred form.
    
    Warned-by: perlcritic
    Addresses: RegularExpressions::ProhibitFixedStringMatches
---
 scripts/Dpkg/Changelog.pm  |  6 +++---
 scripts/dpkg-genchanges.pl | 18 +++++++++---------
 scripts/dpkg-gencontrol.pl | 12 ++++++------
 scripts/dpkg-source.pl     | 18 +++++++++---------
 4 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/scripts/Dpkg/Changelog.pm b/scripts/Dpkg/Changelog.pm
index e36aca527..8ac81d336 100644
--- a/scripts/Dpkg/Changelog.pm
+++ b/scripts/Dpkg/Changelog.pm
@@ -519,9 +519,9 @@ sub _format_dpkg {
     my $opts = $src->get_optional_fields();
     my %closes;
     foreach my $f (keys %{$opts}) {
-        if ($f =~ /^Urgency$/i) {
+        if ($f eq 'Urgency') {
             # Already handled.
-        } elsif ($f =~ /^Closes$/i) {
+        } elsif ($f eq 'Closes') {
            $closes{$_} = 1 foreach (split(/\s+/, $opts->{Closes}));
        } else {
             field_transfer_single($opts, $c, $f);
@@ -539,7 +539,7 @@ sub _format_dpkg {
        # handle optional fields
        $opts = $bin->get_optional_fields();
         foreach my $f (keys %{$opts}) {
-            if ($f =~ /^Closes$/i) {
+            if ($f eq 'Closes') {
                $closes{$_} = 1 foreach (split(/\s+/, $opts->{Closes}));
             } elsif (not exists $c->{$f}) {
                 # Don't overwrite an existing field
diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl
index 2cc4861a1..54413dbd6 100755
--- a/scripts/dpkg-genchanges.pl
+++ b/scripts/dpkg-genchanges.pl
@@ -236,11 +236,11 @@ if (! $is_backport && defined $prev_changelog &&
 my $src_fields = $control->get_source();
 foreach my $f (keys %{$src_fields}) {
     my $v = $src_fields->{$f};
-    if ($f =~ m/^Source$/) {
+    if ($f eq 'Source') {
         set_source_name($v);
-    } elsif ($f =~ m/^Section$|^Priority$/i) {
+    } elsif (any { $f eq $_ } qw(Section Priority)) {
         $sourcedefault{$f} = $v;
-    } elsif ($f =~ m/^Description$/i) {
+    } elsif ($f eq 'Description') {
         # Description in changes is computed, do not copy this field, only
         # initialize the description substvars.
         $substvars->set_desc_substvars($v);
@@ -397,11 +397,11 @@ foreach my $pkg ($control->get_packages()) {
     foreach my $f (keys %{$pkg}) {
         my $v = $pkg->{$f};
 
-        if ($f =~ m/^Section$/) {
+        if ($f eq 'Section') {
             $file2ctrlsec{$_} = $v foreach @files;
-        } elsif ($f =~ m/^Priority$/) {
+        } elsif ($f eq 'Priority') {
             $file2ctrlpri{$_} = $v foreach @files;
-        } elsif ($f =~ m/^Architecture$/) {
+        } elsif ($f eq 'Architecture') {
            if (build_has_any(BUILD_ARCH_DEP) and
                (any { debarch_is($host_arch, $_) } debarch_list_parse($v, 
positive => 1))) {
                $v = $host_arch;
@@ -409,7 +409,7 @@ foreach my $pkg ($control->get_packages()) {
                $v = '';
            }
            push(@archvalues, $v) if $v and not $archadded{$v}++;
-        } elsif ($f =~ m/^Description$/) {
+        } elsif ($f eq 'Description') {
             # Description in changes is computed, do not copy this field
        } else {
             field_transfer_single($pkg, $fields, $f);
@@ -420,9 +420,9 @@ foreach my $pkg ($control->get_packages()) {
 # Scan fields of dpkg-parsechangelog
 foreach my $f (keys %{$changelog}) {
     my $v = $changelog->{$f};
-    if ($f =~ m/^Source$/i) {
+    if ($f eq 'Source') {
         set_source_name($v);
-    } elsif ($f =~ m/^Maintainer$/i) {
+    } elsif ($f eq 'Maintainer') {
        $fields->{'Changed-By'} = $v;
     } else {
         field_transfer_single($changelog, $fields, $f);
diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl
index 8fedac2fc..8c210f9c4 100755
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -194,9 +194,9 @@ $substvars->set_msg_prefix(sprintf(g_('package %s: '), 
$pkg->{Package}));
 # Scan source package
 my $src_fields = $control->get_source();
 foreach my $f (keys %{$src_fields}) {
-    if ($f =~ m/^Source$/) {
+    if ($f eq 'Source') {
         set_source_name($src_fields->{$f});
-    } elsif ($f =~ m/^Description$/) {
+    } elsif ($f eq 'Description') {
         # Description in binary packages is not inherited, do not copy this
         # field, only initialize the description substvars.
         $substvars->set_desc_substvars($src_fields->{$f});
@@ -212,7 +212,7 @@ foreach my $f (keys %{$pkg}) {
 
     if (field_get_dep_type($f)) {
        # Delay the parsing until later
-    } elsif ($f =~ m/^Architecture$/) {
+    } elsif ($f eq 'Architecture') {
        my $host_arch = get_host_arch();
 
        if (debarch_eq('all', $v)) {
@@ -236,11 +236,11 @@ foreach my $f (keys %{$pkg}) {
 foreach my $f (keys %{$changelog}) {
     my $v = $changelog->{$f};
 
-    if ($f =~ m/^Source$/) {
+    if ($f eq 'Source') {
         set_source_name($v);
-    } elsif ($f =~ m/^Version$/) {
+    } elsif ($f eq 'Version') {
         # Already handled previously.
-    } elsif ($f =~ m/^Maintainer$/) {
+    } elsif ($f eq 'Maintainer') {
         # That field must not be copied from changelog even if it's
         # allowed in the binary package control information
     } else {
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index aa5bb9fa5..664f39c76 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -275,13 +275,13 @@ if ($options{opmode} =~ 
/^(build|print-format|(before|after)-build|commit)$/) {
     foreach my $f (keys %{$src_fields}) {
         my $v = $src_fields->{$f};
 
-        if ($f =~ m/^Source$/i) {
+        if ($f eq 'Source') {
             set_source_name($v);
             $fields->{$f} = $v;
-        } elsif ($f =~ m/^Uploaders$/i) {
+        } elsif ($f eq 'Uploaders') {
             # Merge in a single-line.
             ($fields->{$f} = $v) =~ s/\s*[\r\n]\s*/ /g;
-        } elsif ($f =~ m/^Build-(?:Depends|Conflicts)(?:-Arch|-Indep)?$/i) {
+        } elsif (any { $f eq $_ } field_list_src_dep()) {
            my $dep;
             my $type = field_get_dep_type($f);
            $dep = deps_parse($v, build_dep => 1, union => $type eq 'union');
@@ -334,7 +334,7 @@ if ($options{opmode} =~ 
/^(build|print-format|(before|after)-build|commit)$/) {
         foreach my $f (keys %{$pkg}) {
             my $v = $pkg->{$f};
 
-            if ($f =~ m/^Architecture$/) {
+            if ($f eq 'Architecture') {
                 # Gather all binary architectures in one set. 'any' and 'all'
                 # are special-cased as they need to be the only ones in the
                 # current stanza if present.
@@ -352,7 +352,7 @@ if ($options{opmode} =~ 
/^(build|print-format|(before|after)-build|commit)$/) {
                         push(@sourcearch, $a) unless $archadded{$a}++;
                     }
                 }
-            } elsif ($f =~ m/^(?:Homepage|Description)$/) {
+            } elsif (any { $f eq $_ } qw(Homepage Description)) {
                 # Do not overwrite the same field from the source entry
             } else {
                 field_transfer_single($pkg, $fields, $f);
@@ -391,17 +391,17 @@ if ($options{opmode} =~ 
/^(build|print-format|(before|after)-build|commit)$/) {
     foreach my $f (keys %{$changelog}) {
         my $v = $changelog->{$f};
 
-        if ($f =~ m/^Source$/) {
+        if ($f eq 'Source') {
             set_source_name($v);
             $fields->{$f} = $v;
-        } elsif ($f =~ m/^Version$/) {
+        } elsif ($f eq 'Version') {
            my ($ok, $error) = version_check($v);
             error($error) unless $ok;
             $fields->{$f} = $v;
-        } elsif ($f =~ m/^Binary-Only$/) {
+        } elsif ($f eq 'Binary-Only') {
            error(g_('building source for a binary-only release'))
                if $v eq 'yes' and $options{opmode} eq 'build';
-        } elsif ($f =~ m/^Maintainer$/i) {
+        } elsif ($f eq 'Maintainer') {
             # Do not replace the field coming from the source entry
        } else {
             field_transfer_single($changelog, $fields, $f);

-- 
Dpkg.Org's dpkg

Reply via email to