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=fca9a4b8937245f6a4198e8d5d910724462f6600 commit fca9a4b8937245f6a4198e8d5d910724462f6600 Author: Guillem Jover <[email protected]> AuthorDate: Tue Feb 21 02:09:56 2023 +0100 perl: Use an $f variable for fields instead of the topic variable This makes the usage more clear, and once we switch to literal string matches we would need to use the variable explicitly anyway. --- scripts/Dpkg/Changelog.pm | 22 ++++++++++--------- scripts/dpkg-genchanges.pl | 38 ++++++++++++++++----------------- scripts/dpkg-gencontrol.pl | 39 +++++++++++++++++----------------- scripts/dpkg-source.pl | 53 ++++++++++++++++++++++++---------------------- 4 files changed, 79 insertions(+), 73 deletions(-) diff --git a/scripts/Dpkg/Changelog.pm b/scripts/Dpkg/Changelog.pm index 4f44ec0bb..e36aca527 100644 --- a/scripts/Dpkg/Changelog.pm +++ b/scripts/Dpkg/Changelog.pm @@ -518,12 +518,13 @@ sub _format_dpkg { # handle optional fields my $opts = $src->get_optional_fields(); my %closes; - foreach (keys %$opts) { - if (/^Urgency$/i) { # Already dealt - } elsif (/^Closes$/i) { + foreach my $f (keys %{$opts}) { + if ($f =~ /^Urgency$/i) { + # Already handled. + } elsif ($f =~ /^Closes$/i) { $closes{$_} = 1 foreach (split(/\s+/, $opts->{Closes})); } else { - field_transfer_single($opts, $c, $_); + field_transfer_single($opts, $c, $f); } } @@ -537,11 +538,12 @@ sub _format_dpkg { # handle optional fields $opts = $bin->get_optional_fields(); - foreach (keys %$opts) { - if (/^Closes$/i) { + foreach my $f (keys %{$opts}) { + if ($f =~ /^Closes$/i) { $closes{$_} = 1 foreach (split(/\s+/, $opts->{Closes})); - } elsif (not exists $c->{$_}) { # Don't overwrite an existing field - field_transfer_single($opts, $c, $_); + } elsif (not exists $c->{$f}) { + # Don't overwrite an existing field + field_transfer_single($opts, $c, $f); } } } @@ -573,8 +575,8 @@ sub _format_rfc822 { # handle optional fields my $opts = $entry->get_optional_fields(); - foreach (keys %$opts) { - field_transfer_single($opts, $c, $_) unless exists $c->{$_}; + foreach my $f (keys %{$opts}) { + field_transfer_single($opts, $c, $f) unless exists $c->{$f}; } run_vendor_hook('post-process-changelog-entry', $c); diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl index 8eb19ef1a..2cc4861a1 100755 --- a/scripts/dpkg-genchanges.pl +++ b/scripts/dpkg-genchanges.pl @@ -234,18 +234,18 @@ if (! $is_backport && defined $prev_changelog && # Scan control info of source package my $src_fields = $control->get_source(); -foreach (keys %{$src_fields}) { - my $v = $src_fields->{$_}; - if (m/^Source$/) { +foreach my $f (keys %{$src_fields}) { + my $v = $src_fields->{$f}; + if ($f =~ m/^Source$/) { set_source_name($v); - } elsif (m/^Section$|^Priority$/i) { - $sourcedefault{$_} = $v; - } elsif (m/^Description$/i) { + } elsif ($f =~ m/^Section$|^Priority$/i) { + $sourcedefault{$f} = $v; + } elsif ($f =~ m/^Description$/i) { # Description in changes is computed, do not copy this field, only # initialize the description substvars. $substvars->set_desc_substvars($v); } else { - field_transfer_single($src_fields, $fields, $_); + field_transfer_single($src_fields, $fields, $f); } } @@ -394,14 +394,14 @@ foreach my $pkg ($control->get_packages()) { # List of files for this binary package. my @files = @{$pkg2file{$p}}; - foreach (keys %{$pkg}) { - my $v = $pkg->{$_}; + foreach my $f (keys %{$pkg}) { + my $v = $pkg->{$f}; - if (m/^Section$/) { + if ($f =~ m/^Section$/) { $file2ctrlsec{$_} = $v foreach @files; - } elsif (m/^Priority$/) { + } elsif ($f =~ m/^Priority$/) { $file2ctrlpri{$_} = $v foreach @files; - } elsif (m/^Architecture$/) { + } elsif ($f =~ m/^Architecture$/) { if (build_has_any(BUILD_ARCH_DEP) and (any { debarch_is($host_arch, $_) } debarch_list_parse($v, positive => 1))) { $v = $host_arch; @@ -409,23 +409,23 @@ foreach my $pkg ($control->get_packages()) { $v = ''; } push(@archvalues, $v) if $v and not $archadded{$v}++; - } elsif (m/^Description$/) { + } elsif ($f =~ m/^Description$/) { # Description in changes is computed, do not copy this field } else { - field_transfer_single($pkg, $fields, $_); + field_transfer_single($pkg, $fields, $f); } } } # Scan fields of dpkg-parsechangelog -foreach (keys %{$changelog}) { - my $v = $changelog->{$_}; - if (m/^Source$/i) { +foreach my $f (keys %{$changelog}) { + my $v = $changelog->{$f}; + if ($f =~ m/^Source$/i) { set_source_name($v); - } elsif (m/^Maintainer$/i) { + } elsif ($f =~ m/^Maintainer$/i) { $fields->{'Changed-By'} = $v; } else { - field_transfer_single($changelog, $fields, $_); + field_transfer_single($changelog, $fields, $f); } } diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index 774d780e6..8fedac2fc 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -193,29 +193,30 @@ $substvars->set_msg_prefix(sprintf(g_('package %s: '), $pkg->{Package})); # Scan source package my $src_fields = $control->get_source(); -foreach (keys %{$src_fields}) { - if (m/^Source$/) { - set_source_name($src_fields->{$_}); - } elsif (m/^Description$/) { +foreach my $f (keys %{$src_fields}) { + if ($f =~ m/^Source$/) { + set_source_name($src_fields->{$f}); + } elsif ($f =~ m/^Description$/) { # Description in binary packages is not inherited, do not copy this # field, only initialize the description substvars. - $substvars->set_desc_substvars($src_fields->{$_}); + $substvars->set_desc_substvars($src_fields->{$f}); } else { - field_transfer_single($src_fields, $fields, $_); + field_transfer_single($src_fields, $fields, $f); } } $substvars->set_field_substvars($src_fields, 'S'); # Scan binary package -foreach (keys %{$pkg}) { - my $v = $pkg->{$_}; - if (field_get_dep_type($_)) { +foreach my $f (keys %{$pkg}) { + my $v = $pkg->{$f}; + + if (field_get_dep_type($f)) { # Delay the parsing until later - } elsif (m/^Architecture$/) { + } elsif ($f =~ m/^Architecture$/) { my $host_arch = get_host_arch(); if (debarch_eq('all', $v)) { - $fields->{$_} = $v; + $fields->{$f} = $v; } else { my @archlist = debarch_list_parse($v, positive => 1); @@ -224,26 +225,26 @@ foreach (keys %{$pkg}) { "appear in package '%s' architecture list (%s)"), $host_arch, $oppackage, "@archlist"); } - $fields->{$_} = $host_arch; + $fields->{$f} = $host_arch; } } else { - field_transfer_single($pkg, $fields, $_); + field_transfer_single($pkg, $fields, $f); } } # Scan fields of dpkg-parsechangelog -foreach (keys %{$changelog}) { - my $v = $changelog->{$_}; +foreach my $f (keys %{$changelog}) { + my $v = $changelog->{$f}; - if (m/^Source$/) { + if ($f =~ m/^Source$/) { set_source_name($v); - } elsif (m/^Version$/) { + } elsif ($f =~ m/^Version$/) { # Already handled previously. - } elsif (m/^Maintainer$/) { + } elsif ($f =~ m/^Maintainer$/) { # That field must not be copied from changelog even if it's # allowed in the binary package control information } else { - field_transfer_single($changelog, $fields, $_); + field_transfer_single($changelog, $fields, $f); } } diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index 23a98f507..aa5bb9fa5 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -272,24 +272,26 @@ if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) { $controlfile) unless defined $src_fields; my $src_sect = $src_fields->{'Section'} || 'unknown'; my $src_prio = $src_fields->{'Priority'} || 'unknown'; - foreach (keys %{$src_fields}) { - my $v = $src_fields->{$_}; - if (m/^Source$/i) { + foreach my $f (keys %{$src_fields}) { + my $v = $src_fields->{$f}; + + if ($f =~ m/^Source$/i) { set_source_name($v); - $fields->{$_} = $v; - } elsif (m/^Uploaders$/i) { - ($fields->{$_} = $v) =~ s/\s*[\r\n]\s*/ /g; # Merge in a single-line - } elsif (m/^Build-(?:Depends|Conflicts)(?:-Arch|-Indep)?$/i) { + $fields->{$f} = $v; + } elsif ($f =~ m/^Uploaders$/i) { + # Merge in a single-line. + ($fields->{$f} = $v) =~ s/\s*[\r\n]\s*/ /g; + } elsif ($f =~ m/^Build-(?:Depends|Conflicts)(?:-Arch|-Indep)?$/i) { my $dep; - my $type = field_get_dep_type($_); + my $type = field_get_dep_type($f); $dep = deps_parse($v, build_dep => 1, union => $type eq 'union'); - error(g_('cannot parse %s field'), $_) unless defined $dep; + error(g_('cannot parse %s field'), $f) unless defined $dep; my $facts = Dpkg::Deps::KnownFacts->new(); $dep->simplify_deps($facts); $dep->sort() if $type eq 'union'; - $fields->{$_} = $dep->output(); + $fields->{$f} = $dep->output(); } else { - field_transfer_single($src_fields, $fields, $_); + field_transfer_single($src_fields, $fields, $f); } } @@ -329,9 +331,10 @@ if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) { push @pkglist, $pkg_summary; push @binarypackages, $p; - foreach (keys %{$pkg}) { - my $v = $pkg->{$_}; - if (m/^Architecture$/) { + foreach my $f (keys %{$pkg}) { + my $v = $pkg->{$f}; + + if ($f =~ m/^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. @@ -349,10 +352,10 @@ if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) { push(@sourcearch, $a) unless $archadded{$a}++; } } - } elsif (m/^(?:Homepage|Description)$/) { + } elsif ($f =~ m/^(?:Homepage|Description)$/) { # Do not overwrite the same field from the source entry } else { - field_transfer_single($pkg, $fields, $_); + field_transfer_single($pkg, $fields, $f); } } } @@ -385,23 +388,23 @@ if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) { set_testsuite_fields($fields, @binarypackages); # Scan fields of dpkg-parsechangelog - foreach (keys %{$changelog}) { - my $v = $changelog->{$_}; + foreach my $f (keys %{$changelog}) { + my $v = $changelog->{$f}; - if (m/^Source$/) { + if ($f =~ m/^Source$/) { set_source_name($v); - $fields->{$_} = $v; - } elsif (m/^Version$/) { + $fields->{$f} = $v; + } elsif ($f =~ m/^Version$/) { my ($ok, $error) = version_check($v); error($error) unless $ok; - $fields->{$_} = $v; - } elsif (m/^Binary-Only$/) { + $fields->{$f} = $v; + } elsif ($f =~ m/^Binary-Only$/) { error(g_('building source for a binary-only release')) if $v eq 'yes' and $options{opmode} eq 'build'; - } elsif (m/^Maintainer$/i) { + } elsif ($f =~ m/^Maintainer$/i) { # Do not replace the field coming from the source entry } else { - field_transfer_single($changelog, $fields, $_); + field_transfer_single($changelog, $fields, $f); } } -- Dpkg.Org's dpkg

