| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Git::Repository::Log::Iterator; | 
| 2 |  |  |  |  |  |  | $Git::Repository::Log::Iterator::VERSION = '1.314'; | 
| 3 | 2 |  |  | 2 |  | 8 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 54 |  | 
| 4 | 2 |  |  | 2 |  | 8 | use warnings; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 40 |  | 
| 5 | 2 |  |  | 2 |  | 32 | use 5.006; | 
|  | 2 |  |  |  |  | 5 |  | 
| 6 | 2 |  |  | 2 |  | 6 | use Carp; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 122 |  | 
| 7 | 2 |  |  | 2 |  | 8 | use Scalar::Util qw( blessed ); | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 110 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 8 | use Git::Repository; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 35 |  | 
| 10 | 2 |  |  | 2 |  | 53 | use Git::Repository::Command; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 21 |  | 
| 11 | 2 |  |  | 2 |  | 908 | use Git::Repository::Log; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1254 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub new { | 
| 14 | 22 |  |  | 22 | 1 | 103 | my ( $class, @cmd ) = @_; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | # pick up unsupported log options | 
| 17 | 22 |  |  |  |  | 28 | my @badopts = do { | 
| 18 | 22 |  |  |  |  | 28 | my $options = 1; | 
| 19 | 62 |  |  |  |  | 208 | grep {/^--(?:(?:pretty|format)=(?!raw).*|graph|oneline)$/} | 
| 20 | 22 | 100 |  |  |  | 54 | grep { $options = 0 if $_ eq '--'; $options } @cmd; | 
|  | 64 |  |  |  |  | 145 |  | 
|  | 64 |  |  |  |  | 103 |  | 
| 21 |  |  |  |  |  |  | }; | 
| 22 | 22 | 100 |  |  |  | 658 | croak "log() cannot parse @badopts. " | 
| 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 |  | 66 |  |  | 257 | my ($r) = grep blessed $_ && $_->isa('Git::Repository'), @cmd; | 
| 28 | 18 |  | 100 |  |  | 89 | $r ||= 'Git::Repository';    # no Git::Repository object given | 
| 29 | 18 | 50 |  |  |  | 823 | unshift @cmd, '--no-color' if $r->version_ge('1.5.3.3'); | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | # enforce the format | 
| 32 | 18 |  |  |  |  | 128902 | @cmd = ( 'log', '--pretty=raw', @cmd ); | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | # run the command (@cmd may hold a Git::Repository instance) | 
| 35 | 18 |  |  |  |  | 104 | my $cmd = Git::Repository::Command->new(@cmd); | 
| 36 | 18 |  |  |  |  | 111248 | bless { cmd => $cmd, fh => $cmd->stdout }, $class; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub new_from_fh { | 
| 40 | 0 |  |  | 0 | 1 | 0 | my ( $class, $fh ) = @_; | 
| 41 | 0 |  |  |  |  | 0 | bless { fh => $fh }, $class; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub new_from_file { | 
| 45 | 0 |  |  | 0 | 1 | 0 | my ( $class, $file ) = @_; | 
| 46 | 0 | 0 |  |  |  | 0 | open my $fh, '<', $file or die "Can't open $file: $!"; | 
| 47 | 0 |  |  |  |  | 0 | bless { fh => $fh }, $class; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub next { | 
| 51 | 57 |  |  | 57 | 1 | 5948 | my ($self) = @_; | 
| 52 | 57 |  |  |  |  | 84 | my $fh = $self->{fh}; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # get records | 
| 55 | 57 | 100 |  |  |  | 178 | my @records = defined $self->{record} ? ( delete $self->{record} ) : (); | 
| 56 |  |  |  |  |  |  | { | 
| 57 | 57 |  |  |  |  | 67 | local $/ = "\n\n"; | 
|  | 57 |  |  |  |  | 219 |  | 
| 58 | 57 |  |  |  |  | 24379 | while (<$fh>) { | 
| 59 | 90 | 100 | 100 |  |  | 594 | $self->{record} = $_, last if /\Acommit / && @records; | 
| 60 | 65 |  |  |  |  | 1009 | push @records, $_; | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | # EOF | 
| 65 | 57 | 100 |  |  |  | 153 | if ( !@records ) { | 
| 66 | 17 | 50 |  |  |  | 61 | if ( $self->{cmd} ) {    # might catch some git errors | 
| 67 | 17 |  |  |  |  | 73 | $self->{cmd}->final_output(); | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  | else {                   # just close the filehandle | 
| 70 | 0 |  |  |  |  | 0 | $self->{fh}->close; | 
| 71 |  |  |  |  |  |  | } | 
| 72 | 15 |  |  |  |  | 2359 | return; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | # the first two records are always the same, with --pretty=raw | 
| 76 | 40 |  |  |  |  | 111 | local $/ = "\n"; | 
| 77 | 40 |  |  |  |  | 96 | my ( $header, $message, $extra ) = ( @records, '', '' ); | 
| 78 | 40 |  |  |  |  | 63 | chomp $header; | 
| 79 | 40 |  |  |  |  | 399 | my @headers = map { chomp; split / /, $_, 2 } split /^(?=\S)/m, $header; | 
|  | 242 |  |  |  |  | 192 |  | 
|  | 242 |  |  |  |  | 474 |  | 
| 80 | 40 |  |  |  |  | 497 | s/\n /\n/g for @headers; | 
| 81 | 40 | 100 |  |  |  | 122 | chomp( $message, $extra ) if exists $self->{record}; | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | # create the log object | 
| 84 | 40 |  |  |  |  | 252 | return Git::Repository::Log->new( | 
| 85 |  |  |  |  |  |  | @headers, | 
| 86 |  |  |  |  |  |  | message => $message, | 
| 87 |  |  |  |  |  |  | extra   => $extra, | 
| 88 |  |  |  |  |  |  | ); | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | 1; | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | __END__ |