| 1 | package Git::Repository::Log::Iterator; | ||||||||||||||||||||||||||||
| 2 | 4 | $Git::Repository::Log::Iterator::VERSION = '1.314'; | |||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Git::Repository; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Git::Repository::Command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Git::Repository::Log; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 22 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 22 | my ( $class, @cmd ) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # pick up unsupported log options | ||||||||||||||||||||||||||||
| 17 | 22 | my @badopts = do { | |||||||||||||||||||||||||||
| 18 | 22 | my $options = 1; | |||||||||||||||||||||||||||
| 19 | 62 | grep {/^--(?:(?:pretty|format)=(?!raw).*|graph|oneline)$/} | |||||||||||||||||||||||||||
| 20 | 22 | ▶ | grep { $options = 0 if $_ eq '--'; $options } @cmd; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | }; | ||||||||||||||||||||||||||||
| 22 | 22 | ▶ | croak "log() cannot parse @badopts. " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | . 'Use run( log => ... ) to parse the output yourself' | ||||||||||||||||||||||||||||
| 24 | if @badopts; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # note: there is no --color option to git log before 1.5.3.3 | ||||||||||||||||||||||||||||
| 27 | 18 | ▶ | my ($r) = grep blessed $_ && $_->isa('Git::Repository'), @cmd; | ||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($_) && $_->isa('Git::Repository')
MC/DC50%1/2
builtin::blessed($_) && $_->isa('Git::Repository')
builtin::blessed($_)
$_->isa('Git::Repository')
Truth table66%2/3
A && B
A= builtin::blessed($_)B= $_->isa('Git::Repository')
| |||||||||||||||||||||||||||||
| 28 | 18 | ▶ | $r ||= 'Git::Repository'; # no Git::Repository object given | ||||||||||||||||||||||||||
|
Condition100%2/2
$r ||= "Git::Repository"
MC/DC100%1/1
$r ||= "Git::Repository"
$r
Truth table100%2/2
A
A= $r
| |||||||||||||||||||||||||||||
| 29 | 18 | ▶ | unshift @cmd, '--no-color' if $r->version_ge('1.5.3.3'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # enforce the format | ||||||||||||||||||||||||||||
| 32 | 18 | @cmd = ( 'log', '--pretty=raw', @cmd ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # run the command (@cmd may hold a Git::Repository instance) | ||||||||||||||||||||||||||||
| 35 | 18 | my $cmd = Git::Repository::Command->new(@cmd); | |||||||||||||||||||||||||||
| 36 | 18 | bless { cmd => $cmd, fh => $cmd->stdout }, $class; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub new_from_fh { | ||||||||||||||||||||||||||
|
Subroutine
new_from_fh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 0 | my ( $class, $fh ) = @_; | |||||||||||||||||||||||||||
| 41 | 0 | bless { fh => $fh }, $class; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub new_from_file { | ||||||||||||||||||||||||||
|
Subroutine
new_from_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 0 | my ( $class, $file ) = @_; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | open my $fh, '<', $file or die "Can't open $file: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | bless { fh => $fh }, $class; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 57 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 57 | my ($self) = @_; | |||||||||||||||||||||||||||
| 52 | 57 | my $fh = $self->{fh}; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # get records | ||||||||||||||||||||||||||||
| 55 | 57 | ▶ | my @records = defined $self->{record} ? ( delete $self->{record} ) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 57 | local $/ = "\n\n"; | |||||||||||||||||||||||||||
| 58 | 57 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 90 | ▶ | $self->{record} = $_, last if /\Acommit / && @records; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/\Acommit / and @records
MC/DC100%2/2
/\Acommit / and @records
/\Acommit /
@records
Truth table100%3/3
A and B
A= /\Acommit /B= @records
| |||||||||||||||||||||||||||||
| 60 | 65 | push @records, $_; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # EOF | ||||||||||||||||||||||||||||
| 65 | 57 | ▶ | if ( !@records ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 17 | ▶ | if ( $self->{cmd} ) { # might catch some git errors | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 17 | $self->{cmd}->final_output(); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | else { # just close the filehandle | ||||||||||||||||||||||||||||
| 70 | 0 | $self->{fh}->close; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 15 | return; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # the first two records are always the same, with --pretty=raw | ||||||||||||||||||||||||||||
| 76 | 40 | local $/ = "\n"; | |||||||||||||||||||||||||||
| 77 | 40 | my ( $header, $message, $extra ) = ( @records, '', '' ); | |||||||||||||||||||||||||||
| 78 | 40 | chomp $header; | |||||||||||||||||||||||||||
| 79 | 40 | my @headers = map { chomp; split / /, $_, 2 } split /^(?=\S)/m, $header; | |||||||||||||||||||||||||||
| 80 | 40 | s/\n /\n/g for @headers; | |||||||||||||||||||||||||||
| 81 | 40 | ▶ | chomp( $message, $extra ) if exists $self->{record}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # create the log object | ||||||||||||||||||||||||||||
| 84 | 40 | return Git::Repository::Log->new( | |||||||||||||||||||||||||||
| 85 | @headers, | ||||||||||||||||||||||||||||
| 86 | message => $message, | ||||||||||||||||||||||||||||
| 87 | extra => $extra, | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 4 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||