File Coverage

blib/lib/Git/FastExport.pm
Criterion Covered Total %
statement 52 56 92.8
branch 18 22 81.8
condition 3 3 100.0
subroutine 8 8 100.0
pod 2 2 100.0
total 83 91 91.2


line stmt bran cond sub pod time code
1             package Git::FastExport;
2             $Git::FastExport::VERSION = '0.107';
3 4     4   31429 use strict;
  4         6  
  4         96  
4 4     4   12 use warnings;
  4         4  
  4         104  
5 4     4   13 use Carp;
  4         5  
  4         232  
6 4     4   15 use Scalar::Util qw( blessed );
  4         4  
  4         211  
7              
8 4     4   992 use Git::Repository;
  4         64726  
  4         20  
9 4     4   1371 use Git::FastExport::Block;
  4         5  
  4         1913  
10              
11             my $LF = "\012";
12              
13             sub new {
14 66     66 1 1031 my ( $class, $handle ) = @_;
15 66         377 return bless { stream => $handle }, $class;
16             }
17              
18             sub next_block {
19 806     806 1 9013 my ($self) = @_;
20 806         832 my $fh = $self->{stream};
21 806 100       1244 return if !defined $fh;
22              
23 805         1433 my $block = bless {}, 'Git::FastExport::Block';
24              
25             # pick up the header from the previous round, or read it (first time)
26 805   100     111855 $self->{header} ||= <$fh>;
27 805         1394 $block->{header} = delete $self->{header};
28              
29             # nothing left to process
30 805 100       1354 return if !defined $block->{header};
31              
32 741         938 chomp $block->{header};
33 741         3354 ( $block->{type} ) = $block->{header} =~ /^(\w+)/g;
34              
35 741         716 local $_;
36 741         1976 while (<$fh>) {
37              
38             # we've reached the beginning of the next block
39 2472 100       4852 if (/^(commit|tag|reset|blob|checkpoint|progress|feature|option|done)\b/) {
40 678 50       1028 s/^progress /progress [$self->{source}] / if exists $self->{source};
41 678         752 $self->{header} = $_;
42 678         658 last;
43             }
44              
45 1794         1228 chomp;
46              
47             # special case of data block
48 1794 100       4601 if (/^data (.*)/) {
    100          
    100          
49 286 50       579 if ( substr( $1, 0, 2 ) eq '<<' ) { # Delimited format
50              
51             # 'data' SP '<<' LF
52             # LF
53             # LF
54             # LF?
55 0         0 my $delim = substr( $1, 2 );
56 0         0 local $/ = "$LF$delim$LF";
57 0         0 chomp( $block->{data} = <$fh> );
58             }
59             else { # Exact byte count format
60              
61             # 'data' SP LF
62             # LF?
63 286         314 my $bytes = $1;
64 286 50       301 if ($bytes) {
65 286         879 local $/ = \$bytes;
66 286         1318 $block->{data} = <$fh>;
67             }
68             else {
69 0         0 $block->{data} = "";
70             }
71             }
72             }
73             elsif (/^(?:[MDRC] |deleteall)/) {
74 8         6 push @{ $block->{files} }, $_;
  8         29  
75             }
76             elsif (/^(\w+)/) {
77 1151         760 push @{ $block->{$1} }, $_;
  1151         4098  
78             }
79             else {
80              
81             # ignore empty lines, but choke on others
82 349 50       658 die "Unexpected line:\n$_\n" if !/^$/;
83 349         1052 $block->{footer} .= "\012";
84             }
85             }
86              
87             # post-processing
88 741 100       1250 if ( $block->{type} eq 'commit' ) {
89             ( $block->{committer_date} )
90 272         1183 = $block->{committer}[0] =~ /^committer [^>]*> (\d+) [-+]\d+$/g;
91             ( $block->{author_date} )
92 272         814 = $block->{author}[0] =~ /^author [^>]*> (\d+) [-+]\d+$/g;
93             }
94              
95 741         1910 return $block;
96             }
97              
98             'progress 1 objects';
99              
100             __END__