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 4072342bf71f076b25e96e57da4cf58c754987d5 Author: Dominique Dumont <d...@debian.org> Date: Sat Jan 17 21:07:02 2015 +0100 Scanner: Also pack files when similar licenses are mingled --- lib/Dpkg/Copyright/Scanner.pm | 31 ++++++++++++++++++++++--------- t/scanner/pack_files.t | 31 ++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/lib/Dpkg/Copyright/Scanner.pm b/lib/Dpkg/Copyright/Scanner.pm index f785397..e9d31b3 100644 --- a/lib/Dpkg/Copyright/Scanner.pm +++ b/lib/Dpkg/Copyright/Scanner.pm @@ -109,8 +109,7 @@ sub scan_files { my $squashed = __squash($files); # pack files by copyright id - my @packed; - __pack_files($files,\@packed); + my @packed = __pack_files($files); my @copyright_data; @@ -153,21 +152,35 @@ sub __pack_copyright ($r) { #in each directory, pack files that have the same copyright/license information # traverse recursively %h (whose strcuture matches the scanned directory) # @path keeps track of the recursion depth to provide the file path -sub __pack_files ($h, $pack, @path) { - my $old_id ; +sub __pack_files ($h) { + + my @res ; + __pack_dir($h,\@res) ; + + # sort by first path listed in there + my $sort_path = sub { + $a->[1] cmp $b->[1]; + }; + + return sort $sort_path @res ; +} + +sub __pack_dir ($h, $pack, @path) { + my %pack_by_id; foreach my $file (sort keys %$h) { my $id = $h->{$file}; if (ref($id)) { - __pack_files($id, $pack, @path, $file) ; + __pack_dir($id, $pack, @path, $file) ; } - elsif (defined $old_id and $old_id == $id ) { - push $pack->[$#$pack]->@*, join('/',@path,$file); + elsif (defined $pack_by_id{$id} ) { + push $pack_by_id{$id}->@*, join('/',@path,$file); } else { - push @$pack, [ $id, join('/',@path,$file) ] ; + $pack_by_id{$id} = [ join('/',@path,$file) ] ; } - $old_id = $id; } + + push $pack->@*, map { [ $_, $pack_by_id{$_}->@* ]; } keys %pack_by_id ; } # $h is a tree of hash matching the directory structure. Each leaf is a diff --git a/t/scanner/pack_files.t b/t/scanner/pack_files.t index 7866ccc..14bc534 100644 --- a/t/scanner/pack_files.t +++ b/t/scanner/pack_files.t @@ -67,10 +67,10 @@ pan: [ [ 0,'*' ], [ 4,'pan/*' ], + [ 1,'pan/data-impl/defgroup.h' ], [ 5,'pan/data/cert-store.cc','pan/data/cert-store.h' ], [ 1,'pan/data/defgroup.h' ], [ 3,'pan/data/parts.cc','pan/data/parts.h' ], - [ 1,'pan/data-impl/defgroup.h' ], [ 1,'pan/general/debug.cc','pan/general/defgroup.h' ], [ 8,'pan/general/e-util.cc','pan/general/e-util.h' ], [ 1,'pan/gui/action-manager.h','pan/gui/defgroup.h' ], @@ -79,13 +79,38 @@ pan: [ 4,'pan/icons/*' ], ] ], + [ + 'interspersed copyrights', + "--- +include: + SDL.h: 2 + SDL_copying.h: 2 + SDL_cpuinfo.h: 2 + SDL_egl.h: 3 + SDL_endian.h: 2 + SDL_mutex.h: 2 + SDL_name.h: 0 + SDL_opengl.h: 2 + SDL_opengles.h: 2 + SDL_opengles2.h: 3 + SDL_pixels.h: 2 + SDL_render.h: 2 + SDL_revision.h: 0 + SDL_rwops.h: 2 + close_code.h: 2 +", + [ + [ 2,'include/SDL.h','include/SDL_copying.h','include/SDL_cpuinfo.h','include/SDL_endian.h','include/SDL_mutex.h','include/SDL_opengl.h','include/SDL_opengles.h','include/SDL_pixels.h','include/SDL_render.h','include/SDL_rwops.h','include/close_code.h'], + [ 3,'include/SDL_egl.h','include/SDL_opengles2.h'], + [ 0,'include/SDL_name.h','include/SDL_revision.h'], + ] + ] ); foreach my $t (@tests) { my ($label,$in,$expect) = @$t; - my @res ; - Dpkg::Copyright::Scanner::__pack_files(Load($in),\@res); + my @res = Dpkg::Copyright::Scanner::__pack_files(Load($in)); eq_or_diff(\@res,$expect,"__pack_files $label"); } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libconfig-model-dpkg-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits