blib/lib/SVN/Dumpfilter.pm

filter: Statementstmt 13.7% 38 / 276 Branchbran 0.0% 0 / 152 Conditioncond 0.0% 0 / 72 MC/DCmcdc 0.0% 0 / 42 Subroutinesub 40.0% 10 / 25 Podpod 0.0% 0 / 14 totaltotal 8.2% 48 / 581 CC 106 SCAR 58.9
CC
106
Cov
8%
Dumpfilter
930.0
svn_header_sanitycheck
552.0
svn_read_entry
182.0
CRAP 362.3
↑ Summary
1 #!/usr/bin/perl -w
2 # $Id: Dumpfilter.pm 278 2007-01-13 12:37:13Z martin $
3 # Copyright (C) 2006-2008 by Martin Scharrer <martin@scharrer-online.de>
4 # This is free software under the GPL.
5  
6 package SVN::Dumpfilter;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use 5.8.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 our ( $VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
15  
16 #use version; $ VERSION = qv('0.21');
17 1 $VERSION = '0.21';
18  
19 1 @ISA = qw(Exporter);
20 1 @EXPORT = qw(&Dumpfilter &svn_recalc_content_header
21 &svn_recalc_textcontent_header &svn_recalc_prop_header);
22 1 %EXPORT_TAGS = (
23 'recalc' => [
24 qw(svn_recalc_content_header svn_recalc_textcontent_header
25 svn_recalc_prop_header)
26 ],
27 'filters' => [qw(dos2unix_filter null_filter null_recalc_filter)],
28 'internal' => [
29 qw(svn_read_entry svn_print_entry svn_get_properties
30 svn_props2str svn_header_sanitycheck)
31 ],
32 );
33 1 @EXPORT_OK = qw(&svn_get_properties &svn_props2str &svn_header_sanitycheck
34 &svn_read_entry &svn_print_entry &dos2unix_filter
35 &null_filter &null_recalc_filter &svn_remove_entry);
36 }
37 1 our @EXPORT_OK;
38  
39 #use Data::Dumper; # for Debug output
40 1 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 our $dumpfile;
43 1 our $filepos;
44 1 our $dumpfh;
45 1 our $outfh;
46  
47 1 ▶use vars qw($CR $NL);
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
50 # "\n" and "\r" are not fully platform independend.
51 # So explicite ASCII numbers in octal are used.
52 # Variables, not constants, are used because these are used inside regexes.
53 1 $CR = "\015"; # carriage return
54 1 $NL = "\012"; # new line
55 }
56  
57 sub svn_get_properties (\%\@$);
58 sub svn_props2str (\%;\@);
59 sub svn_header_sanitycheck (\%);
60 sub svn_recalc_content_header(\%);
61 sub svn_recalc_textcontent_header(\%);
62 sub svn_recalc_prop_header(\%);
63 sub svn_read_entry (*\%;$);
64 sub svn_print_entry(*\%);
65 sub svn_remove_entry (\%);
66  
67 # Filter
68 sub null_filter (\%;$);
69 sub null_recalc_filter (\%;$);
70 sub dos2unix_filter (\%;$);
71  
72 1 my @SVNHEADER = qw(
73 Revision-number
74 Node-path
75 Node-kind
76 Node-action
77 Node-copyfrom-rev
78 Node-copyfrom-path
79 Prop-delta
80 Prop-content-length
81 Text-delta
82 Text-content-length
83 Text-copy-source-md5
84 Text-content-md5
85 Content-length
86 );
87  
88 # "inverse array", maps name to index:
89 #my %svnhdridx = map { $SVNHEADER[$_] => $_ } (0 .. $#SVNHEADER);
90  
91 0 ▶sub _supported_dump_format_version {
Subroutine _supported_dump_format_version: not called CC=2 SCAR=17.9
92 0 my $version = shift;
93  
94 # Versions 1 - 3 are supported
95 0 ▶ return ( $version >= 1 && $version <= 3 );
Condition0%0/3
$version >= 1 && $version <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$version >= 1 && $version <= 3
$version >= 1 $version <= 3
Truth table0%0/3
A && B
A= $version >= 1B= $version <= 3
ABresult
0X0
100
111
96 }
97  
98 ###############################################################################
99 # Dumpfilter
100 ####
101 # Awaits the dumpfile name, an output file name and a reference to a call-back
102 # function. While parsing the dumpfile the call-back function is called for
103 # every node and the result is re-assembled and written to the output file.
104  
105 0 ▶sub Dumpfilter {
Subroutine Dumpfilter: not called CC=30 SCAR=68.4
Pod undocumented
106 0 $dumpfile = shift;
107 0 my $outfile = shift;
108 0 my $filtersub = shift;
109  
110 0 ▶ if ( !defined $dumpfile ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $SVN::Dumpfilter::dumpfile) 0 0 0
111 0 $dumpfile = '-'; # Defaults to STDIN
112 }
113  
114 0 ▶ if ( !defined $outfile ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $outfile) { } 0 0 0
elsif ($outfile eq '') { } 0 0 0
115 0 $outfile = '-'; # Defaults to STDOUT
116 }
117 elsif ( $outfile eq q{} ) {
118 0 $outfile = undef; # An empty string disables output
119 }
120  
121 0 ▶ if ( !defined $filtersub || ref $filtersub ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $filtersub or ref $filtersub ne "CODE") 0 0 0
Condition0%0/3
not defined $filtersub or ref $filtersub ne "CODE"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $filtersub or ref $filtersub ne "CODE"
not defined $filtersub ref $filtersub ne "CODE"
Truth table0%0/3
not(A) or B
A= not defined $filtersubB= ref $filtersub ne "CODE"
ABresult
1X1
011
000
122 0 print STDERR "No filter function given!\n";
123 0 return 1;
124 }
125  
126 0 my $dumpfileerror = 0;
127  
128 0 my $SVN_fs_dump_format_version;
129 my $UUID;
130  
131 0 ▶ unless ( open( $dumpfh, "<$dumpfile" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $SVN::Dumpfilter::dumpfh, "<$SVN::Dumpfilter::dumpfile") 0 0 0
132 0 print STDERR "Couldn't open dumpfile '$dumpfile'.\n";
133 0 return 1;
134 }
135  
136 0 ▶ if ( defined $outfile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $outfile) 0 0 0
137 0 ▶ unless ( open( $outfh, ">$outfile" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $SVN::Dumpfilter::outfh, ">$outfile") 0 0 0
138 0 print STDERR "Couldn't open output file '$outfile'.\n";
139 0 return 1;
140 }
141 }
142  
143 0 my $line;
144 0 local $INPUT_RECORD_SEPARATOR = $NL;
145 0 ▶ if ( defined( $line = <$dumpfh> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^SVN-fs-dump-format-version: (\d+)$/) { } 0 0 0
Condition0%0/3
defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^SVN-fs-dump-format-version: (\d+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^SVN-fs-dump-format-version: (\d+)$/
defined($line = readline $SVN::Dumpfilter::dumpfh) $line =~ /^SVN-fs-dump-format-version: (\d+)$/
Truth table0%0/3
A and B
A= defined($line = readline $SVN::Dumpfilter::dumpfh)B= $line =~ /^SVN-fs-dump-format-version: (\d+)$/
ABresult
0X0
100
111
146 && $line =~ /^SVN-fs-dump-format-version: (\d+)$/ )
147 {
148 0 $SVN_fs_dump_format_version = $1;
149 0 ▶ if ( !_supported_dump_format_version($SVN_fs_dump_format_version) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_supported_dump_format_version($SVN_fs_dump_format_version)) 0 0 0
150 0 print STDERR "Warning: Found dump format version ",
151 "($SVN_fs_dump_format_version) is not supported (yet).\n",
152 "Unknown entries will be ignored. Use at your own risk.\n";
153 }
154 0 ▶ print $outfh $line if defined $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if defined $outfile 0 0 0
155 }
156 else {
157 0 print STDERR "Error: Dumpfile looks invalid. Couldn't find valid ",
158 "'SVN-fs-dump-format-version' header.\n";
159 0 chomp($line);
160 0 ▶ print STDERR "Found '$line' instead.\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $line 0 0 0
161 if defined($line);
162 0 return 1;
163 }
164  
165 # Skip empty lines
166 0 ▶ while ( defined( $line = <$dumpfh> ) && $line =~ /^$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/) 0 0 0
Condition0%0/3
defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/
defined($line = readline $SVN::Dumpfilter::dumpfh) $line =~ /^$/
Truth table0%0/3
A and B
A= defined($line = readline $SVN::Dumpfilter::dumpfh)B= $line =~ /^$/
ABresult
0X0
100
111
167 0 ▶ print $outfh $line if defined $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if defined $outfile 0 0 0
168 }
169 0 ▶ return 1 unless defined($line); # check for early EOF
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
170  
171 0 ▶ if ( $line =~ /^UUID: (.*)$/ ) # Save UUID if present
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^UUID: (.*)$/) 0 0 0
172 {
173 0 $UUID = $1;
174 0 ▶ print $outfh $line if defined $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if defined $outfile 0 0 0
175  
176 # Skip empty lines
177 0 ▶ while ( defined( $line = <$dumpfh> ) && $line =~ /^$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/) 0 0 0
Condition0%0/3
defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/
defined($line = readline $SVN::Dumpfilter::dumpfh) $line =~ /^$/
Truth table0%0/3
A and B
A= defined($line = readline $SVN::Dumpfilter::dumpfh)B= $line =~ /^$/
ABresult
0X0
100
111
178 0 ▶ print $outfh $line if defined $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if defined $outfile 0 0 0
179 }
180 }
181  
182 0 ▶ return 1 unless defined($line); # check for early EOF
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
183  
184 0 while (1) {
185 0 my $href = {}; # Reference to hash which will hold next entry
186  
187 # Read next entry into hash
188 0 $dumpfileerror += svn_read_entry( *$dumpfh, %$href, $line );
189  
190 # Filter code comes here
191 # We call a filter subfunction and pass everything as a hash
192 0 &{$filtersub}($href);
193  
194 # Reassemble of dump data
195 0 ▶ next unless ($outfile); # skip if we don't have an output file
Branch: 1 branch
BranchTrueFalseTotal
unless $outfile 0 0 0
196 0 svn_print_entry( *$outfh, %$href );
197 }
198 continue {
199  
200 # Skip empty lines
201 0 ▶ while ( defined( $line = <$dumpfh> ) && $line =~ /^$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/) 0 0 0
Condition0%0/3
defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($line = readline $SVN::Dumpfilter::dumpfh) and $line =~ /^$/
defined($line = readline $SVN::Dumpfilter::dumpfh) $line =~ /^$/
Truth table0%0/3
A and B
A= defined($line = readline $SVN::Dumpfilter::dumpfh)B= $line =~ /^$/
ABresult
0X0
100
111
202 0 ▶ print $outfh $line if defined $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if defined $outfile 0 0 0
203 }
204 0 ▶ last unless defined($line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
205 }
206  
207 0 close($dumpfh);
208 0 ▶ close($outfh) if defined $outfile;
Branch: 1 branch
BranchTrueFalseTotal
if defined $outfile 0 0 0
209 0 return $dumpfileerror;
210 }
211  
212 #################
213 # Null filter - does nothing
214 # For before-after self-checks
215  
216 0 ▶sub null_filter (\%;$) {
Subroutine null_filter: not called CC=1 SCAR=0.0
Pod undocumented
217 }
218  
219 #################
220 # Null Recalc filter - does nothing except recalculation of headers
221 # For before-after self-checks
222  
223 0 ▶sub null_recalc_filter (\%;$) {
Subroutine null_recalc_filter: not called CC=3 SCAR=24.8
Pod undocumented
224 0 my $href = shift;
225 0 ▶ my $recalc = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
226  
227 0 ▶ if ($recalc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recalc) 0 0 0
228 0 svn_recalc_prop_header(%$href);
229 0 svn_recalc_textcontent_header(%$href);
230 }
231 }
232  
233 #################
234 # Dos to Unix filter - changes end-of-line sequences
235  
236 0 ▶sub dos2unix_filter (\%;$) {
Subroutine dos2unix_filter: not called CC=9 SCAR=45.0
Pod undocumented
237 0 my $href = shift;
238 0 ▶ my $recalc = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
239  
240 0 my $header = $href->{'header'};
241 0 my $prop = $href->{'properties'};
242  
243 # return when no content present
244 0 ▶ return unless exists $header->{'Text-content-length'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $header->{"Text-content-length"} 0 0 0
245  
246 # skip all files which have a mime-type set to something other than 'text/*'
247 return
248 if exists $prop->{'svn:mime-type'}
249 0 ▶ and $prop->{'svn:mime-type'} !~ m{^text/};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prop->{"svn:mime-type"} and not $prop->{"svn:mime-type"} =~ m[^text/] 0 0 0
Condition0%0/3
exists $prop->{"svn:mime-type"} and not $prop->{"svn:mime-type"} =~ m[^text/]
!ll&&!rl&&r
000
MC/DC0%0/2
exists $prop->{"svn:mime-type"} and not $prop->{"svn:mime-type"} =~ m[^text/]
exists $prop->{"svn:mime-type"} not $prop->{"svn:mime-type"} =~ m[^text/]
Truth table0%0/3
A and not(B)
A= exists $prop->{"svn:mime-type"}B= not $prop->{"svn:mime-type"} =~ m[^text/]
ABresult
0X0
100
111
250 0 ▶ return if exists $prop->{'svn:eol-style'}; # skip if eol-style is set
Branch: 1 branch
BranchTrueFalseTotal
if exists $prop->{"svn:eol-style"} 0 0 0
251 # Skip when text is saved as deltas
252 return
253 if exists $header->{'Text-delta'}
254 0 ▶ and lc( $header->{'Text-delta'} ) eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if exists $header->{"Text-delta"} and lc $header->{"Text-delta"} eq "true" 0 0 0
Condition0%0/3
exists $header->{"Text-delta"} and lc $header->{"Text-delta"} eq "true"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $header->{"Text-delta"} and lc $header->{"Text-delta"} eq "true"
exists $header->{"Text-delta"} lc $header->{"Text-delta"} eq "true"
Truth table0%0/3
A and B
A= exists $header->{"Text-delta"}B= lc $header->{"Text-delta"} eq "true"
ABresult
0X0
100
111
255  
256 0 ${ $href->{'content'} } =~ s/$CR$NL/$NL/mog;
257  
258 # Set eol-style:
259 0 push( @{ $href->{'properties_order'} }, 'svn:eol-style' );
260 0 $prop->{'svn:eol-style'} = 'native';
261  
262 0 ▶ if ($recalc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recalc) 0 0 0
263 0 svn_recalc_prop_header(%$href);
264 0 svn_recalc_textcontent_header(%$href);
265 }
266 }
267  
268 #################
269 # new_scalar_ref - Creates and returns a new scalar reference
270  
271 0 ▶sub new_scalar_ref () {
Subroutine new_scalar_ref: not called CC=1 SCAR=6.9
Pod undocumented
272 0 my $new;
273 0 return \$new; # For C-Programmers: Yes, this works under Perl!
274 }
275  
276 #################
277 # svn_read_entry - Read node entry from filehandle
278  
279 0 ▶sub svn_read_entry (*\%;$) {
Subroutine svn_read_entry: not called CC=13 SCAR=52.0
Pod undocumented
280 0 my $infh = shift; # Filehandle to read
281 0 my $href = shift; # (Empty) Hash (as reference) to write node
282 0 my $line = shift; # Optional: First line (already read before)
283 0 my $error = 0;
284  
285 # Init hash
286 0 my $header = ( $href->{'header'} = {} );
287 0 my $prop = ( $href->{'properties'} = {} );
288 0 my $prop_order = ( $href->{'properties_order'} = [] );
289 0 my $content = ( $href->{'content'} = new_scalar_ref );
290  
291 0 $filepos = tell($infh);
292  
293 0 local $INPUT_RECORD_SEPARATOR = $NL; # New line
294  
295 0 ▶ $line = <$dumpfh>
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
296 unless defined $line;
297  
298 # Should be 'Node-path: ' or 'Revision-number: ' now
299 0 ▶ if ( $line !~ /^(Node-path|Revision-number): / ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /^(Node-path|Revision-number): /) 0 0 0
300 0 chomp($line);
301 0 print STDERR
302 "Read error in dumpfile '$dumpfile' at line '$.'. Skipping line: '$line'\n";
303 0 $error++;
304 }
305  
306 # Read headers
307 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
defined($line = readline $infh) and not $line =~ /^$/ and do { do { if ($line =~ /^([^:]+):\s*(.*)$/) { $header->{$1} = $2; } else { print STDERR "Error in header at input line $.\n"; ++$error; } } } 0 0 0
Condition0%0/3
defined($line = readline $infh) and not $line =~ /^$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($line = readline $infh) and not $line =~ /^$/
defined($line = readline $infh) not $line =~ /^$/
Truth table0%0/3
A and not(B)
A= defined($line = readline $infh)B= not $line =~ /^$/
ABresult
0X0
100
111
308 0 ▶ if ( $line =~ /^([^:]+):\s*(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([^:]+):\s*(.*)$/) { } 0 0 0
309 0 $header->{$1} = $2;
310 }
311 else {
312 0 print STDERR "Error in header at input line $.\n";
313 0 $error++;
314 }
315 } while ( defined( $line = <$infh> ) && $line !~ /^$/ );
316 0 ▶ last unless defined($line); # Safety check for EOF
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
317  
318 # Get properties when they exist (but then they can be empty also!)
319 0 ▶ if ( exists $header->{'Prop-content-length'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $header->{"Prop-content-length"}) 0 0 0
320 0 my $prop_lines;
321 0 read $infh, $prop_lines, $header->{'Prop-content-length'};
322 0 ▶ $.++ while ( $prop_lines =~ /$NL/go ); # Count lines
Branch: 1 branch
BranchTrueFalseTotal
$prop_lines =~ /$SVN::Dumpfilter::NL/go and do { ++$. } 0 0 0
323  
324 0 ▶ if ( not $prop_lines =~ s/PROPS-END$NL\Z//o ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prop_lines =~ s/PROPS-END$SVN::Dumpfilter::NL\Z//o) 0 0 0
325 0 print STDERR
326 "Didn't found 'PROPS-END' where it was expected at input line $.\n";
327 0 $error++;
328 }
329  
330 # Parse lines and extract properties:
331 0 ▶ unless ( svn_get_properties( %$prop, @$prop_order, $prop_lines ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&svn_get_properties(\%$prop, \@$prop_order, $prop_lines)) 0 0 0
332 0 $error++;
333 }
334 }
335  
336 # Get content
337 0 ▶ if ( exists( $header->{'Text-content-length'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $header->{"Text-content-length"}) 0 0 0
338 0 read $infh, $$content, $header->{'Text-content-length'};
339 0 ▶ $.++ while ( $$content =~ /$NL/go ); # Count lines
Branch: 1 branch
BranchTrueFalseTotal
$$content =~ /$SVN::Dumpfilter::NL/go and do { ++$. } 0 0 0
340 # TODO: check number of bytes returned
341 }
342  
343 # Some sanity checks:
344 0 $error += svn_header_sanitycheck(%$header);
345  
346 0 return $error;
347 }
348  
349 #################
350 ## svn_print_entry - Write node entry to filehandle
351  
352 0 ▶sub svn_print_entry (*\%) {
Subroutine svn_print_entry: not called CC=11 SCAR=48.8
Pod undocumented
353 0 my $fh = shift; # Filehandle to write to
354 0 my $href = shift; # Hash (as reference) with node to be written
355 0 my $header = $href->{'header'};
356 0 my $prop = $href->{'properties'};
357  
358 0 ▶ return unless ( keys %$header ); # skip if there are no header
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$header 0 0 0
359  
360 # Header
361 # We try to print all header in the original order.
362 {
363  
364 # Generate hash to check if all header are printed
365 0 my %header_notprinted = map { $_ => 0 } keys %$header;
366  
367 # Print header in the standard order given by @SVNHEADER
368 0 foreach my $head (@SVNHEADER) {
369 0 ▶ if ( exists $header->{$head} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $header->{$head}) 0 0 0
370 0 print $fh "$head: $header->{$head}" . $NL;
371 0 delete $header_notprinted{$head}; # delete from check-hash
372 }
373 }
374  
375 # Print all remaining (non-standard?) header
376 0 foreach my $head ( sort keys %header_notprinted ) {
377 0 print $fh "$head: $header->{$head}" . $NL;
378 0 print STDERR "Info: header '$head' unknown by script.\n";
379 }
380 0 print $fh $NL; # delimiter
381 }
382  
383 # Properties
384 0 ▶ if ( exists $header->{'Prop-content-length'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $header->{"Prop-content-length"} and $header->{"Prop-content-length"} > 0) 0 0 0
Condition0%0/3
exists $header->{"Prop-content-length"} and $header->{"Prop-content-length"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
exists $header->{"Prop-content-length"} and $header->{"Prop-content-length"} > 0
exists $header->{"Prop-content-length"} $header->{"Prop-content-length"} > 0
Truth table0%0/3
A and B
A= exists $header->{"Prop-content-length"}B= $header->{"Prop-content-length"} > 0
ABresult
0X0
100
111
385 and $header->{'Prop-content-length'} > 0 )
386 {
387 0 ▶ if ( exists $href->{'properties_order'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $href->{'properties_order'}) { } 0 0 0
388 0 print $fh svn_props2str( %$prop, @{ $href->{'properties_order'} } );
389 }
390 0 else { print $fh svn_props2str(%$prop) }
391 0 print $fh "PROPS-END" . $NL;
392 }
393  
394 # Content
395 0 ▶ if ( exists $header->{'Text-content-length'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $header->{"Text-content-length"} and $header->{"Text-content-length"} > 0 and exists $href->{"content"}) 0 0 0
Condition0%0/6
exists $header->{"Text-content-length"} and $header->{"Text-content-length"} > 0 and exists $href->{"content"}
!ll&&!rl&&r
000
exists $header->{"Text-content-length"} and $header->{"Text-content-length"} > 0
!ll&&!rl&&r
000
MC/DC0%0/3
exists $header->{"Text-content-length"} and $header->{"Text-content-length"} > 0 and exists $href->{"content"}
exists $header->{"Text-content-length"} $header->{"Text-content-length"} > 0 exists $href->{"content"}
Truth table0%0/4
A and B and C
A= exists $header->{"Text-content-length"}B= $header->{"Text-content-length"} > 0C= exists $href->{"content"}
ABCresult
0XX0
10X0
1100
1111
396 and $header->{'Text-content-length'} > 0
397 and exists $href->{'content'} )
398 {
399 0 print $fh ${ $href->{'content'} };
400 }
401 }
402  
403 #################
404 ## svn_recalc_content_header - Recalculate 'Content-length' header
405 #####
406 # Depends on correct values in other headers.
407 # Will be called by other recalc-functions.
408  
409 0 ▶sub svn_recalc_content_header(\%) {
Subroutine svn_recalc_content_header: not called CC=3 SCAR=20.0
Pod undocumented
410 0 my $href = shift;
411 0 my $header = $href->{'header'};
412 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
413  
414 0 my $header_existed = exists $header->{'Content-length'};
415  
416 $header->{'Content-length'} =
417 0 $header->{'Text-content-length'} + $header->{'Prop-content-length'};
418  
419 0 ▶ if ( $header->{'Content-length'} == 0 && !$header_existed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header->{"Content-length"} == 0 and not $header_existed) 0 0 0
Condition0%0/3
$header->{"Content-length"} == 0 and not $header_existed
!ll&&!rl&&r
000
MC/DC0%0/2
$header->{"Content-length"} == 0 and not $header_existed
$header->{"Content-length"} == 0 not $header_existed
Truth table0%0/3
A and not(B)
A= $header->{"Content-length"} == 0B= not $header_existed
ABresult
0X0
100
111
420 0 delete $header->{'Content-length'};
421 }
422 }
423  
424 #################
425 ## svn_recalc_textcontent_header - Recalculate 'Text-content'* and dependend headers
426 #####
427  
428 0 ▶sub svn_recalc_textcontent_header(\%) {
Subroutine svn_recalc_textcontent_header: not called CC=4 SCAR=30.0
Pod undocumented
429 0 my $href = shift;
430 0 my $header = $href->{'header'};
431  
432 0 my $header_existed = exists $header->{'Text-content-length'};
433  
434 my $length =
435 defined $href->{'content'}
436 0 ▶ ? length ${ $href->{'content'} }
Branch: 1 branch
BranchTrueFalseTotal
defined $href->{'content'} ? : 0 0 0
437 : 0;
438  
439 0 ▶ if ( $length == 0 and !$header_existed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length == 0 and not $header_existed) { } 0 0 0
Condition0%0/3
$length == 0 and not $header_existed
!ll&&!rl&&r
000
MC/DC0%0/2
$length == 0 and not $header_existed
$length == 0 not $header_existed
Truth table0%0/3
A and not(B)
A= $length == 0B= not $header_existed
ABresult
0X0
100
111
440 0 delete $header->{'Text-content-length'};
441 0 delete $header->{'Text-content-md5'};
442 }
443 else {
444 0 $header->{'Text-content-length'} = $length;
445 0 $header->{'Text-content-md5'} = md5_hex( ${ $href->{'content'} } );
446 }
447  
448 0 svn_recalc_content_header(%$href);
449 }
450  
451 #################
452 ## svn_recalc_prop_header - Recalculate 'Prop-content-length' and dependend headers
453 #####
454  
455 0 ▶sub svn_recalc_prop_header(\%) {
Subroutine svn_recalc_prop_header: not called CC=2 SCAR=17.9
Pod undocumented
456 0 my $href = shift;
457 0 my $header = $href->{'header'};
458 0 my $prop = $href->{'properties'};
459  
460 0 ▶ return unless keys %$prop; # do nothing when no properties are present
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$prop 0 0 0
461  
462 # Correct properties length:
463 $header->{'Prop-content-length'} = 10 # for the "PROPS-END$NL" string
464 0 + length( svn_props2str( %{ $href->{'properties'} } ) );
465 0 svn_recalc_content_header(%$href);
466 }
467  
468 #################
469 ## svn_get_properties - Extracts properties from a formatted string
470 #####
471 # Opposite of 'svn_props2str'
472 # Could also be called 'svn_str2props'
473  
474 0 ▶sub svn_get_properties (\%\@$) {
Subroutine svn_get_properties: not called CC=11 SCAR=48.8
Pod undocumented
475 0 my $prophash = shift; # Hash reference to store properties
476 0 my $proporder = shift; # Array ref. to store order of properties
477 0 my $props = shift; # String in SVN property format to parse
478  
479 # Parse string
480 0 ▶ while ( defined($props) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $props) 0 0 0
481  
482 # Look for Keyword
483 0 ▶ ( $props =~ s/^K (\d+)$NL//o ) or last;
Branch: 1 branch
BranchTrueFalseTotal
$props =~ s/^K (\d+)$SVN::Dumpfilter::NL//o or last 0 0 0
484 0 my $key = substr( $props, 0, $1, '' ); # get key with length given by
485 # above line and replace it with an null-string
486 0 $props =~ s/^$NL//o; # delete trailing new-line
487  
488 # Look for Value
489 0 ▶ ( $props =~ s/^V (\d+)$NL//o ) or last;
Branch: 1 branch
BranchTrueFalseTotal
$props =~ s/^V (\d+)$SVN::Dumpfilter::NL//o or last 0 0 0
490 0 my $value =
491 substr( $props, 0, $1, '' ); # get value with length given by
492 # above line and replace it with an null-string
493 0 $props =~ s/^$NL//o; # delete trailing new-line
494  
495 # Save
496 0 push( @$proporder, $key );
497 0 $prophash->{$key} = $value;
498 }
499  
500 # Deleted properties
501 0 ▶ while ( defined($props) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $props) 0 0 0
502 0 ▶ ( $props =~ s/^D (\d+)$NL//o ) or last;
Branch: 1 branch
BranchTrueFalseTotal
$props =~ s/^D (\d+)$SVN::Dumpfilter::NL//o or last 0 0 0
503 0 my $key = substr( $props, 0, $1, '' ); # get key with length given by
504 # above line and replace it with an null-string
505 0 $props =~ s/^($NL)//o; # delete trailing new-line
506 0 ▶ $prophash->{__DELETED_PROPERTIES__} .= $key . ( defined($1) ? $1 : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 0 0 0
507 }
508  
509 # Read unkown but valid looking entries
510 0 ▶ while ( defined($props) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $props) 0 0 0
511 0 ▶ ( $props =~ s/^([A-Z] (\d+)$NL)//o ) or last;
Branch: 1 branch
BranchTrueFalseTotal
$props =~ s/^([A-Z] (\d+)$SVN::Dumpfilter::NL)//o or last 0 0 0
512 0 my $head = $1;
513 0 my $key = substr( $props, 0, $2, '' ); # get key with length given by
514 # above line and replace it with an null-string
515 0 $props =~ s/^($NL)//o; # delete trailing new-line
516 0 print STDERR "Error: Found unknown entry in property field:\n------\n",
517 $head, $key, "\n";
518 $prophash->{__UNKNOWN_PROPERTY_ENTRY__} .=
519 0 ▶ $head . $key . ( defined($1) ? $1 : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 0 0 0
520 }
521  
522 # Debug output
523 #print Data::Dumper->Dump([\$prophash, \$proporder], ['prophash',
524 # 'proporder']) if @$proporder;
525  
526 0 ▶ if ( length($props) != 0 ) # parse errors
Branch: 1 branch
BranchTrueFalseTotal
if (length $props != 0) 0 0 0
527 {
528 0 print STDERR "Error at parsing properties at input line $.:",
529 "Couldn't understand '$props'.\n";
530 0 return 0;
531 }
532  
533 0 return 1;
534 }
535  
536 #################
537 ## svn_props2str - Converts properties to a formatted string
538 #####
539 # Opposite of 'svn_get_properties';
540 # Returns formatted string in SVN property format
541  
542 0 ▶sub svn_props2str (\%;\@) {
Subroutine svn_props2str: not called CC=6 SCAR=37.4
Pod undocumented
543 0 my $prophash = shift; # Hash ref. with properties
544 0 ▶ my $proporder = shift || []; # Array ref. with properties order
Condition0%0/2
shift() || []
l!l
00
MC/DC0%0/1
shift() || []
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
545 0 my $props = ''; # Return string
546  
547 # Create check-hash
548 0 my %prop_notprinted = map { $_ => 0 } ( keys %$prophash );
549  
550 # Print properties by given order
551 0 foreach my $key (@$proporder) {
552 $props .= 'K '
553 . length($key)
554 . $NL
555 . $key
556 . $NL . 'V '
557 . length( $prophash->{$key} )
558 . $NL
559 0 . $prophash->{$key}
560 . $NL;
561 0 delete $prop_notprinted{$key}; # printed so delete from check-hash
562 }
563  
564 # Print now all remaining properties (if any)
565 0 foreach my $key ( sort keys %prop_notprinted ) {
566 $props .= 'K '
567 . length($key)
568 . $NL
569 . $key
570 . $NL . 'V '
571 . length( $prophash->{$key} )
572 . $NL
573 0 . $prophash->{$key}
574 . $NL;
575 }
576  
577 # Print list of deleted properties
578 0 ▶ if ( exists $prophash->{__DELETED_PROPERTIES__} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $prophash->{"__DELETED_PROPERTIES__"}) 0 0 0
579 0 my $value = $prophash->{__DELETED_PROPERTIES__};
580 0 $props .= 'D ' . length($value) . $NL . $value . $NL;
581 }
582  
583 # Print unknown entries
584 0 ▶ if ( exists $prophash->{__UNKNOWN_PROPERTY_ENTRY__} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $prophash->{"__UNKNOWN_PROPERTY_ENTRY__"}) 0 0 0
585 0 $props .= $prophash->{__UNKNOWN_PROPERTY_ENTRY__};
586 }
587  
588 0 return $props;
589 }
590  
591 #################
592 ## svn_header_sanitycheck - Checks if needed header exists and belong to each other
593 #####
594  
595 0 ▶sub svn_header_sanitycheck (\%) {
Subroutine svn_header_sanitycheck: not called CC=23 SCAR=63.1
Pod undocumented
596 0 my $header = shift;
597 0 my $error = 0;
598  
599 # Revision entry needs also 'Prop-content-length' and 'Content-length'
600 0 ▶ if ( exists $header->{'Revision-number'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $header->{'Revision-number'}) { } 0 0 0
elsif (not exists $header->{'Node-action'}) { } 0 0 0
601 0 ▶ if ( !exists $header->{'Prop-content-length'}
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $header->{"Prop-content-length"} and exists $header->{"Content-length"}) 0 0 0
Condition0%0/3
exists $header->{"Prop-content-length"} and exists $header->{"Content-length"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $header->{"Prop-content-length"} and exists $header->{"Content-length"}
exists $header->{"Prop-content-length"} exists $header->{"Content-length"}
Truth table0%0/3
A and B
A= exists $header->{"Prop-content-length"}B= exists $header->{"Content-length"}
ABresult
0X0
100
111
602 || !exists $header->{'Content-length'} )
603 {
604 0 print STDERR
605 "Missing needed header(s) after 'Revision-number' at line $..\n";
606 0 $error++;
607 }
608 }
609  
610 # if ( exists $header->{'Node-path'} ) # Must have 'Node-path' yet because of
611 # above tests (see begin of while loop)
612 # Nodes need 'Node-action' at minimum.
613 elsif ( !exists $header->{'Node-action'} ) {
614 0 print STDERR
615 "Missing needed header 'Node-action' after 'Node-path' at line $..\n";
616 0 $error++;
617 }
618 else # 'Node-action' exists:
619 {
620 0 my $action = $header->{'Node-action'}; # buffer
621 0 ▶ if ( $action eq 'delete' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($action eq 'delete') { } 0 0 0
elsif ($action eq 'add' or $action eq 'replace') { } 0 0 0
elsif ($action eq 'change') { } 0 0 0
622 my $num_headers_expected =
623 0 ▶ ( exists $header->{'Node-kind'} ) ? 3 : 2;
Branch: 1 branch
BranchTrueFalseTotal
exists $header->{'Node-kind'} ? : 0 0 0
624  
625 0 ▶ if ( keys %$header != $num_headers_expected ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$header != $num_headers_expected) 0 0 0
626 0 print STDERR
627 "Two much headers for 'Node-action: delete' at line $.:\n";
628 0 local $, = "\n";
629  
630 0 ▶ while ( my ( $key, $value ) = each %$header ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$header) 0 0 0
631 0 print STDERR "$key: $value\n";
632 }
633 0 $error++;
634 }
635 }
636 ▶ elsif ( $action eq 'add' or $action eq 'replace' ) {
Condition0%0/3
$action eq "add" or $action eq "replace"
l!l&&r!l&&!r
000
MC/DC0%0/2
$action eq "add" or $action eq "replace"
$action eq "add" $action eq "replace"
Truth table0%0/3
A or B
A= $action eq "add"B= $action eq "replace"
ABresult
1X1
011
000
637 0 ▶ if ( !exists $header->{'Node-kind'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not exists $header->{'Node-kind'}) { } 0 0 0
elsif ($header->{'Node-kind'} eq 'file') { } 0 0 0
elsif ($header->{'Node-kind'} eq 'dir') { } 0 0 0
638 0 print STDERR
639 "Missing header 'Node-kind' for 'Node-action: add' at line $..\n";
640 0 $error++;
641 }
642 elsif ( $header->{'Node-kind'} eq 'file' ) {
643 0 ▶ unless ( # This two header both exist
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"} and not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"} or exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"} and not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}) 0 0 0
Condition0%0/15
exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"} and not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"} or exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"} and not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
l!l&&r!l&&!r
000
exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"} and not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"}
!ll&&!rl&&r
000
exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"}
!ll&&!rl&&r
000
exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"} and not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
!ll&&!rl&&r
000
exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"}
!ll&&!rl&&r
000
MC/DC0%0/6
exists $header->{"Text-content-length"} and exists $header->{"Text-content-md5"} and not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"} or exists $header->{"Node-copyfrom-rev"} and exists $header->{"Node-copyfrom-path"} and not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
exists $header->{"Text-content-length"} exists $header->{"Text-content-md5"} not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"} exists $header->{"Node-copyfrom-rev"} exists $header->{"Node-copyfrom-path"} not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
Truth table0%0/13
A and B and not(C) or D and E and not(F)
A= exists $header->{"Text-content-length"}B= exists $header->{"Text-content-md5"}C= not exists $header->{"Node-copyfrom-rev"} ^ exists $header->{"Node-copyfrom-path"}D= exists $header->{"Node-copyfrom-rev"}E= exists $header->{"Node-copyfrom-path"}F= not exists $header->{"Text-content-length"} ^ exists $header->{"Text-content-md5"}
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
644 (
645 exists $header->{'Text-content-length'}
646 && exists $header->{'Text-content-md5'}
647 && !( # and this two both exist or both non-exist
648 exists $header->{
649 'Node-copyfrom-rev'} ^ #\ xor+negation
650 exists $header->{
651 'Node-copyfrom-path'} #/ = equivalence
652 )
653 )
654 || ( # This two header both exist
655 exists $header->{'Node-copyfrom-rev'}
656 && exists $header->{'Node-copyfrom-path'}
657 && !( # and this two both exist or both non-exist
658 exists $header->{
659 'Text-content-length'} ^ #\ xor+negation
660 exists $header->{
661 'Text-content-md5'} #/ = equivalence
662 )
663 )
664 )
665 { # then there is something wrong
666 0 print STDERR
667 "Missing/wrong header(s) for 'Node-action: add'/'Node-kind: ",
668 "file' ", "at line $..\n";
669 0 $error++;
670 }
671 }
672 elsif ( $header->{'Node-kind'} eq 'dir' ) {
673 0 ▶ if ( exists $header->{'Text-content-length'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $header->{"Text-content-length"} or exists $header->{"Text-content-md5"}) 0 0 0
Condition0%0/3
exists $header->{"Text-content-length"} or exists $header->{"Text-content-md5"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $header->{"Text-content-length"} or exists $header->{"Text-content-md5"}
exists $header->{"Text-content-length"} exists $header->{"Text-content-md5"}
Truth table0%0/3
A or B
A= exists $header->{"Text-content-length"}B= exists $header->{"Text-content-md5"}
ABresult
1X1
011
000
674 || exists $header->{'Text-content-md5'} )
675 {
676 0 print STDERR
677 "To much header(s) for 'Node-action: add'/'Node-kind: dir' ",
678 "at line $..\n";
679 0 $error++;
680 }
681 }
682 else {
683 0 print STDERR "Invalid value '", $header->{'Node-kind'},
684 "' for 'Node-kind' ", "at line $..\n";
685 0 $error++;
686 }
687 }
688 elsif ( $action eq 'change' ) {
689  
690 }
691 else {
692  
693 }
694 } # end of else path of "if ( !exists $header->{'Node-action'} )"
695  
696 #print STDERR Data::Dumper->Dump([$header], ['%header']) if $error;
697 0 return $error;
698 }
699  
700 #################
701 ## svn_remove_entry - Removes given entry, i.e. cleans entry hash, so that
702 ## this entry is not part of the output dump file.
703 #####
704 0 ▶sub svn_remove_entry (\%) {
Subroutine svn_remove_entry: not called CC=1 SCAR=6.9
Pod undocumented
705 0 my $href = shift;
706  
707 0 %$href = ();
708 }
709  
710 1 1;
711 __END__
↑ Summary