VCI/VCS/Svn/Directory.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 85 CC 8 SCAR 38.1
CC
8
Cov
0%
_build_contents
72.0
_x_handle_svn_failure
2.0
_me_from
2.0
CRAP 45.1
1 package VCI::VCS::Svn::Directory;
2 use Moose;
3  
4 use Path::Abstract::Underload;
5 use SVN::Core;
6  
7 with 'VCI::VCS::Svn::Committable';
8 extends 'VCI::Abstract::Directory';
9  
10 # There's a bug in the SVN API that causes it to segfault if you don't
11 # die inside an error handler. So in order to get details about an error,
12 # we die with a reference to the error.
13 sub _x_handle_svn_failure { die $_[0]; }
14  
15 sub _build_contents {
16 my $self = shift;
17 my $project = $self->project;
18 my $vci = $project->vci;
19 my $ra = $project->repository->x_ra;
20 my $dir_path = Path::Abstract::Underload->new($project->name, $self->path);
21 print STDERR "Getting contents for " . $dir_path->stringify
22 . " rev " . $self->revision . "\n"
23 if $vci->debug;
24  
25 my @info;
26 {
27 local $SVN::Error::handler = \&_x_handle_svn_failure;
28 eval { @info = $ra->get_dir($dir_path->stringify, $self->revision) };
29 }
30
31 # When a directory has been copied, and hasn't been modified since,
32 # SVN says the last revision of its contents is the revision the directory
33 # was copied *from*.
34 # However, when you try to get the contents of the path at that
35 # revision, SVN throws error 175007, meaning "path not found."
36 # So, to handle that, we find the place our parent was copied from,
37 # and get the contents of that, at that revision.
38 if (ref($@) && $@->apr_err == 175007) {
39 my $history = $self->history;
40 my $parent_from;
41 foreach my $commit (@{$history->commits}) {
42 $parent_from = $commit->copied->{$self->parent->path->stringify};
43 last if $parent_from;
44 }
45 SVN::Error::croak_on_error($@) if !$parent_from;
46 $@->clear();
47 my ($my_source) = grep ($_->name eq $self->name,
48 @{$parent_from->contents});
49 if ($vci->debug) {
50 print STDERR $self->path, " was copied from ", $my_source->path,
51 "\n";
52 }
53 return $my_source->contents;
54 }
55 else {
56 SVN::Error::croak_on_error($@);
57 }
58
59 my $svn_contents = shift @info;
60 my @contents;
61 foreach my $name (keys %$svn_contents) {
62 my $item = $svn_contents->{$name};
63 my $path = Path::Abstract::Underload->new($self->path, $name);
64 if ($item->kind == $SVN::Node::dir) {
65 my $dir = VCI::VCS::Svn::Directory->new(
66 path => $path, project => $project, parent => $self,
67 x_info => $item);
68 push(@contents, $dir);
69 }
70 elsif ($item->kind == $SVN::Node::file) {
71 my $file = $self->file_class->new(
72 path => $path, project => $project, parent => $self,
73 x_info => $item);
74 push(@contents, $file);
75 }
76 }
77
78 return \@contents;
79 }
80  
81 # We have to do this because ->isa File or Directory never
82 # returns true on a FileOrDirectory.
83 sub _me_from {
84 my $self = shift;
85 my $orig_class = blessed $self;
86 bless $self, 'VCI::VCS::Svn::FileOrDirectory';
87 my $ret = $self->SUPER::_me_from(@_);
88 bless $self, $orig_class;
89 bless $ret, $orig_class;
90 return $ret;
91 };
92  
93 __PACKAGE__->meta->make_immutable;
94  
95 1;