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

guillem pushed a commit to branch master
in repository dpkg.

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

commit 37030e02cab5efe710834268f3d4ea426ec4a99a
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Tue Sep 18 23:34:31 2018 +0200

    Dpkg::Dist::Files: Add support for file attributes
    
    This will make it possible to track key/value attributes for each file,
    so that we can track interesting information and pass it to the various
    programs parsing the debian/files file.
---
 debian/changelog                       |  1 +
 man/deb-src-files.man                  |  7 +++++++
 scripts/Dpkg/Dist/Files.pm             | 17 ++++++++++++++---
 scripts/t/Dpkg_Dist_Files.t            | 31 ++++++++++++++++++++++---------
 scripts/t/Dpkg_Dist_Files/files-byhand |  4 ++--
 5 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 5f45df110..5b00463da 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -169,6 +169,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
       packaging problems as of late. This was apparently an oversight in
       the original implementation. Closes: #854438
     - Dpkg::Vendor::Debian: Add fixfilepath support to reproducible feature.
+    - Dpkg::Dist::Files: Add support for file attributes.
   * Documentation:
     - Update gettext minimal version in README.
     - Add a missing dot on the dpkg-buildflags(1) «lfs» feature paragraph.
diff --git a/man/deb-src-files.man b/man/deb-src-files.man
index 39269aacd..cc8abda52 100644
--- a/man/deb-src-files.man
+++ b/man/deb-src-files.man
@@ -33,6 +33,9 @@ The \fIdebian/files\fP file has a simple whitespace-delimited 
format.
 .I filename
 .I section
 .I priority
+[
+.I keyword=value\&...\&
+]
 .in -5
 .PP
 .I filename
@@ -43,6 +46,10 @@ and
 .I priority
 correspond to the respective control fields available in the .deb.
 The allowed values are specific to each distribution archive.
+.PP
+.I keyword=value\&...\&
+corresponds to an optional whitespace-delimited list of attributes for this
+entry.
 .
 .SH NOTES
 This file is not intended to be modified directly, please use one of
diff --git a/scripts/Dpkg/Dist/Files.pm b/scripts/Dpkg/Dist/Files.pm
index c2c426bd9..28f9d9a7a 100644
--- a/scripts/Dpkg/Dist/Files.pm
+++ b/scripts/Dpkg/Dist/Files.pm
@@ -81,12 +81,14 @@ sub parse {
 
         my $file;
 
-        if (m/^(\S+) (\S+) (\S+)$/) {
+        if (m/^(\S+) (\S+) (\S+)((?:\s+[0-9a-z-]+=\S+)*)$/) {
             $file = $self->parse_filename($1);
             error(g_('badly formed package name in files list file, line %d'), 
$.)
                 unless defined $file;
             $file->{section} = $2;
             $file->{priority} = $3;
+            my $attrs = $4;
+            $file->{attrs} = { map { split /=/ } split ' ', $attrs };
         } else {
             error(g_('badly formed line in files list file, line %d'), $.);
         }
@@ -131,12 +133,13 @@ sub get_file {
 }
 
 sub add_file {
-    my ($self, $filename, $section, $priority) = @_;
+    my ($self, $filename, $section, $priority, %attrs) = @_;
 
     my $file = $self->parse_filename($filename);
     error(g_('invalid filename %s'), $filename) unless defined $file;
     $file->{section} = $section;
     $file->{priority} = $priority;
+    $file->{attrs} = \%attrs;
 
     $self->{files}->{$filename} = $file;
 
@@ -171,7 +174,15 @@ sub output {
 
     foreach my $filename (sort keys %{$self->{files}}) {
         my $file = $self->{files}->{$filename};
-        my $entry = "$filename $file->{section} $file->{priority}\n";
+        my $entry = "$filename $file->{section} $file->{priority}";
+
+        if (exists $file->{attrs}) {
+            foreach my $attr (sort keys %{$file->{attrs}}) {
+                $entry .= " $attr=$file->{attrs}->{$attr}";
+            }
+        }
+
+        $entry .= "\n";
 
         print { $fh } $entry if defined $fh;
         $str .= $entry;
diff --git a/scripts/t/Dpkg_Dist_Files.t b/scripts/t/Dpkg_Dist_Files.t
index 44d42d058..e7d6a5da6 100644
--- a/scripts/t/Dpkg_Dist_Files.t
+++ b/scripts/t/Dpkg_Dist_Files.t
@@ -29,11 +29,13 @@ my %expected = (
         filename => 'pkg-src_4:2.0+1A~rc1-1.dsc',
         section => 'source',
         priority => 'extra',
+        attrs => {},
     },
     'pkg-src_4:2.0+1A~rc1-1.tar.xz' => {
         filename => 'pkg-src_4:2.0+1A~rc1-1.tar.xz',
         section => 'source',
         priority => 'extra',
+        attrs => {},
     },
     'pkg-templ_1.2.3_arch.type' => {
         filename => 'pkg-templ_1.2.3_arch.type',
@@ -43,6 +45,7 @@ my %expected = (
         arch => 'arch',
         section => 'section',
         priority => 'priority',
+        attrs => {},
     },
     'pkg-arch_2.0.0_amd64.deb' => {
         filename => 'pkg-arch_2.0.0_amd64.deb',
@@ -52,6 +55,7 @@ my %expected = (
         arch => 'amd64',
         section => 'admin',
         priority => 'required',
+        attrs => {},
     },
     'pkg-indep_0.0.1-2_all.deb' => {
         filename => 'pkg-indep_0.0.1-2_all.deb',
@@ -61,26 +65,35 @@ my %expected = (
         arch => 'all',
         section => 'net',
         priority => 'standard',
+        attrs => {},
     },
     'other_0.txt' => {
         filename => 'other_0.txt',
         section => 'text',
         priority => 'optional',
+        attrs => {
+            'mime-type' => 'text/plain',
+        },
     },
     'BY-HAND-file' => {
         filename => 'BY-HAND-file',
         section => 'webdocs',
         priority => 'optional',
+        attrs => {
+            'by-hand' => 'true'
+        },
     },
     'another:filename' => {
         filename => 'another:filename',
         section => 'by-hand',
         priority => 'extra',
+        attrs => {},
     },
     'added-on-the-fly' => {
         filename => 'added-on-the-fly',
         section => 'void',
         priority => 'wish',
+        attrs => {},
     },
 );
 
@@ -88,8 +101,8 @@ my $dist = Dpkg::Dist::Files->new();
 $dist->load("$datadir/files-byhand") or error('cannot parse file');
 
 $expected = <<'FILES';
-BY-HAND-file webdocs optional
-other_0.txt text optional
+BY-HAND-file webdocs optional by-hand=true
+other_0.txt text optional mime-type=text/plain
 pkg-arch_2.0.0_amd64.deb admin required
 pkg-indep_0.0.1-2_all.deb net standard
 pkg-templ_1.2.3_arch.type section priority
@@ -110,9 +123,9 @@ foreach my $f ($dist->get_files()) {
 is($dist->parse_filename('file%invalid'), undef, 'invalid filename');
 
 $expected = <<'FILES';
-BY-HAND-file webdocs optional
+BY-HAND-file webdocs optional by-hand=true
 added-on-the-fly void wish
-other_0.txt text optional
+other_0.txt text optional mime-type=text/plain
 pkg-arch_2.0.0_amd64.deb void imperative
 pkg-templ_1.2.3_arch.type section priority
 FILES
@@ -156,8 +169,8 @@ is_deeply($dist->get_file('another:filename'),
 is($dist->output, $expected, 'Added source files');
 
 $expected = <<'FILES';
-BY-HAND-file webdocs optional
-other_0.txt text optional
+BY-HAND-file webdocs optional by-hand=true
+other_0.txt text optional mime-type=text/plain
 pkg-arch_2.0.0_amd64.deb admin required
 pkg-frag-a_0.0_arch.type section priority
 pkg-frag-b_0.0_arch.type section priority
@@ -181,8 +194,8 @@ $dist->filter(remove => sub { $_[0]->{priority} eq 
'optional' });
 is($dist->output(), $expected, 'Filter remove priority optional');
 
 $expected = <<'FILES';
-BY-HAND-file webdocs optional
-other_0.txt text optional
+BY-HAND-file webdocs optional by-hand=true
+other_0.txt text optional mime-type=text/plain
 FILES
 
 $dist->reset();
@@ -191,7 +204,7 @@ $dist->filter(keep => sub { $_[0]->{priority} eq 'optional' 
});
 is($dist->output(), $expected, 'Filter keep priority optional');
 
 $expected = <<'FILES';
-BY-HAND-file webdocs optional
+BY-HAND-file webdocs optional by-hand=true
 FILES
 
 $dist->reset();
diff --git a/scripts/t/Dpkg_Dist_Files/files-byhand 
b/scripts/t/Dpkg_Dist_Files/files-byhand
index ac45d4610..416b14fb8 100644
--- a/scripts/t/Dpkg_Dist_Files/files-byhand
+++ b/scripts/t/Dpkg_Dist_Files/files-byhand
@@ -1,5 +1,5 @@
 pkg-templ_1.2.3_arch.type section priority
 pkg-arch_2.0.0_amd64.deb admin required
 pkg-indep_0.0.1-2_all.deb net standard
-other_0.txt text optional
-BY-HAND-file webdocs optional
+other_0.txt text optional mime-type=text/plain
+BY-HAND-file webdocs optional by-hand=true

-- 
Dpkg.Org's dpkg

Reply via email to