| 1 | package Git::FastExport; | ||||||||||||||||||||
| 2 | 6 | $Git::FastExport::VERSION = '0.108'; | |||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 6 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 6 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 6 | ▶ | use Git::Repository; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 6 | ▶ | use Git::FastExport::Block; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 6 | my $LF = "\012"; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 66 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 14 | 66 | my ( $class, $handle ) = @_; | |||||||||||||||||||
| 15 | 66 | return bless { stream => $handle }, $class; | |||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 682 | ▶ | sub next_block { | ||||||||||||||||||
|
Subroutine
next_block: called CC=14 SCAR=26.7
Pod
documented
| |||||||||||||||||||||
| 19 | 682 | my ($self) = @_; | |||||||||||||||||||
| 20 | 682 | my $fh = $self->{stream}; | |||||||||||||||||||
| 21 | 682 | ▶ | return if !defined $fh; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 681 | my $block = bless {}, 'Git::FastExport::Block'; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | # pick up the header from the previous round, or read it (first time) | ||||||||||||||||||||
| 26 | 681 | ▶ | $self->{header} ||= <$fh>; | ||||||||||||||||||
|
Condition100%3/3
$self->{"header"} ||= readline $fh
MC/DC100%2/2
$self->{"header"} ||= readline $fh
$self->{"header"}
readline $fh
Truth table100%3/3
A ||= B
A= $self->{"header"}B= readline $fh
| |||||||||||||||||||||
| 27 | 681 | $block->{header} = delete $self->{header}; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # nothing left to process | ||||||||||||||||||||
| 30 | 681 | ▶ | return if !defined $block->{header}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 617 | chomp $block->{header}; | |||||||||||||||||||
| 33 | 617 | ( $block->{type} ) = $block->{header} =~ /^(\w+)/g; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 617 | local $_; | |||||||||||||||||||
| 36 | 617 | ▶ | while (<$fh>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | # we've reached the beginning of the next block | ||||||||||||||||||||
| 39 | 2224 | ▶ | if (/^(commit|tag|reset|blob|checkpoint|progress|feature|option|done)\b/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 554 | ▶ | s/^progress /progress [$self->{source}] / if exists $self->{source}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 554 | $self->{header} = $_; | |||||||||||||||||||
| 42 | 554 | last; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 1670 | chomp; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # special case of data block | ||||||||||||||||||||
| 48 | 1670 | ▶ | if (/^data (.*)/) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 49 | 286 | ▶ | if ( substr( $1, 0, 2 ) eq '<<' ) { # Delimited format | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # 'data' SP '<<' <delim> LF | ||||||||||||||||||||
| 52 | # <raw> LF | ||||||||||||||||||||
| 53 | # <delim> LF | ||||||||||||||||||||
| 54 | # LF? | ||||||||||||||||||||
| 55 | 0 | my $delim = substr( $1, 2 ); | |||||||||||||||||||
| 56 | 0 | local $/ = "$LF$delim$LF"; | |||||||||||||||||||
| 57 | 0 | chomp( $block->{data} = <$fh> ); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | else { # Exact byte count format | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # 'data' SP <count> LF | ||||||||||||||||||||
| 62 | # <raw> LF? | ||||||||||||||||||||
| 63 | 286 | my $bytes = $1; | |||||||||||||||||||
| 64 | 286 | ▶ | if ($bytes) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 286 | local $/ = \$bytes; | |||||||||||||||||||
| 66 | 286 | $block->{data} = <$fh>; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||
| 69 | 0 | $block->{data} = ""; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | elsif (/^(?:[MDRC] |deleteall)/) { | ||||||||||||||||||||
| 74 | 8 | push @{ $block->{files} }, $_; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | elsif (/^(\w+)/) { | ||||||||||||||||||||
| 77 | 1089 | push @{ $block->{$1} }, $_; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | # ignore empty lines, but choke on others | ||||||||||||||||||||
| 82 | 287 | ▶ | die "Unexpected line:\n$_\n" if !/^$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 287 | $block->{footer} .= "\012"; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | # post-processing | ||||||||||||||||||||
| 88 | 617 | ▶ | if ( $block->{type} eq 'commit' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | ( $block->{committer_date} ) | ||||||||||||||||||||
| 90 | 272 | = $block->{committer}[0] =~ /^committer [^>]*> (\d+) [-+]\d+$/g; | |||||||||||||||||||
| 91 | ( $block->{author_date} ) | ||||||||||||||||||||
| 92 | 272 | = $block->{author}[0] =~ /^author [^>]*> (\d+) [-+]\d+$/g; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 617 | return $block; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 6 | 'progress 1 objects'; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||