VCI/VCS/Hg/Commit.pm

filter: Statementstmt 21.9% 16 / 73 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.3% 4 / 11 Podpod 0.0% 0 / 1 totaltotal 19.4% 20 / 103 CC 12 SCAR 27.1
CC
12
Cov
18%
_build_x_changes
30.0
_build_as_diff
20.0
_diff_files
20.0
CRAP 15.1
« VCI/VCS/Bzr/Committable.pm ↑ Summary VCI/VCS/Git/Committable.pm »
1 package VCI::VCS::Hg::Commit;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use VCI::VCS::Hg::Diff;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use VCI::VCS::Hg::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 extends 'VCI::Abstract::Commit';
7  
8 1 has 'x_changes' => (is => 'ro', isa => 'HashRef', lazy_build => 1);
9  
10 1 ▶use constant DIFF_HEADER => qr/^([\-\+]{3}) (\S+)\t\w{3} \w{3} \d\d \d\d:\d\d:\d\d \d{4} [\+\-]\d{4}$/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # XXX Hg does have a concept of revno, but we can't access it via hgweb.
13 # So we have to use the default "revno is revision id".
14  
15 0 ▶sub _build_added {
Subroutine _build_added: not called CC=1 SCAR=6.9
16 0 my $self = shift;
17 0 my $files = $self->x_changes->{added};
18 0 return [map { $self->file_class->new(path => $_, project => $self->project,
19 revision => $self->revision, time => $self->time) }
20 @$files];
21 }
22  
23 0 ▶sub _build_removed {
Subroutine _build_removed: not called CC=1 SCAR=6.9
24 0 my $self = shift;
25 0 my $files = $self->x_changes->{removed};
26 0 return [map { $self->file_class->new(path => $_, project => $self->project,
27 revision => $self->revision, time => $self->time) }
28 @$files];
29 }
30  
31 0 ▶sub _build_modified {
Subroutine _build_modified: not called CC=1 SCAR=6.9
32 0 my $self = shift;
33 0 my $files = $self->x_changes->{modified};
34 0 return [map { $self->file_class->new(path => $_, project => $self->project,
35 revision => $self->revision, time => $self->time) }
36 @$files];
37 }
38  
39  
40 0 ▶sub x_from_rss_item {
Subroutine x_from_rss_item: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my ($class, $item, $project) = @_;
42 0 my $project_path = $project->repository->root . $project->name;
43 0 my $revision = $item->{'guid'}->{'content'};
44 # Older versions of hgweb have it in "link"
45 0 ▶ if (!$revision) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($revision) 0 0 0
46 0 $revision = $item->{'link'};
47 }
48
49 # Sometimes revisions come to us with log{$rev}. We also include
50 # log/$rev/File as an option in case they fix the bug in Hg.
51 0 $revision =~ s#^\Q$project_path\E(/rev/|/log[{/])##;
52 0 $revision =~ s#}?/.+$##;
53 0 my $time = $item->{pubDate};
54
55 0 my $message = $item->{description};
56 # As far as I know, this is the only HTML that hgweb adds here.
57 0 $message =~ s/<br\/>//g;
58
59 return $class->new(
60 message => $message,
61 revision => $revision,
62 time => $time,
63 committer => $item->{author},
64 0 project => $project);
65 }
66  
67 0 ▶sub _build_as_diff {
Subroutine _build_as_diff: not called CC=4 SCAR=30.0
68 0 my $self = shift;
69 0 my $text = $self->project->x_get(['raw-rev', $self->revision]);
70 0 my @lines = split("\n", $text);
71 0 my $line = shift @lines;
72 # XXX This may break if there's a line identical to DIFF_HEADER
73 # in the log message.
74 0 ▶ while ($line !~ DIFF_HEADER) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /^([\-\+]{3}) (\S+)\t\w{3} \w{3} \d\d \d\d:\d\d:\d\d \d{4} [\+\-]\d{4}$/) 0 0 0
75 0 $line = shift @lines;
76 0 ▶ last if (!defined $line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
77 }
78 0 ▶ unshift(@lines, $line) if defined $line;
Branch: 1 branch
BranchTrueFalseTotal
if defined $line 0 0 0
79 0 return $self->diff_class->new(raw => join("\n", @lines),
80 project => $self->project);
81 }
82  
83 # Mercurial doesn't say anything about directories in its logs, so we have
84 # no idea when directories are added or removed.
85  
86 0 ▶sub _build_x_changes {
Subroutine _build_x_changes: not called CC=5 SCAR=34.0
87 0 my $self = shift;
88 0 my $text = $self->as_diff->raw;
89 0 my $files = _diff_files($text);
90
91 0 my (@added, @removed, @modified);
92 0 foreach my $set (@$files) {
93 0 my ($file1, $file2) = @$set;
94 0 ▶ my $changed_file = $file1 eq '/dev/null' ? $file2 : $file1;
Branch: 1 branch
BranchTrueFalseTotal
$file1 eq '/dev/null' ? : 0 0 0
95 0 ▶ if ($file1 eq $file2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file1 eq $file2) { } 0 0 0
elsif ($file1 eq '/dev/null') { } 0 0 0
96 0 push(@modified, $changed_file);
97 }
98 elsif ($file1 eq '/dev/null') {
99 0 push(@added, $changed_file);
100 }
101 else {
102 0 push(@removed, $changed_file);
103 }
104 }
105 0 return { added => \@added, removed => \@removed, modified => \@modified };
106 }
107  
108 # There is currently a bug in Text::Diff::Parser where it doesn't process
109 # correctly beyond the first file in the diff. So I just do this manually
110 # instead of parsing the diff.
111 0 ▶sub _diff_files {
Subroutine _diff_files: not called CC=4 SCAR=30.0
112 0 my $text = shift;
113 0 my @files;
114 0 my @current_set = (undef, undef);
115 0 foreach my $line (split("\n", $text)) {
116 0 ▶ if ($line =~ DIFF_HEADER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([\-\+]{3}) (\S+)\t\w{3} \w{3} \d\d \d\d:\d\d:\d\d \d{4} [\+\-]\d{4}$/) 0 0 0
117 0 my ($type, $file) = ($1, $2);
118 # Strip a/ or b/ if the file starts with that.
119 0 $file =~ s|^[ab]/||;
120 0 ▶ if ($type eq '---') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq '---') { } 0 0 0
121 0 $current_set[0] = $file;
122 }
123 else {
124 0 $current_set[1] = $file;
125 0 push(@files, [@current_set]);
126 0 @current_set = (undef, undef);
127 }
128 }
129 }
130 0 return \@files;
131 }
132  
133 1 __PACKAGE__->meta->make_immutable;
134  
135 1 1;
« VCI/VCS/Bzr/Committable.pm ↑ Summary VCI/VCS/Git/Committable.pm »