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=0d472ec1751fe6b2e14eab3e6c691fc14deb8d02

commit 0d472ec1751fe6b2e14eab3e6c691fc14deb8d02 (HEAD -> main)
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Sat Dec 14 05:10:19 2024 +0100

    scripts: Change and inject default value for Section and Priority fields
    
    When generating a DEBIAN/control, .dsc, .changes or a Sources repository
    metaindex, set the default values for the Section and Priority fields to
    «unknown» and «optional» respectively.
    
    For the Priority field, this means that the package maintainer does not
    longer need to add that field if it uses the default value, and only
    need to add it to override it.
    
    For the Section field, currently this only unifies its value when unset
    so that it always is «unknown» instead of sometimes being that and
    others being «-». In the future this makes way to be able to add some
    heuristics to auto-generate some more useful defaults.
    
    Proposed-by: Niels Thykier <ni...@thykier.net> (for Priority)
    Proposed-by: Guillem Jover <guil...@debian.org> (for Section)
---
 man/deb-changes.pod                |  3 +++
 man/deb-src-control.pod            |  6 ++++++
 man/dsc.pod                        |  3 ++-
 scripts/Dpkg/Control/FieldsCore.pm |  4 ++--
 scripts/dpkg-genchanges.pl         | 10 ----------
 scripts/dpkg-gencontrol.pl         | 12 +++++++++++-
 scripts/dpkg-scansources.pl        |  9 +++++----
 scripts/dpkg-source.pl             |  3 ++-
 scripts/t/Dpkg_Control_Fields.t    |  4 ++--
 9 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/man/deb-changes.pod b/man/deb-changes.pod
index 580ef6750..882004c31 100644
--- a/man/deb-changes.pod
+++ b/man/deb-changes.pod
@@ -177,6 +177,9 @@ Each line consists of space-separated entries describing 
the file:
 the md5sum, the file size, the file section, the file priority, and
 the file name.
 
+If the section or priority are omitted from the package,
+these default to B<unknown> and B<optional> respectively.
+
 This field lists all files that make up the upload.
 The list of files in this field must match the list of files in the
 other related B<Checksums> fields.
diff --git a/man/deb-src-control.pod b/man/deb-src-control.pod
index 86510fd34..457afee41 100644
--- a/man/deb-src-control.pod
+++ b/man/deb-src-control.pod
@@ -208,12 +208,18 @@ software that it installs.
 Some common sections are B<utils>, B<net>, B<mail>, B<text>,
 B<x11>, etc.
 
+When omitted,
+the I<section> defaults to B<unknown>.
+
 =item B<Priority:> I<priority>
 
 Sets the importance of this package in relation to the system as a whole.
 Common priorities are B<required>, B<standard>, B<optional>,
 B<extra>, etc.
 
+When omitted,
+the I<priority> defaults to B<optional>.
+
 The
 B<Section>
 and
diff --git a/man/dsc.pod b/man/dsc.pod
index 5b50556a8..bcf156c6c 100644
--- a/man/dsc.pod
+++ b/man/dsc.pod
@@ -216,7 +216,8 @@ The I<package-type> is the binary package type, usually 
B<deb>, another
 common value is B<udeb>.
 
 The I<section> and I<priority> match the binary package fields of the
-same name.
+same name,
+or if omitted default to B<unknown> and B<optional> respectively.
 
 The I<key-value-list> is a space separated I<key>B<=>I<value> list,
 and the currently known optional keys are:
diff --git a/scripts/Dpkg/Control/FieldsCore.pm 
b/scripts/Dpkg/Control/FieldsCore.pm
index 696a19e11..e3ebb80f0 100644
--- a/scripts/Dpkg/Control/FieldsCore.pm
+++ b/scripts/Dpkg/Control/FieldsCore.pm
@@ -435,7 +435,7 @@ our %FIELDS = (
     'priority' => {
         name => 'Priority',
         allowed => CTRL_TMPL_SRC | CTRL_REPO_SRC | ALL_PKG,
-        default => '-',
+        default => 'optional',
     },
     'protected' => {
         name => 'Protected',
@@ -475,7 +475,7 @@ our %FIELDS = (
     'section' => {
         name => 'Section',
         allowed => CTRL_TMPL_SRC | CTRL_REPO_SRC | ALL_PKG,
-        default => '-',
+        default => 'unknown',
     },
     'sha1' => {
         # XXX: Wrong capitalization due to historical reasons.
diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl
index 39c36377b..ccefae9f6 100755
--- a/scripts/dpkg-genchanges.pl
+++ b/scripts/dpkg-genchanges.pl
@@ -266,11 +266,6 @@ my $dist = Dpkg::Dist::Files->new();
 my $origsrcmsg;
 
 if (build_has_any(BUILD_SOURCE)) {
-    foreach my $f (qw(Section Priority)) {
-        warning(g_('missing %s field in source stanza, for source files'), $f)
-            if $sourcedefault{$f} eq field_get_default_value($f);
-    }
-
     my $spackage = get_source_name();
     (my $sversion = $substvars->get('source:Version')) =~ s/^\d+://;
 
@@ -463,12 +458,7 @@ for my $p (keys %pkg2file) {
 
         foreach my $f (qw(Section Priority)) {
             my $v = $file2ctrlfield{$fn}{$f} || $sourcedefault{$f};
-            my $def = field_get_default_value($f);
 
-            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 fce8ee6b2..2ef2fc929 100755
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -312,6 +312,16 @@ for my $f (qw(Maintainer Description)) {
     warning(g_('missing information for output field %s'), $f)
         unless defined $fields->{$f};
 }
+for my $f (qw(Section)) {
+    next if defined $fields->{$f};
+
+    $fields->{$f} = field_get_default_value($f);
+    warning(g_('missing information for output field %s; ' .
+               'using default value "%s"'), $fields->{$f});
+}
+for my $f (qw(Priority)) {
+    $fields->{$f} //= field_get_default_value($f);
+}
 
 my $pkg_type = $pkg->{'Package-Type'} ||
                $pkg->get_custom_field('Package-Type') || 'deb';
@@ -392,7 +402,7 @@ if ($stdout) {
 
     my %fileprop;
     foreach my $f (qw(Section Priority)) {
-        $fileprop{lc $f} = $fields->{$f} || field_get_default_value($f);
+        $fileprop{lc $f} = $fields->{$f};
     }
 
     # Obtain a lock on debian/control to avoid simultaneous updates
diff --git a/scripts/dpkg-scansources.pl b/scripts/dpkg-scansources.pl
index 6c86cd938..d256d2fe8 100755
--- a/scripts/dpkg-scansources.pl
+++ b/scripts/dpkg-scansources.pl
@@ -28,6 +28,7 @@ use Dpkg ();
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
 use Dpkg::Control;
+use Dpkg::Control::Fields;
 use Dpkg::Checksums;
 use Dpkg::Compression::FileHandle;
 use Dpkg::Compression;
@@ -241,16 +242,16 @@ sub process_dsc {
     my $priority_override = $override{$binary_by_priority[-1]};
     my $priority = $priority_override ?
                    $priority_override->[O_PRIORITY] :
-                   undef;
-    $fields->{Priority} = $priority if defined $priority;
+                   field_get_default_value('Priority');
+    $fields->{Priority} = $priority;
 
     # For the section override, first check for a record from the source
     # override file, else use the regular override file.
     my $section_override = $override{"source/$source"} || $override{$source};
     my $section = $section_override ?
                   $section_override->[O_SECTION] :
-                  undef;
-    $fields->{Section} = $section if defined $section;
+                  field_get_default_value('Section');
+    $fields->{Section} = $section;
 
     # For the maintainer override, use the override record for the first
     # binary. Modify the maintainer if necessary.
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index 0d2715ff6..697678b3f 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -300,7 +300,8 @@ if ($options{opmode} =~ 
/^(build|print-format|(before|after)-build|commit)$/) {
 
         my %pkg_prop;
         foreach my $f (qw(Section Priority)) {
-            $pkg_prop{lc $f} = $pkg->{$f} || $src_fields->{$f} || 'unknown';
+            $pkg_prop{lc $f} = $pkg->{$f} || $src_fields->{$f} ||
+                               field_get_default_value($f);
         }
         $pkg_prop{type} = $pkg->{'Package-Type'} ||
             $pkg->get_custom_field('Package-Type') || 'deb';
diff --git a/scripts/t/Dpkg_Control_Fields.t b/scripts/t/Dpkg_Control_Fields.t
index 23f7efe50..ce9304e58 100644
--- a/scripts/t/Dpkg_Control_Fields.t
+++ b/scripts/t/Dpkg_Control_Fields.t
@@ -477,9 +477,9 @@ is_deeply([ field_list_pkg_dep() ],
 
 is(field_get_default_value('Source'), undef,
     'no default value for Source field');
-is(field_get_default_value('Section'), '-',
+is(field_get_default_value('Section'), 'unknown',
     'default value for Section field');
-is(field_get_default_value('Priority'), '-',
+is(field_get_default_value('Priority'), 'optional',
     'default value for Priority field');
 
 is(field_capitalize('invented-field'), 'Invented-Field',

-- 
Dpkg.Org's dpkg

Reply via email to