[dpkg] 55/192: Dpkg::Index: Add a new "unique_tuple_key" option to set_options()

Ximin Luo infinity0 at debian.org
Tue Oct 17 11:03:58 UTC 2017


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

infinity0 pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit 976d6ad7be0b704fab3675175a051b9d94a9b68e
Author: Guillem Jover <guillem at debian.org>
Date:   Tue Feb 14 13:55:03 2017 +0100

    Dpkg::Index: Add a new "unique_tuple_key" option to set_options()
    
    When the option is true it will set a get_func_key to a function that
    generates a unique tuple for that item. For CTRL_INDEX_SRC and CTRL_PKG_SRC
    use the Package and Version fields, for CTRL_INDEX_PKG and CTRL_PKG_DEB use
    the Package, Version and Architecture fields, all joined by "_" to index
    the entries.
    
    This behavior will become the default in dpkg 1.20.x. A deprecation
    warning will be emitted now requesting to set the option to true or
    to set a get_key_func options.
    
    Prompted-by: Johannes Schauer <josch at debian.org>
---
 debian/changelog      |  3 +++
 scripts/Dpkg/Index.pm | 69 +++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 5e31963..c88537f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,9 @@ dpkg (1.19.0) UNRELEASED; urgency=medium
   * Perl modules:
     - Switch from Dpkg::Util to List::Util, now that the module in the
       new required Perl contains the needed functions.
+    - Add a new "unique_tuple_key" option to Dpkg::Index set_options() to
+      set better default "get_key_func" options, which will become the default
+      behavior in 1.20.x. Prompted by Johannes Schauer <josch at debian.org>.
   * Documentation:
     - Document currently accepted syntax for changelogs in deb-changelog(5).
       Closes: #858579
diff --git a/scripts/Dpkg/Index.pm b/scripts/Dpkg/Index.pm
index ebeafcb..37fd3c7 100644
--- a/scripts/Dpkg/Index.pm
+++ b/scripts/Dpkg/Index.pm
@@ -1,4 +1,5 @@
 # Copyright © 2009 Raphaël Hertzog <hertzog at debian.org>
+# Copyright © 2012-2017 Guillem Jover <guillem at debian.org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -18,7 +19,7 @@ package Dpkg::Index;
 use strict;
 use warnings;
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
@@ -57,6 +58,7 @@ sub new {
     my $self = {
 	items => {},
 	order => [],
+	unique_tuple_key => 0,
 	get_key_func => sub { return $_[0]->{Package} },
 	type => CTRL_UNKNOWN,
     };
@@ -73,20 +75,33 @@ sub new {
 
 The "type" option is checked first to define default values for other
 options. Here are the relevant options: "get_key_func" is a function
-returning a key for the item passed in parameters. The index can only
-contain one item with a given key. The function used depends on the
-type:
+returning a key for the item passed in parameters, "unique_tuple_key" is
+a boolean requesting whether the default key should be the unique tuple
+(default to false for backwards compatibility, but it will change to true
+in dpkg 1.20.x). The index can only contain one item with a given key.
+The "get_key_func" function used depends on the type:
 
 =over
 
 =item *
 
-for CTRL_INFO_SRC and CTRL_PKG_SRC, it is the Source field;
+for CTRL_INFO_SRC, it is the Source field;
 
 =item *
 
-for CTRL_INFO_PKG, CTRL_INDEX_SRC, CTRL_INDEX_PKG and CTRL_PKG_DEB
-it is simply the Package field;
+for CTRL_INDEX_SRC and CTRL_PKG_SRC it is the Package field by default,
+or the Package and Version fields (concatenated with "_") when
+"unique_tuple_key" is true;
+
+=item *
+
+for CTRL_INFO_PKG it is simply the Package field;
+
+=item *
+
+for CTRL_INDEX_PKG and CTRL_PKG_DEB it is the Package field by default,
+or the Package, Version and Architecture fields (concatenated with "_")
+when "unique_tuple_key" is true;
 
 =item *
 
@@ -125,10 +140,9 @@ sub set_options {
     # Default values based on type
     if (exists $opts{type}) {
         my $t = $opts{type};
-        if ($t == CTRL_INFO_PKG or $t == CTRL_INDEX_SRC or
-	         $t == CTRL_INDEX_PKG or $t == CTRL_PKG_DEB) {
+        if ($t == CTRL_INFO_PKG) {
 	    $self->{get_key_func} = sub { return $_[0]->{Package}; };
-        } elsif ($t == CTRL_PKG_SRC or $t == CTRL_INFO_SRC) {
+        } elsif ($t == CTRL_INFO_SRC) {
 	    $self->{get_key_func} = sub { return $_[0]->{Source}; };
         } elsif ($t == CTRL_CHANGELOG) {
 	    $self->{get_key_func} = sub {
@@ -146,6 +160,35 @@ sub set_options {
             $self->{get_key_func} = sub {
                 return $_[0]->{Tests} || $_[0]->{'Test-Command'};
             };
+        } elsif ($t == CTRL_INDEX_SRC or $t == CTRL_PKG_SRC) {
+            if ($opts{unique_tuple_key} // $self->{unique_tuple_key}) {
+                $self->{get_key_func} = sub {
+                    return $_[0]->{Package} . '_' . $_[0]->{Version};
+                };
+            } elsif (not defined $opts{get_key_func}) {
+                $self->{get_key_func} = sub {
+                    return $_[0]->{Package};
+                };
+                warnings::warnif('deprecated',
+                    'the default get_key_func for this control type will ' .
+                    'change semantics in dpkg 1.20.x , please set ' .
+                    'unique_tuple_key or get_key_func explicitly');
+            }
+        } elsif ($t == CTRL_INDEX_PKG or $t == CTRL_PKG_DEB) {
+            if ($opts{unique_tuple_key} // $self->{unique_tuple_key}) {
+                $self->{get_key_func} = sub {
+                    return $_[0]->{Package} . '_' . $_[0]->{Version} . '_' .
+                           $_[0]->{Architecture};
+                };
+            } elsif (not defined $opts{get_key_func}) {
+                $self->{get_key_func} = sub {
+                    return $_[0]->{Package};
+                };
+                warnings::warnif('deprecated',
+                    'the default get_key_func for this control type will ' .
+                    'change semantics in dpkg 1.20.x , please set ' .
+                    'unique_tuple_key or get_key_func explicitly');
+            }
         } elsif ($t == CTRL_FILE_CHANGES) {
 	    $self->{get_key_func} = sub {
 		return $_[0]->{Source} . '_' . $_[0]->{Version} . '_' .
@@ -393,6 +436,12 @@ sub output {
 
 =head1 CHANGES
 
+=head2 Version 1.01 (dpkg 1.19.0)
+
+New option: Add new "unique_tuple_key" option to $index->set_options() to set
+better default "get_key_func" options, which will become the default behavior
+in 1.20.x.
+
 =head2 Version 1.00 (dpkg 1.15.6)
 
 Mark the module as public.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list