line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Deploy::Say; |
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => "all"; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
220
|
|
4
|
1
|
|
|
1
|
|
7
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
5
|
1
|
|
|
1
|
|
1183
|
use File::Spec::Functions qw(catfile); |
|
1
|
|
|
|
|
1197
|
|
|
1
|
|
|
|
|
933
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1160
|
use POSIX 'strftime'; |
|
1
|
|
|
|
|
20607
|
|
|
1
|
|
|
|
|
12
|
|
8
|
1
|
|
|
1
|
|
3722
|
use Memoize; |
|
1
|
|
|
|
|
4576
|
|
|
1
|
|
|
|
|
194
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
1
|
|
|
1
|
|
76
|
select( ( select(STDERR), $|++ )[0] ); $|++; # flush ALL buffers! |
|
1
|
|
|
|
|
3
|
|
12
|
1
|
50
|
33
|
|
|
156
|
unless ( !$ENV{NO_COLOR} and -t STDOUT and eval "use Term::ANSIColor qw(color colored); 1" ) { |
|
|
|
33
|
|
|
|
|
13
|
1
|
50
|
|
0
|
0
|
107
|
eval ' |
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub color { return "" } |
15
|
|
|
|
|
|
|
sub colored { return $_[1] } |
16
|
|
|
|
|
|
|
1 |
17
|
|
|
|
|
|
|
' or die "Failed to installed stub color functions: $@"; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT = qw( |
22
|
|
|
|
|
|
|
_error |
23
|
|
|
|
|
|
|
_die |
24
|
|
|
|
|
|
|
_warn |
25
|
|
|
|
|
|
|
_info |
26
|
|
|
|
|
|
|
_say |
27
|
|
|
|
|
|
|
_yay |
28
|
|
|
|
|
|
|
_tell |
29
|
|
|
|
|
|
|
_log |
30
|
|
|
|
|
|
|
_print |
31
|
|
|
|
|
|
|
_printf |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
COLOR_WARN |
34
|
|
|
|
|
|
|
COLOR_INFO |
35
|
|
|
|
|
|
|
COLOR_SAY |
36
|
|
|
|
|
|
|
COLOR_MODIFIED |
37
|
|
|
|
|
|
|
COLOR_ADDED |
38
|
|
|
|
|
|
|
COLOR_DELETED |
39
|
|
|
|
|
|
|
COLOR_RENAMED |
40
|
|
|
|
|
|
|
COLOR_MODECHG |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
color |
43
|
|
|
|
|
|
|
colored |
44
|
|
|
|
|
|
|
$LOG_HANDLE |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _msg { |
48
|
0
|
|
|
0
|
|
|
my ( $pfx, @bits )= @_; |
49
|
0
|
|
|
|
|
|
my $msg= join "", @bits; |
50
|
0
|
|
|
|
|
|
$msg =~ s/\n*\z/\n/; |
51
|
0
|
|
|
|
|
|
$msg =~ s/^\s*#\s+//mg; |
52
|
0
|
|
0
|
|
|
|
$pfx ||= "###"; |
53
|
0
|
|
|
|
|
|
my $qpfx= quotemeta($pfx); |
54
|
0
|
|
|
|
|
|
$msg =~ s/^(\s+$qpfx)?/$pfx /mg; |
55
|
0
|
|
|
|
|
|
return $msg; |
56
|
|
|
|
|
|
|
} |
57
|
1
|
50
|
|
|
|
215
|
use constant $ENV{WHITE_BACKGROUND} |
58
|
|
|
|
|
|
|
? { |
59
|
|
|
|
|
|
|
COLOR_CONFESS => 'red', |
60
|
|
|
|
|
|
|
COLOR_DIE => 'red', |
61
|
|
|
|
|
|
|
COLOR_WARN => 'red', |
62
|
|
|
|
|
|
|
COLOR_INFO => 'black', |
63
|
|
|
|
|
|
|
COLOR_SAY => 'blue', |
64
|
|
|
|
|
|
|
COLOR_TELL => 'magenta', |
65
|
|
|
|
|
|
|
COLOR_YAY => 'bold black', |
66
|
|
|
|
|
|
|
COLOR_MODIFIED => 'black', |
67
|
|
|
|
|
|
|
COLOR_ADDED => 'green', |
68
|
|
|
|
|
|
|
COLOR_DELETED => 'red', |
69
|
|
|
|
|
|
|
COLOR_RENAMED => 'magenta', |
70
|
|
|
|
|
|
|
COLOR_MODECHG => 'cyan', |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
: { |
73
|
|
|
|
|
|
|
COLOR_CONFESS => 'bold red', |
74
|
|
|
|
|
|
|
COLOR_DIE => 'bold red', |
75
|
|
|
|
|
|
|
COLOR_WARN => 'bold red', |
76
|
|
|
|
|
|
|
COLOR_INFO => 'white', |
77
|
|
|
|
|
|
|
COLOR_SAY => 'cyan', |
78
|
|
|
|
|
|
|
COLOR_TELL => 'yellow', |
79
|
|
|
|
|
|
|
COLOR_YAY => 'bold white', |
80
|
|
|
|
|
|
|
COLOR_MODIFIED => 'white', |
81
|
|
|
|
|
|
|
COLOR_ADDED => 'green', |
82
|
|
|
|
|
|
|
COLOR_DELETED => 'red', |
83
|
|
|
|
|
|
|
COLOR_RENAMED => 'magenta', |
84
|
|
|
|
|
|
|
COLOR_MODECHG => 'cyan', |
85
|
1
|
|
|
1
|
|
16
|
}; |
|
1
|
|
|
|
|
3
|
|
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
1
|
|
6
|
use constant SKIP_LOGGING => $ENV{GIT_DEPLOY_SAY_SKIP_LOGGING}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1402
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _get_log_handle { |
90
|
|
|
|
|
|
|
return if SKIP_LOGGING; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
require Git::Deploy; |
93
|
|
|
|
|
|
|
my $log_dir = Git::Deploy::log_directory(); |
94
|
|
|
|
|
|
|
my $log_file = catfile($log_dir, 'git-deploy.log'); |
95
|
|
|
|
|
|
|
open my $fh, ">>", $log_file or do { |
96
|
|
|
|
|
|
|
warn "Can not append to global log file '$log_file': $!"; |
97
|
|
|
|
|
|
|
return; |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return $fh; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
memoize('_get_log_handle'); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# NOTE - THESE COLORS ARE CHOSEN WITH COLOR BLINDNESS IN MIND - DO NOT CHANGE THEM WITHOUT |
105
|
|
|
|
|
|
|
# VERIFYING THAT A COLOR BLIND PROGRAMMER CAN SEE THE DIFFERENCE - 10% of MEN SUFFER SOME KIND |
106
|
|
|
|
|
|
|
# OF COLOR BLINDNESS AND APPROXIMATELY 99% OF OUR CODERS ARE MEN. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
our $SKIP_LOGING_DUE_TO_DEEP_RECURSION_WITH_GIT_DEPLOY_DEBUG; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub __log { |
111
|
0
|
0
|
|
0
|
|
|
return if $SKIP_LOGING_DUE_TO_DEEP_RECURSION_WITH_GIT_DEPLOY_DEBUG; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $str= join("",@_); |
114
|
0
|
|
0
|
|
|
|
my $user = $ENV{USER} || ((getpwuid($<))[0]); |
115
|
0
|
|
|
|
|
|
my $pfx= sprintf "# %-12s | %s #",$user,strftime("%Y-%m-%d %H:%M:%S",localtime); |
116
|
0
|
|
|
|
|
|
$str=~s/\033\[[^m]+m//g; # strip color |
117
|
0
|
|
|
|
|
|
$str=~s/^#([^:]+):/$pfx $1:/mg; # fix prefix |
118
|
0
|
|
|
|
|
|
$str=~s/\n*\z/\n/; |
119
|
0
|
0
|
|
|
|
|
if (my $fh= _get_log_handle()) { |
120
|
0
|
|
|
|
|
|
print $fh $str; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub __say(@) { |
125
|
0
|
|
|
0
|
|
|
my $color= shift; |
126
|
0
|
|
|
|
|
|
my $msg= _msg( @_ ); |
127
|
0
|
|
|
|
|
|
__log($msg); |
128
|
0
|
0
|
|
|
|
|
eval { |
129
|
0
|
|
|
|
|
|
print STDERR colored $color, $msg; |
130
|
0
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
} or Carp::confess("wtf! $@"); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub _log(@) { |
135
|
0
|
|
|
0
|
|
|
__log(_msg( "# LOG:", @_ )); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub _print { |
139
|
0
|
|
|
0
|
|
|
__log(_msg("#PRINT:", @_)); |
140
|
0
|
|
|
|
|
|
print @_; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _printf { |
144
|
0
|
|
|
0
|
|
|
my $fmt= shift; |
145
|
0
|
|
|
|
|
|
my $msg= sprintf $fmt, @_; # i dont think you can use @_ here alone |
146
|
0
|
|
|
|
|
|
__log(_msg("#PRINT:", $msg)); |
147
|
0
|
|
|
|
|
|
print $msg; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _confess(@) { |
152
|
0
|
|
|
0
|
|
|
my $msg= Carp::longmess(); |
153
|
0
|
|
|
|
|
|
$msg= _msg( "# FATAL:", @_, $msg ); |
154
|
0
|
|
|
|
|
|
__log($msg); |
155
|
0
|
|
|
|
|
|
die colored [COLOR_CONFESS], $msg; |
156
|
|
|
|
|
|
|
} # very bad |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub _die(@) { |
159
|
|
|
|
|
|
|
# very bad |
160
|
0
|
|
|
0
|
|
|
my $msg= _msg( "# FATAL:", @_ ); |
161
|
0
|
|
|
|
|
|
__log($msg); |
162
|
0
|
|
|
|
|
|
chomp $msg; |
163
|
0
|
|
|
|
|
|
die colored([COLOR_DIE], $msg), "\n"; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub _error(@) { |
167
|
0
|
|
|
0
|
|
|
__say( [COLOR_DIE], "# ERROR:", @_ ); |
168
|
|
|
|
|
|
|
} # still bad, but not fatal |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _warn(@) { |
172
|
0
|
|
|
0
|
|
|
__say([COLOR_WARN], "# WARN :", @_ ); |
173
|
|
|
|
|
|
|
} # bad |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _info(@) { |
176
|
0
|
|
|
0
|
|
|
__say([COLOR_INFO], "# INFO :", @_ ); |
177
|
|
|
|
|
|
|
} # diags |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub _say(@) { |
180
|
0
|
|
|
0
|
|
|
__say([COLOR_SAY], "# NOTE :", @_ ); |
181
|
|
|
|
|
|
|
} # ok |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub _yay(@) { |
184
|
0
|
|
|
0
|
|
|
__say([COLOR_YAY], "# YAY :", @_ ); |
185
|
|
|
|
|
|
|
} # great |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub _tell(@) { |
188
|
0
|
|
|
0
|
|
|
__say( [COLOR_TELL], "# USER :", @_ ); |
189
|
|
|
|
|
|
|
} # tell user to do something |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |