blib/lib/Kwiki/Archive/Cvs.pm

filter: Statementstmt 23.8% 21 / 88 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 33.3% 6 / 18 Podpod 0.0% 0 / 12 totaltotal 18.7% 27 / 144 SCAR 44.9
CC
12
Cov
19%
parse_metadata
20.0
fetch_metadata
12.0
history
12.0
CRAP 88.8
↑ Summary
1 package Kwiki::Archive::Cvs;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Kwiki::Archive -Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our $VERSION = '0.105';
8  
9 # It will try to add files to CVS every time they're changed; this
10 # fails silently when they're already present.
11  
12 # Misinteractions:
13 # Kwiki::Revisions tries to show the previous revision for single-revision pages.
14 # Kwiki::Pages trips up on the CVS directory; change the line to
15 # map {chomp; $_} `ls -1t $path | fgrep -xv CVS`;
16 # for a quick-and-dirty fix.
17  
18  
19 # These should be read once and cached.
20  
21 0 ▶sub cvsSetting {
Subroutine cvsSetting: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my $page = shift;
23 0 my $setting = shift;
24  
25 0 ▶ my $l = io($page->database_directory."/CVS/$setting")->getline or die "Unable to read CVS/$setting: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $l = io($page->database_directory . "/CVS/$setting")->getline or die "Unable to read CVS/${setting}: $!" 0 0 0
26  
27 0 local ($/);
28 0 $/ = "\n";
29 0 chomp($l);
30 0 $l;
31 }
32  
33 0 ▶sub cvsRoot {
Subroutine cvsRoot: not called CC=1 SCAR=6.9
Pod undocumented
34 0 my $page = shift;
35 0 $self->cvsSetting($page, 'Root');
36 }
37  
38 0 ▶sub cvsRepository {
Subroutine cvsRepository: not called CC=1 SCAR=6.9
Pod undocumented
39 0 my $page = shift;
40 0 $self->cvsSetting($page, 'Repository');
41 }
42  
43 # Take responsibility for initialising this manually.
44 0 ▶sub empty {
Subroutine empty: not called CC=1 SCAR=6.9
Pod undocumented
45 0 0;
46 }
47  
48 0 ▶sub commit {
Subroutine commit: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my $page = shift;
50 0 my $props = $self->page_properties($page);
51  
52 # Unconditionally add (this command will fail once the file is added)
53 0 system('cvs', '-Q', '-d', $self->cvsRoot($page), 'add', $page->io);
54  
55 my $msg = join ',',
56 $self->uri_escape($props->{edit_by}),
57 $props->{edit_time},
58 0 $props->{edit_unixtime};
59  
60 # my $msg = join ',', map {
61 # $_ . ":" . $props->{$_}
62 # } sort keys %$props;
63  
64 0 $self->cvs($page, 'commit', '-m', $msg, $page->io);
65 }
66  
67 0 ▶sub revision_numbers {
Subroutine revision_numbers: not called CC=1 SCAR=6.9
Pod undocumented
68 0 my $page = shift;
69 0 [map $_->{revision_id}, @{$self->history($page)}];
70 }
71  
72 0 ▶sub fetch_metadata {
Subroutine fetch_metadata: not called CC=3 SCAR=24.8
Pod undocumented
73 0 my $page = shift;
74 0 my $rev = shift;
75  
76 0 ▶ my $rlog = io("cvs -Q -d ".$self->cvsRoot($page)." log -r1.$rev ".$page->io." |") or die $!;
Branch: 1 branch
BranchTrueFalseTotal
my $rlog = io('cvs -Q -d ' . $self->cvsRoot($page) . " log -r1.$rev " . $page->io . ' |') or die $! 0 0 0
77  
78 0 ▶ $rlog->utf8 if $self->has_utf8;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_utf8 0 0 0
79 0 $self->parse_metadata($rlog->all);
80 }
81  
82 0 ▶sub parse_metadata {
Subroutine parse_metadata: not called CC=4 SCAR=30.0
Pod undocumented
83 0 my $log = shift;
84 0 ▶ $log =~ /
Branch: 1 branch
BranchTrueFalseTotal
$log =~ / ^revision\s+(\S+).*? ^date:\s+(.+?);.*?\n (.*) /msx or die "Couldn't parse rlog:\n$log" 0 0 0
85 ^revision\s+(\S+).*?
86 ^date:\s+(.+?);.*?\n
87 (.*)
88 /xms or die "Couldn't parse rlog:\n$log";
89  
90 0 my $revision_id = $1;
91 # my $archive_date = $2;
92 0 my $msg = $3;
93 0 chomp $msg;
94  
95 0 $msg =~ s/"//g; # Get rid of quote marks from old CVS commit messages
96 0 my ($edit_by, $edit_time, $edit_unixtime) = split ',', $msg;
97 0 ▶ $edit_time ||= $2;
Condition0%0/3
$edit_time ||= $2
l!l&&r!l&&!r
000
MC/DC0%0/2
$edit_time ||= $2
$edit_time $2
Truth table0%0/3
A ||= B
A= $edit_timeB= $2
ABresult
1X1
011
000
98 0 ▶ $edit_unixtime ||= 0;
Condition0%0/2
$edit_unixtime ||= 0
l!l
00
MC/DC0%0/1
$edit_unixtime ||= 0
$edit_unixtime
Truth table0%0/2
A
A= $edit_unixtime
Aresult
11
00
99 0 $revision_id =~ s/^1\.//;
100  
101 return {
102 0 revision_id => $revision_id,
103 edit_by => $self->uri_unescape($edit_by),
104 edit_time => $edit_time,
105 edit_unixtime => $edit_unixtime,
106 };
107 }
108  
109 0 ▶sub history {
Subroutine history: not called CC=3 SCAR=24.8
Pod undocumented
110 0 my $page = shift;
111  
112 0 ▶ my $rlog = io("cvs -Q -d ".$self->cvsRoot($page)." log ".$page->io." |") or die $!;
Branch: 1 branch
BranchTrueFalseTotal
my $rlog = io('cvs -Q -d ' . $self->cvsRoot($page) . ' log ' . $page->io . ' |') or die $! 0 0 0
113  
114 0 ▶ $rlog->utf8 if $self->has_utf8;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_utf8 0 0 0
115  
116 0 my $input = $rlog->all;
117 0 $input =~ s/
118 \n=+$
119 .*\Z
120 //msx;
121 0 my @rlog = split /^-+\n/m, $input;
122 0 shift(@rlog);
123  
124 return [
125 0 map $self->parse_metadata($_), @rlog
126 ];
127 }
128  
129 0 ▶sub fetch {
Subroutine fetch: not called CC=3 SCAR=24.8
Pod undocumented
130 0 my $page = shift;
131 0 my $revision_id = shift;
132 0 my $revision = "1.$revision_id";
133 0 local($/, *CO);
134 0 ▶ open CO, "cvs -Q -d ".$self->cvsRoot($page)." checkout -r$revision -p ".$self->cvsRepository($page)."/".$page->id." |"
Branch: 1 branch
BranchTrueFalseTotal
open CO, 'cvs -Q -d ' . $self->cvsRoot($page) . " checkout -r$revision -p " . $self->cvsRepository($page) . '/' . $page->id . ' |' or die $! 0 0 0
135 or die $!;
136 0 ▶ binmode(CO, ':utf8') if $self->has_utf8;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_utf8 0 0 0
137 0 scalar <CO>;
138 }
139  
140 0 ▶sub shell {
Subroutine shell: not called CC=2 SCAR=10.9
Pod undocumented
141 1 ▶ use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
142 0 $! = undef;
143 0 ▶ system(@_) == 0
Branch: 1 branch
BranchTrueFalseTotal
system(@_) == 0 or die "@_ failed:\n$?\nin " . Cwd::cwd() 0 0 0
144 or die "@_ failed:\n$?\nin " . Cwd::cwd();
145 }
146  
147 0 ▶sub cvs {
Subroutine cvs: not called CC=1 SCAR=6.9
Pod undocumented
148 0 my $page = shift;
149 0 $self->shell('cvs', '-Q', '-d', $self->cvsRoot($page), @_);
150 }
151  
152 1 1;
153  
154 1 __DATA__
↑ Summary