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=a365789d463aadaf6870abcb149a90e54cef988e commit a365789d463aadaf6870abcb149a90e54cef988e Author: Guillem Jover <guil...@debian.org> AuthorDate: Sat Dec 14 04:37:34 2024 +0100 scripts: Unify handling of default Priority and Section values Track and handle these fields in a single hash, so that we can apply similar logic to both of them without having to repeat the same code for each field. --- scripts/dpkg-genbuildinfo.pl | 8 ++++--- scripts/dpkg-genchanges.pl | 52 ++++++++++++++++++++------------------------ scripts/dpkg-gencontrol.pl | 9 +++++--- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/scripts/dpkg-genbuildinfo.pl b/scripts/dpkg-genbuildinfo.pl index 895506c8a..9ba3997c8 100755 --- a/scripts/dpkg-genbuildinfo.pl +++ b/scripts/dpkg-genbuildinfo.pl @@ -558,8 +558,10 @@ if ($stdout) { if ($stdout) { $fields->output(\*STDOUT); } else { - my $section = $control->get_source->{'Section'} || '-'; - my $priority = $control->get_source->{'Priority'} || '-'; + my %fileprop; + foreach my $f (qw(Section Priority)) { + $fileprop{lc $f} = $control->get_source->{$f} || '-'; + } # Obtain a lock on debian/control to avoid simultaneous updates # of debian/files when parallel building is in use @@ -585,7 +587,7 @@ if ($stdout) { } } - $dist->add_file($buildinfo, $section, $priority); + $dist->add_file($buildinfo, @fileprop{qw(section priority)}); $dist->save("$fileslistfile.new"); rename "$fileslistfile.new", $fileslistfile diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl index cb985023a..d72bd6ace 100755 --- a/scripts/dpkg-genchanges.pl +++ b/scripts/dpkg-genchanges.pl @@ -61,10 +61,8 @@ my $changes_format = '1.8'; # Package to file map, has entries for "packagename". my %pkg2file; -# Package to section map, from control file. -my %file2ctrlsec; -# Package to priority map, from control file. -my %file2ctrlpri; +# Package to section/priority field map, from control file. +my %file2ctrlfield; # Default values taken from source (used for Section, Priority and Maintainer). my %sourcedefault; @@ -254,7 +252,7 @@ foreach my $f (keys %{$src_fields}) { if ($f eq 'Source') { set_source_name($v); } elsif (any { $f eq $_ } qw(Section Priority)) { - $sourcedefault{$f} = $v; + $sourcedefault{$f} = $v // '-'; } elsif ($f eq 'Description') { # Description in changes is computed, do not copy this field, only # initialize the description substvars. @@ -268,10 +266,10 @@ my $dist = Dpkg::Dist::Files->new(); my $origsrcmsg; if (build_has_any(BUILD_SOURCE)) { - my $sec = $sourcedefault{'Section'} // '-'; - my $pri = $sourcedefault{'Priority'} // '-'; - warning(g_('missing Section for source files')) if $sec eq '-'; - warning(g_('missing Priority for source files')) if $pri eq '-'; + foreach my $f (qw(Section Priority)) { + warning(g_('missing %s field in source stanza, for source files'), $f) + if $sourcedefault{$f} eq '-'; + } my $spackage = get_source_name(); (my $sversion = $substvars->get('source:Version')) =~ s/^\d+://; @@ -323,7 +321,7 @@ if (build_has_any(BUILD_SOURCE)) { # Only add attributes for files being distributed. for my $fn ($checksums->get_files()) { - $dist->add_file($fn, $sec, $pri); + $dist->add_file($fn, @sourcedefault{qw(Section Priority)}); } } elsif (build_is(BUILD_ARCH_DEP)) { $origsrcmsg = g_('binary-only arch-specific upload ' . @@ -411,9 +409,9 @@ foreach my $pkg ($control->get_packages()) { my $v = $pkg->{$f}; if ($f eq 'Section') { - $file2ctrlsec{$_} = $v foreach @files; + $file2ctrlfield{$_}{$f} = $v foreach @files; } elsif ($f eq 'Priority') { - $file2ctrlpri{$_} = $v foreach @files; + $file2ctrlfield{$_}{$f} = $v foreach @files; } elsif ($f eq 'Architecture') { if (build_has_any(BUILD_ARCH_DEP) and (any { debarch_is($host_arch, $_) } debarch_list_parse($v, positive => 1))) { @@ -463,23 +461,19 @@ for my $p (keys %pkg2file) { foreach my $fn (@{$pkg2file{$p}}) { my $file = $dist->get_file($fn); - my $sec = $file2ctrlsec{$fn} || $sourcedefault{'Section'} // '-'; - if ($sec eq '-') { - warning(g_("missing Section for binary package %s; using '-'"), $p); - } - if ($sec ne $file->{section}) { - error(g_('package %s has section %s in control file but %s in ' . - 'files list'), $p, $sec, $file->{section}); - } - - my $pri = $file2ctrlpri{$fn} || $sourcedefault{'Priority'} // '-'; - if ($pri eq '-') { - warning(g_("missing Priority for binary package %s; using '-'"), $p); - } - if ($pri ne $file->{priority}) { - error(g_('package %s has priority %s in control file but %s in ' . - 'files list'), $p, $pri, $file->{priority}); - } + foreach my $f (qw(Section Priority)) { + my $v = $file2ctrlfield{$fn}{$f} || $sourcedefault{$f}; + my $def = '-'; + + if ($v eq $def) { + warning(g_("missing %s field for binary package %s; using %s"), + $f, $p, $def); + } + if ($v ne $file->{lc $f}) { + error(g_('package %s has value %s in %s field in control file ' . + 'but %s in files list'), $p, $v, $f, $file->{lc $f}); + } + } } } diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index 56f1bdc6a..8ba7f0a84 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -389,8 +389,11 @@ if ($stdout) { $sversion =~ s/^\d+://; $forcefilename //= sprintf('%s_%s_%s.%s', $fields->{'Package'}, $sversion, $fields->{'Architecture'}, $pkg_type); - my $section = $fields->{'Section'} || '-'; - my $priority = $fields->{'Priority'} || '-'; + + my %fileprop; + foreach my $f (qw(Section Priority)) { + $fileprop{lc $f} = $fields->{$f} || '-'; + } # Obtain a lock on debian/control to avoid simultaneous updates # of debian/files when parallel building is in use @@ -418,7 +421,7 @@ if ($stdout) { my %fileattrs; $fileattrs{automatic} = 'yes' if $fields->{'Auto-Built-Package'}; - $dist->add_file($forcefilename, $section, $priority, %fileattrs); + $dist->add_file($forcefilename, @fileprop{qw(section priority)}, %fileattrs); $dist->save("$fileslistfile.new"); rename "$fileslistfile.new", $fileslistfile -- Dpkg.Org's dpkg