[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.10-133-g342c2d6



The following commit has been merged in the master branch:
commit a8041573cfdf5aeae77c322fd43b219b4f1a2f54
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Sep 7 20:56:37 2012 +0200

    L::Proc{Group,Pool}: Optionally map procs to L::Lab::Entry
    
    Add new optional Lab argument for L::ProccessableGroup and
    L::ProcessablePool.  If given, the instance of these classes will
    automatically map processables added to a Lab entry for the given lab.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/lib/Lintian/Lab/Entry.pm b/lib/Lintian/Lab/Entry.pm
index 34e1b94..3bf0590 100644
--- a/lib/Lintian/Lab/Entry.pm
+++ b/lib/Lintian/Lab/Entry.pm
@@ -66,6 +66,8 @@ use File::Spec;
 
 use Cwd();
 
+use Scalar::Util qw(refaddr);
+
 use Lintian::Lab;
 use Lintian::Util qw(delete_dir read_dpkg_control get_dsc_info);
 
@@ -142,6 +144,17 @@ Returns the base directory of this package inside the lab.
 
 Lintian::Lab::Entry->mk_ro_accessors (qw(base_dir));
 
+=item from_lab (LAB)
+
+Returns a truth value if this entry is from LAB.
+
+=cut
+
+sub from_lab {
+    my ($self, $lab) = @_;
+    return refaddr $lab eq refaddr $self->{'lab'} ? 1 : 0;
+}
+
 =item lab_pkg
 
 Returns the instance itself.  This method is here to simplify using a
diff --git a/lib/Lintian/ProcessableGroup.pm b/lib/Lintian/ProcessableGroup.pm
index 5fc1f0c..ad6f416 100644
--- a/lib/Lintian/ProcessableGroup.pm
+++ b/lib/Lintian/ProcessableGroup.pm
@@ -52,21 +52,35 @@ and one changes package per set, but multiple binary packages
 
 =over 4
 
-=item Lintian::ProcessableGroup->new([$changes_file])
+=item Lintian::ProcessableGroup->new ([LAB[, CHANGES]])
 
-Creates a group and optionally add all processables from $changes_file.
+Creates a group and optionally add all processables from CHANGES.
+
+If the LAB parameter is given, all processables added to this group
+will bestored as a L<lab entry|Lintian::Lab::Entry> from LAB.
 
 =cut
 
 sub new {
-    my ($class, $changes) = @_;
-    my $self = {};
+    my ($class, $lab, $changes) = @_;
+    my $self = {
+        'lab' => $lab,
+    };
     bless $self, $class;
     $self->_init_group_from_changes($changes)
         if defined $changes;
     return $self;
 }
 
+# Map a processable to L::Lab::Entry if needed.
+sub _lab_proc {
+    my ($self, $proc) = @_;
+    return $proc unless $self->{'lab'};
+    return $proc if $proc->isa ('Lintian::Lab::Entry') and
+        not $proc->from_lab ($self->{'lab'});
+    return $self->{'lab'}->get_package ($proc);
+}
+
 # Internal initialization sub
 #  populates $self from a changes file.
 sub _init_group_from_changes {
@@ -155,10 +169,10 @@ sub add_processable{
 
     if ($pkg_type eq 'changes'){
         fail 'Cannot add another changes file' if (exists $self->{changes});
-        $self->{changes} = $processable;
+        $self->{changes} = $self->_lab_proc ($processable);
     } elsif ($pkg_type eq 'source'){
         fail 'Cannot add another source package' if (exists $self->{source});
-        $self->{source} = $processable;
+        $self->{source} = $self->_lab_proc ($processable);
     } else {
         my $phash;
         my $id = $processable->identifier;
@@ -171,7 +185,7 @@ sub add_processable{
         }
         # duplicate ?
         return 0 if (exists $phash->{$id});
-        $phash->{$id} = $processable;
+        $phash->{$id} = $self->_lab_proc ($processable);
     }
     $processable->group($self);
     return 1;
diff --git a/lib/Lintian/ProcessablePool.pm b/lib/Lintian/ProcessablePool.pm
index 1bc22ed..469f469 100644
--- a/lib/Lintian/ProcessablePool.pm
+++ b/lib/Lintian/ProcessablePool.pm
@@ -51,15 +51,21 @@ Lintian::ProcessablePool -- Pool of processables
 
 =over 4
 
-=item Lintian::ProcessablePool->new
+=item Lintian::ProcessablePool->new ([LAB])
 
 Creates a new empty pool.
 
+If LAB is given, it is assumed to be a Lintian::Lab.  In this case,
+any processable added to this pool will be stored as a
+L<lab entry|Lintian::Lab::Entry> from LAB.
+
 =cut
 
 sub new {
-    my ($class) = @_;
-    my $self = {};
+    my ($class, $lab) = @_;
+    my $self = {
+        'lab' => $lab,
+    };
     foreach my $field (qw(binary changes groups source udeb)){
         $self->{$field} = {};
     }
@@ -101,8 +107,7 @@ sub add_proc {
     my $pkg_type = $proc->pkg_type;
     my $tmap = $self->{$pkg_type};
 
-
-   if ($proc->tainted) {
+    if ($proc->tainted) {
         warn (sprintf ("warning: tainted %1\$s package '%2\$s', skipping\n",
              $pkg_type, $proc->pkg_name));
         return 0;
@@ -121,7 +126,7 @@ sub add_proc {
         return $group->add_processable ($proc);
     } else {
         # Create a new group
-        $group = Lintian::ProcessableGroup->new;
+        $group = Lintian::ProcessableGroup->new ($self->{'lab'});
         $group->add_processable($proc);
         $self->{groups}->{$groupid} = $group;
     }
@@ -187,7 +192,7 @@ sub empty{
 
 sub _add_changes_file{
     my ($self, $pkg_path) = @_;
-    my $group = Lintian::ProcessableGroup->new($pkg_path);
+    my $group = Lintian::ProcessableGroup->new ($self->{'lab'}, $pkg_path);
     my $cproc = $group->get_changes_processable();
     my $gid = $self->_get_group_id($cproc);
     my $ogroup = $self->{groups}->{$gid};

-- 
Debian package checker


Reply to: