VCI/VCS/Git/Directory.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 46 CC 5 SCAR 32.3
CC
5
Cov
0%
_build_contents
30.0
BEGIN
2.0
CRAP 25.3
1 package VCI::VCS::Git::Directory;
2 use Moose;
3  
4 extends 'VCI::Abstract::Directory';
5 with 'VCI::VCS::Git::Committable';
6  
7 # XXX This should probably be optimized to not build a File object for
8 # every file in the whole tree--it's a bit slow on the kernel sources
9 # (over 20,000 files).
10 sub _build_contents {
11 my $self = shift;
12 my @path_part;
13 @path_part = ('--', $self->path->stringify) unless $self->path->is_empty;
14 my $files = $self->project->x_do('ls-tree',
15 ['-r', $self->revision, @path_part]);
16
17 @$files = map { s/^\d+ \w+ \S+\s+//; $_ } @$files;
18
19 # Get the directory names from the output
20 my %dirs;
21 foreach my $line (@$files) {
22 # XXX This assumes the path separator is always /.
23 if ($line =~ m|^(.+)/[^/]+$|) {
24 $dirs{$1} = 1;
25 }
26 }
27
28 # Make sure that every dir has a parent in the list.
29 my @new_dirs;
30 my @check_dirs = keys %dirs;
31 my $found_parent = 1;
32 while ($found_parent) {
33 $found_parent = 0;
34 foreach my $dir (@check_dirs) {
35 # If this directory has a parent... (XXX path separator assumption)
36 if ($dir =~ m|^(.+)/[^/]+$|) {
37 my $parent_dir = $1;
38 # And that parent isn't already in the list...
39 if (!$dirs{$parent_dir}) {
40 push(@new_dirs, $parent_dir);
41 $found_parent = 1;
42 }
43 }
44 }
45
46 $dirs{$_} = 1 foreach @new_dirs;
47 @check_dirs = @new_dirs;
48 }
49
50 $self->_set_contents_from_list([keys %dirs], $files, $self->path->stringify);
51 return $self->{contents};
52 }
53  
54 __PACKAGE__->meta->make_immutable;
55  
56 1;