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

[lintian] 02/03: Revert "L::L::ManifestDiff: Remove - unused"



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

nthykier pushed a commit to branch master
in repository lintian.

commit 91d2b6eb1be2a9fe1de57c98f89ab9df25d67fb8
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Jan 22 21:27:47 2016 +0000

    Revert "L::L::ManifestDiff: Remove - unused"
    
    This reverts commit 51da10b2dd56dbce998bb24c46d426eb12c80844.
    It was still being used for tests.
---
 debian/changelog                |   2 -
 lib/Lintian/Lab/Manifest.pm     |  54 ++++++++++++++++
 lib/Lintian/Lab/ManifestDiff.pm | 133 ++++++++++++++++++++++++++++++++++++++++
 t/scripts/pod-coverage.t        |   1 +
 4 files changed, 188 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 5247e0d..55d64bf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -68,8 +68,6 @@ lintian (2.5.40) UNRELEASED; urgency=medium
       fixed even in oldstable.
     + [JW] Apply patch from Justin B Rye to fix an uninitialized value
       warning.  (Closes: #810649)
-  * lib/Lintian/Lab/ManifestDiff.pm:
-    + [NT] Remove module.
 
   * reporting/html_reports:
     + [JW] Add missing "map_maintainer" call, which made the reporting
diff --git a/lib/Lintian/Lab/Manifest.pm b/lib/Lintian/Lab/Manifest.pm
index 1d32401..0c14dc2 100644
--- a/lib/Lintian/Lab/Manifest.pm
+++ b/lib/Lintian/Lab/Manifest.pm
@@ -28,6 +28,8 @@ use parent qw(Class::Accessor::Fast Clone);
 
 use Carp qw(croak);
 
+use Lintian::Lab::ManifestDiff;
+
 =head1 NAME
 
 Lintian::Lab::Manifest -- Lintian Lab manifest
@@ -453,6 +455,58 @@ sub _do_delete {
     return 0;
 }
 
+=item diff (MANIFEST)
+
+Returns a L<diff|Lintian::Lab::ManifestDiff> between this manifest and
+MANIFEST.
+
+This instance is considered the "original" and MANIFEST is "new"
+version of the manifest.  (See the olist and nlist methods of
+L<Lintian::Lab::ManifestDiff> for more information.
+
+=cut
+
+sub diff {
+    my ($self, $other) = @_;
+    croak 'Cannot diff a GROUP manifest' if $self->type eq 'GROUP';
+    my $copy;
+    my @changed;
+    my @added;
+    my @removed;
+    my $visitor;
+    unless ($self->{'type'} eq $other->{'type'}) {
+        my $st = $self->{'type'};
+        my $ot = $other->{'type'};
+        croak "Diffing incompatible types ($st != $ot)";
+    }
+    $copy = $self->clone;
+
+    $visitor = sub {
+        my ($ov, @keys) = @_;
+        my $sv = $copy->get(@keys);
+        unless (defined $sv) {
+            push @added, \@keys;
+            return;
+        }
+        if (  $sv->{'version'} ne $ov->{'version'}
+            ||$sv->{'timestamp'} ne $ov->{'timestamp'}) {
+            push @changed, \@keys;
+        }
+        # Remove the entry from $copy
+        $copy->delete(@keys);
+    }; # End of visitor sub
+
+    # Find all the added and changed entries - since $visitor removes
+    # all entries it finds from $copy, $copy will contain the elements
+    # that are only in $self after this call.
+    $other->visit_all($visitor);
+    # Thus we can just add all of these entries to @removed.  :)
+    $copy->visit_all(sub { my (undef, @keys) = @_; push @removed, \@keys; });
+
+    return Lintian::Lab::ManifestDiff->_new($self->{'type'}, $other, $self,
+        \@added, \@removed, \@changed);
+}
+
 ### Internal methods ###
 
 # $plist->_mark_dirty($val)
diff --git a/lib/Lintian/Lab/ManifestDiff.pm b/lib/Lintian/Lab/ManifestDiff.pm
new file mode 100644
index 0000000..ba1d6b3
--- /dev/null
+++ b/lib/Lintian/Lab/ManifestDiff.pm
@@ -0,0 +1,133 @@
+# Lintian::Lab::ManifestDiff -- Representation of a diff between two manifests
+
+# Copyright (C) 2011 Niels Thykier
+#
+# 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, you can find it on the World Wide
+# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package Lintian::Lab::ManifestDiff;
+
+use strict;
+use warnings;
+
+use parent qw(Class::Accessor::Fast);
+
+=head1 NAME
+
+Lintian::Lab::ManifestDiff -- Difference representation between two Manifests
+
+=head1 SYNOPSIS
+
+ use Lintian::Lab::Manifest;
+ 
+ my $olist = Lintian::Lab::Manifest->new ('binary');
+ my $nlist = Lintian::Lab::Manifest->new ('binary');
+ $olist->read_list ('old/binary-packages');
+ $nlist->read_list ('new/binary-packages');
+ my $diff = $olist->diff($nlist);
+ foreach my $added (@{ $diff->added }) {
+    my $entry = $nlist->get (@$added);
+    # do something
+ }
+ foreach my $removed (@{ $diff->removed }) {
+    my $entry = $olist->get (@$removed);
+    # do something
+ }
+ foreach my $changed (@{ $diff->changed }) {
+    my $oentry = $olist->get (@$changed);
+    my $nentry = $nlist->get (@$changed);
+    # use/diff $oentry and $nentry as needed
+ }
+
+=head1 DESCRIPTION
+
+Instances of this class provides access to the packages list used by
+the Lab as caches.
+
+=head1 METHODS
+
+=over 4
+
+=cut
+
+# Private constructor (used by Lintian::Lab::Manifest::diff)
+sub _new {
+    my ($class, $type, $nlist, $olist, $added, $removed, $changed) = @_;
+    my $self = {
+        'added'   => $added,
+        'removed' => $removed,
+        'changed' => $changed,
+        'type'    => $type,
+        'olist'   => $olist,
+        'nlist'   => $nlist,
+    };
+    bless $self, $class;
+    return $self;
+}
+
+=item $diff->added
+
+Returns a listref containing the keys of the elements that has been added.
+
+Each element is a listref of keys; this list (when dereferenced) can be
+used with the manifest's get method to look up the item.
+
+=item $diff->removed
+
+Returns a listref containing the keys of the elements that has been removed.
+
+Each element is a listref of keys; this list (when dereferenced) can
+be used with the manifest's get method to look up the item.
+
+=item $diff->changed
+
+Returns a listref containing the keys of the elements that has been changed.
+
+Each element is a listref of keys; this list (when dereferenced) can
+be used with the manifest's get method to look up the item.
+
+=item $diff->nlist
+
+Returns the "new" manifest used to create this diff.  Note the manifest is not
+copied and may have been changed since the diff has been created.
+
+=item $diff->olist
+
+Returns the "orig" manifest used to create this diff.  Note the manifest is not
+copied and may have been changed since the diff has been created.
+
+=cut
+
+Lintian::Lab::ManifestDiff->mk_ro_accessors(
+    qw(added removed changed type nlist olist));
+
+=back
+
+Originally written by Niels Thykier <niels@thykier.net> for Lintian.
+
+=head1 SEE ALSO
+
+lintian(1)
+
+=cut
+
+1;
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/t/scripts/pod-coverage.t b/t/scripts/pod-coverage.t
index 96934a1..d6860fb 100755
--- a/t/scripts/pod-coverage.t
+++ b/t/scripts/pod-coverage.t
@@ -25,6 +25,7 @@ our %MODULES =(
     'Lintian::Lab'                => [],
     'Lintian::Lab::Entry'         => [],
     'Lintian::Lab::Manifest'      => [],
+    'Lintian::Lab::ManifestDiff'  => [],
     'Lintian::Profile'            => [],
     'Lintian::Processable'        => [qr/^new$/],
     'Lintian::ProcessableGroup'   => [],

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


Reply to: