[libconfig-model-dpkg-perl] 10/12: Scanner: do next instead of last when an entry has problems...

dod at debian.org dod at debian.org
Sat Apr 4 13:58:55 UTC 2015


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

dod pushed a commit to branch master
in repository libconfig-model-dpkg-perl.

commit 668211ad35895cdc4db308dc344120212750e305
Author: Dominique Dumont <dod at debian.org>
Date:   Sat Apr 4 15:53:20 2015 +0200

    Scanner: do next instead of last when an entry has problems...
    
    ... also extracted __coalesce_copyright_years. This function does
    "next" instead of "last" in case of issue when coalescing (c) years.
    This also avoid a non-repetitive bug: call to last occurred within a loop
    over random keys %stuff .
---
 lib/Dpkg/Copyright/Scanner.pm | 55 ++++++++++++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 21 deletions(-)

diff --git a/lib/Dpkg/Copyright/Scanner.pm b/lib/Dpkg/Copyright/Scanner.pm
index f1c96cd..ae5b70f 100644
--- a/lib/Dpkg/Copyright/Scanner.pm
+++ b/lib/Dpkg/Copyright/Scanner.pm
@@ -253,30 +253,19 @@ sub __squash_copyrights_years ($copyrights_by_id) {
     foreach my $owner_license (keys %id_year_by_same_owner_license) {
         my @entries =  $id_year_by_same_owner_license{$owner_license}->@* ;
         next unless @entries > 1;
+
         my ($l, at owners) = split /\|/, $owner_license;
-        my @ranges_of_years ;
-        my @ids;
-      SQUASH:
-        foreach my $entry (@entries) {
-            my ($id, @years) = $entry->@* ;
-
-            for (my $i = 0; $i < @years; $i++) {
-                last SQUASH if $years[$i] =~ /[^\d,\s-]/;
-                my $span = $ranges_of_years[$i] //= Array::IntSpan->new();
-                last SQUASH unless $span; # bail out in case of problems
-                $span->set_range_as_string($years[$i], 1);
-            }
-            push @ids, $id;
-        }
-        my @squashed_c;
-        for (my $i=0; $i < @owners ; $i++) {
-            $ranges_of_years[$i]->consolidate();
-            $squashed_c[$i] = $ranges_of_years[$i]->get_range_list.', '.$owners[$i];
-        }
 
-        my $new_id = @$copyrights_by_id + @merged_c_info ;
+        # create new copyright info with coaslesced years
+        my @squashed_c = __coalesce_copyright_years(\@entries,\@owners) ;
+        next unless @squashed_c ; # give up this entry when problem
+
+        # store (c) info with coalesced years in new item of $copyrights_by_id
+        my $new_id = @$copyrights_by_id ;
         $copyrights_by_id->[$new_id] = [ join("\n ", at squashed_c), $l ];
-        foreach my $id (@ids) {
+
+        # fill the swap table entry-id -> coaslesces entry-id
+        foreach my $id ( map { $_->[0]} @entries) {
             $merged_c_info[$id] = $new_id;
         }
     }
@@ -296,6 +285,30 @@ sub __swap_merged_ids ($files, $merged_c_info) {
     }
 }
 
+sub __coalesce_copyright_years($entries, $owners) {
+    my @ranges_of_years ;
+    # $entries and $owners always have the same size
+
+    foreach my $entry (@$entries) {
+        my ($id, @years) = $entry->@* ;
+
+        for (my $i = 0; $i < @years; $i++) {
+            return () if $years[$i] =~ /[^\d,\s-]/;
+            my $span = $ranges_of_years[$i] //= Array::IntSpan->new();
+            return () unless $span; # bail out in case of problems
+            $span->set_range_as_string($years[$i], 1);
+        }
+    }
+
+    my @squashed_c;
+    for (my $i=0; $i < @$owners ; $i++) {
+        $ranges_of_years[$i]->consolidate();
+        $squashed_c[$i] = $ranges_of_years[$i]->get_range_list.', '.$owners->[$i];
+    }
+
+    return @squashed_c;
+}
+
 # $h is a tree of hash matching the directory structure. Each leaf is a
 # copyright id.
 sub __squash ($h) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libconfig-model-dpkg-perl.git



More information about the Pkg-perl-cvs-commits mailing list