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=0286be37b54cb43263e9f0065ce76db1d005dc26

commit 0286be37b54cb43263e9f0065ce76db1d005dc26
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Dec 14 03:32:29 2024 +0100

    Dpkg::Control::FieldsCore: Add new field_get_default_value() function
    
    This function will make it possible to centralize default values for
    fields, so that we can change it in one place instead of every place
    where the field is being used.
---
 scripts/Dpkg/Control/FieldsCore.pm | 21 ++++++++++++++++++++-
 scripts/t/Dpkg_Control_Fields.t    |  9 ++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/scripts/Dpkg/Control/FieldsCore.pm 
b/scripts/Dpkg/Control/FieldsCore.pm
index 1fec429f9..96089ffe3 100644
--- a/scripts/Dpkg/Control/FieldsCore.pm
+++ b/scripts/Dpkg/Control/FieldsCore.pm
@@ -28,7 +28,7 @@ CTRL_* constants exported by L<Dpkg::Control>.
 
 =cut
 
-package Dpkg::Control::FieldsCore 1.02;
+package Dpkg::Control::FieldsCore 1.03;
 
 use strict;
 use warnings;
@@ -44,6 +44,7 @@ our @EXPORT = qw(
     field_list_pkg_dep
     field_get_dep_type
     field_get_sep_type
+    field_get_default_value
     field_ordered_list
     field_register
     field_insert_after
@@ -1307,6 +1308,20 @@ sub field_get_sep_type {
     return FIELD_SEP_UNKNOWN;
 }
 
+=item $value = field_get_default_value($field)
+
+Return the default value (if any) for the field. If there is no default value
+then it returns "undef".
+
+=cut
+
+sub field_get_default_value {
+    my $field = lc shift;
+
+    return $FIELDS{$field}{default} if exists $FIELDS{$field}{default};
+    return;
+}
+
 =item field_register($field, $allowed_types, %opts)
 
 Register a new field as being allowed in control information of specified
@@ -1375,6 +1390,10 @@ sub field_insert_before {
 
 =head1 CHANGES
 
+=head2 Version 1.03 (dpkg 1.22.12)
+
+New function: field_get_default_value().
+
 =head2 Version 1.02 (dpkg 1.22.0)
 
 Deprecate argument: field_transfer_single() implicit argument usage.
diff --git a/scripts/t/Dpkg_Control_Fields.t b/scripts/t/Dpkg_Control_Fields.t
index 800e64902..06fc43712 100644
--- a/scripts/t/Dpkg_Control_Fields.t
+++ b/scripts/t/Dpkg_Control_Fields.t
@@ -20,7 +20,7 @@ use Test::More;
 use Test::Dpkg qw(:paths);
 
 BEGIN {
-    plan tests => 2603;
+    plan tests => 2606;
 
     use_ok('Dpkg::Control::Types');
     use_ok('Dpkg::Control::FieldsCore');
@@ -475,6 +475,13 @@ is_deeply([ field_list_pkg_dep() ],
           [ @bin_dep_fields ],
           'List of build dependencies');
 
+is(field_get_default_value('Source'), undef,
+    'no default value for Source field');
+is(field_get_default_value('Section'), undef,
+    'no default value for Section field');
+is(field_get_default_value('Priority'), undef,
+    'no default value for Priority field');
+
 is(field_capitalize('invented-field'), 'Invented-Field',
    'Field Invented-Field capitalization');
 ok(!field_is_official('invented-field'),

-- 
Dpkg.Org's dpkg

Reply via email to