| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Plack::Middleware::Debug::GitStatus; |
|
2
|
1
|
|
|
1
|
|
119079
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
54
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
6
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1015
|
use Plack::Util::Accessor qw( git_dir gitweb_url ); |
|
|
1
|
|
|
|
|
298
|
|
|
|
1
|
|
|
|
|
7
|
|
|
9
|
1
|
|
|
1
|
|
2356
|
use Encode qw/ decode_utf8 /; |
|
|
1
|
|
|
|
|
20047
|
|
|
|
1
|
|
|
|
|
1466
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
899
|
use parent 'Plack::Middleware::Debug::Base'; |
|
|
1
|
|
|
|
|
289
|
|
|
|
1
|
|
|
|
|
7
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub run { |
|
14
|
1
|
|
|
1
|
1
|
977
|
my ( $self, undef, $panel ) = @_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
return sub { |
|
17
|
1
|
|
|
1
|
|
336
|
my ( $branch, $info ) = $self->get_git_info; |
|
18
|
1
|
|
|
|
|
81
|
$panel->title( 'GitStatus' ); |
|
19
|
1
|
|
|
|
|
66
|
$panel->nav_title( 'GitStatus' ); |
|
20
|
1
|
|
|
|
|
56
|
$panel->nav_subtitle( 'On branch ' . $branch ); |
|
21
|
1
|
|
|
|
|
49
|
$panel->content( $self->render_info( $info ) ); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
1
|
|
|
|
|
9
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub render_info { |
|
26
|
3
|
|
|
3
|
0
|
4544
|
my $self = shift; |
|
27
|
3
|
|
|
|
|
4
|
my $info = shift; |
|
28
|
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
6
|
my $html = qq|| |;
|
|
30
|
|
|
|
|
|
|
|
|
31
|
3
|
100
|
|
|
|
11
|
if ( $info->{ error } ) { |
|
32
|
1
|
|
|
|
|
6
|
$html .= qq|Error |
|
33
|
|
|
|
|
|
|
| | Git reported an error | $info->{ error } |
|
34
|
|
|
|
|
|
|
|; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
else { |
|
37
|
2
|
|
|
|
|
18
|
$html .= qq|Git status information |
|
38
|
|
|
|
|
|
|
| | Current Branch | $info->{ current_branch } |
|
39
|
|
|
|
|
|
|
| | Status | $info->{ status } |
|
40
|
|
|
|
|
|
|
| | Last commit | |
|
41
|
|
|
|
|
|
|
| | Date | $info->{ date } |
|
42
|
|
|
|
|
|
|
| | Author | $info->{ author } |
|
43
|
|
|
|
|
|
|
| | SHA-1 | $info->{ sha_1 } |
|
44
|
|
|
|
|
|
|
| | Message | $info->{ message } |
|
45
|
|
|
|
|
|
|
|; |
|
46
|
|
|
|
|
|
|
|
|
47
|
2
|
100
|
|
|
|
17
|
if ( my $url = $self->gitweb_url ) { |
|
48
|
1
|
|
|
|
|
105
|
$html .= sprintf qq| | | View | | \n|, $info->{ sha_1 };
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
231
|
$html .= ' | '; |
|
53
|
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
12
|
return $html; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get_git_info { |
|
58
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my ( $branch, $info ) = eval { |
|
61
|
0
|
0
|
|
|
|
|
if ( my $dir = $self->git_dir ) { |
|
62
|
0
|
0
|
|
|
|
|
if ( ! chdir $dir ) { |
|
63
|
0
|
|
|
|
|
|
die "Could not change to directory '$dir': $!"; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $current_branch = `git symbolic-ref HEAD 2>&1`; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if ( $? ) { |
|
70
|
0
|
|
|
|
|
|
die "Git reported an error: $current_branch"; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$current_branch =~ s|refs/heads/||; |
|
74
|
0
|
|
|
|
|
|
my %info = ( current_branch => $current_branch ); |
|
75
|
0
|
|
|
|
|
|
$info{ status } = $self->get_git_status; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my @ci_info = split /\0/, `git log -1 --pretty=format:%H%x00%an%x00%aD%x00%s`; |
|
78
|
0
|
|
|
|
|
|
$info{ sha_1 } = shift @ci_info; |
|
79
|
0
|
|
|
|
|
|
$info{ author } = decode_utf8 shift @ci_info; |
|
80
|
0
|
|
|
|
|
|
$info{ date } = shift @ci_info; |
|
81
|
0
|
|
|
|
|
|
$info{ message } = decode_utf8 shift @ci_info; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $current_branch, \%info; |
|
84
|
|
|
|
|
|
|
}; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if ( my $err = $@ ) { |
|
87
|
0
|
|
|
|
|
|
return 'unknown', { error => $err }; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
else { |
|
90
|
0
|
|
|
|
|
|
return $branch, $info; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub get_git_status { |
|
95
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $status = `git status -s`; |
|
98
|
0
|
0
|
|
|
|
|
return 'clean' unless $status; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $status; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |