line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Repository::Plugin::Blame; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
72792
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
128
|
|
4
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
87
|
|
5
|
3
|
|
|
3
|
|
70
|
use 5.006; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
78
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1575
|
use Git::Repository::Plugin; |
|
3
|
|
|
|
|
1278
|
|
|
3
|
|
|
|
|
195
|
|
8
|
|
|
|
|
|
|
our @ISA = qw( Git::Repository::Plugin ); |
9
|
2
|
|
|
2
|
|
106
|
sub _keywords { return qw( blame ) } ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
18
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
195
|
|
12
|
3
|
|
|
3
|
|
1498
|
use Class::Load qw(); |
|
3
|
|
|
|
|
108212
|
|
|
3
|
|
|
|
|
114
|
|
13
|
3
|
|
|
3
|
|
2204
|
use Perl6::Slurp qw(); |
|
3
|
|
|
|
|
5730
|
|
|
3
|
|
|
|
|
102
|
|
14
|
3
|
|
|
3
|
|
1768
|
use Git::Repository::Plugin::Blame::Line; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
3358
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Git::Repository::Plugin::Blame - Add a blame() method to L. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 VERSION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Version 1.3.0 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '1.3.0'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Load the plugin. |
34
|
|
|
|
|
|
|
use Git::Repository 'Blame'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $repository = Git::Repository->new(); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Get the git blame information. |
39
|
|
|
|
|
|
|
my $blame_lines = $repository->blame( $file ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This module adds a new C method to L, which can be |
45
|
|
|
|
|
|
|
used to determine what the last change for each line in a file is. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 METHODS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 blame() |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Return the git blame information for a given file as an arrayref of |
53
|
|
|
|
|
|
|
L objects. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $blame_lines = $repository->blame( |
56
|
|
|
|
|
|
|
$file, |
57
|
|
|
|
|
|
|
use_cache => $boolean, # default 0 |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Arguments: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over 4 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item * use_cache I<(default: 0)> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Cache the git blame output. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item * ignore_whitespace I<(default: 0)> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Ignore whitespace when comparing the parent's version and the child's to find |
71
|
|
|
|
|
|
|
where the lines came from. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=back |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub blame |
78
|
|
|
|
|
|
|
{ |
79
|
6
|
|
|
6
|
1
|
611231
|
my ( $repository, $file, %args ) = @_; |
80
|
6
|
|
100
|
|
|
126
|
my $use_cache = delete( $args{'use_cache'} ) || 0; |
81
|
6
|
|
100
|
|
|
52
|
my $ignore_whitespace = delete( $args{'ignore_whitespace'} ) || 0; |
82
|
6
|
50
|
|
|
|
31
|
croak 'The following arguments are not valid: ' . join( ', ' , keys %args ) |
83
|
|
|
|
|
|
|
if scalar( keys %args ) != 0; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Check if the cache is enabled and if the file has already been parsed. |
86
|
6
|
|
|
|
|
10
|
my $cache; |
87
|
6
|
100
|
|
|
|
22
|
if ( $use_cache ) |
88
|
|
|
|
|
|
|
{ |
89
|
2
|
|
|
|
|
20
|
my $class = Class::Load::load_class( 'Git::Repository::Plugin::Blame::Cache' ); |
90
|
2
|
|
|
|
|
239
|
$cache = $class->new( |
91
|
|
|
|
|
|
|
repository => $repository->work_tree(), |
92
|
|
|
|
|
|
|
blame_args => |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
ignore_whitespace => $ignore_whitespace, |
95
|
|
|
|
|
|
|
}, |
96
|
|
|
|
|
|
|
); |
97
|
2
|
50
|
|
|
|
8
|
croak 'Failed to initialize cache for repository ' . $repository->work_tree() |
98
|
|
|
|
|
|
|
if !defined( $cache ); |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
7
|
my $blame_lines = $cache->get_blame_lines( file => $file ); |
101
|
2
|
50
|
|
|
|
6
|
return $blame_lines |
102
|
|
|
|
|
|
|
if defined( $blame_lines ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Run the command. |
106
|
6
|
|
|
|
|
19
|
my @commandline_options = ( '--porcelain' ); |
107
|
6
|
100
|
|
|
|
20
|
push( @commandline_options, '-w' ) if $ignore_whitespace; |
108
|
6
|
|
|
|
|
39
|
my $command = $repository->command( 'blame', @commandline_options, $file ); |
109
|
6
|
|
|
|
|
85943
|
my @output = $command->final_output(); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Parse the output. |
112
|
6
|
|
|
|
|
18151
|
my ( $commit_id, $original_line_number, $final_line_number, $lines_count_in_group ); |
113
|
6
|
|
|
|
|
22
|
my $commit_attributes = {}; |
114
|
6
|
|
|
|
|
18
|
my $lines = []; |
115
|
6
|
|
|
|
|
30
|
foreach my $line ( @output ) |
116
|
|
|
|
|
|
|
{ |
117
|
163
|
100
|
|
|
|
328
|
if ( $line =~ /^\t(.*)$/x ) |
118
|
|
|
|
|
|
|
{ |
119
|
|
|
|
|
|
|
# It's a line from the file we git blamed. |
120
|
21
|
50
|
|
|
|
185
|
push( |
121
|
|
|
|
|
|
|
@$lines, |
122
|
|
|
|
|
|
|
Git::Repository::Plugin::Blame::Line->new( |
123
|
|
|
|
|
|
|
line_number => $final_line_number, |
124
|
|
|
|
|
|
|
line => defined( $1 ) ? $1 : '', |
125
|
|
|
|
|
|
|
commit_attributes => $commit_attributes->{ $commit_id }, |
126
|
|
|
|
|
|
|
commit_id => $commit_id, |
127
|
|
|
|
|
|
|
) |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
else |
131
|
|
|
|
|
|
|
{ |
132
|
|
|
|
|
|
|
# It's a git header line. |
133
|
142
|
100
|
|
|
|
868
|
if ( $line =~ /^([0-9a-f]+)\s(\d+)\s(\d+)\s*(\d*)$/x ) |
|
|
50
|
|
|
|
|
|
134
|
|
|
|
|
|
|
{ |
135
|
21
|
|
|
|
|
141
|
( $commit_id, $original_line_number, $final_line_number, $lines_count_in_group ) = ( $1, $2, $3, $4 ); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
elsif ( $line =~ m/^([\w\-]+)\s*(.*)$/x ) |
138
|
|
|
|
|
|
|
{ |
139
|
121
|
|
|
|
|
643
|
$commit_attributes->{ $commit_id }->{ $1 } = $2; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# If we have a cache object, cache the output. |
145
|
6
|
100
|
|
|
|
16
|
if ( defined( $cache ) ) |
146
|
|
|
|
|
|
|
{ |
147
|
2
|
|
|
|
|
20
|
$cache->set_blame_lines( |
148
|
|
|
|
|
|
|
file => $file, |
149
|
|
|
|
|
|
|
blame_lines => $lines, |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
6
|
|
|
|
|
360
|
return $lines; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 BUGS |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
160
|
|
|
|
|
|
|
L. |
161
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
162
|
|
|
|
|
|
|
your bug as I make changes. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SUPPORT |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
perldoc Git::Repository::Plugin::Blame |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
You can also look for information at: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 4 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * GitHub (report bugs there) |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * CPAN Ratings |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * MetaCPAN |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 AUTHOR |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L, |
198
|
|
|
|
|
|
|
C<< >>. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Copyright 2012-2015 Guillaume Aubert. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under |
206
|
|
|
|
|
|
|
the terms of the GNU General Public License version 3 as published by the Free |
207
|
|
|
|
|
|
|
Software Foundation. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
210
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
211
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with |
214
|
|
|
|
|
|
|
this program. If not, see http://www.gnu.org/licenses/ |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
1; |