Util.pm

filter: Statementstmt 6.2% 47 / 755 Branchbran 0.7% 3 / 396 Conditioncond 5.3% 6 / 113 MC/DCmcdc 0.0% 0 / 65 Subroutinesub 14.1% 14 / 99 Podpod 76.7% 56 / 73 totaltotal 8.3% 126 / 1501 CC 263 SCAR 44.4
CC
263
Cov
4%
meta_data_add
342.0
meta_data_rm
240.0
git
210.0
CRAP 85.2
↑ Summary Its/Eventum.pm »
1 package App::Gitc::Util;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: The workhorse of gitc
6 1 our $VERSION = '0.60'; # VERSION
7  
8 1 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Hash::Merge::Simple qw( merge );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # To help gitc load quickly, only use modules here which
13 # must be loaded at compile time. Otherwise, use "require Foo"
14 # in the implementation below. That way, the module can be
15 # lazily loaded at run time, if it's actually needed.
16 1 ▶use List::Util qw( first max );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use List::MoreUtils qw( first_index any );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use constant GITC_CONFIG => '/etc/gitc/gitc.config';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 our @EXPORT = qw(
25 current_branch
26 eventum
27 eventum_transition_status
28 fetch_tags
29 get_user_name
30 get_user_email
31 git
32 git_config
33 guarantee_a_clean_working_directory
34 let_user_edit
35 meta_data_add
36 meta_data_rm
37 meta_data_rm_all
38 project_config
39 its
40 its_for_changeset
41 );
42 1 our @EXPORT_OK = qw(
43 add_current_user
44 archived_tags
45 branch_basis
46 branch_point
47 cache_meta_data
48 changeset_group
49 changeset_merged_to
50 changesets_in
51 changesets_promoted_between
52 command_name
53 commit_decorations
54 confirm
55 current_branch_version
56 environment_preceding
57 full_changeset_name
58 git_fetch_and_clean_up
59 git_dir
60 git_tag
61 highest_quickfix_number
62 history
63 history_owner
64 history_reviewer
65 history_status
66 history_submitter
67 is_auto_fetch
68 is_merge_commit
69 is_suspendable
70 is_valid_ref
71 meta_data_rm_project
72 new_branch_version
73 new_version_tag
74 open_packed_refs
75 parse_changeset_spec
76 project_name
77 project_root
78 remote_branch_exists
79 restore_meta_data
80 sendmail
81 short_ref_name
82 sort_changesets_by_name
83 toplevel
84 traverse_commits
85 unmerged_changesets
86 unpromoted
87 user_lookup_class
88 version_tag_prefix
89 state_blocked
90 );
91 }
92  
93  
94 0 ▶sub confirm {
Subroutine confirm: not called CC=5 SCAR=34.0
Pod documented
95 0 my ($message) = @_;
96 0 ▶ die "No message given to 'confirm'" if not defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 0 0
97  
98 0 require Term::ReadLine;
99 0 my $term = Term::ReadLine->new('gitc');
100 0 my $prompt = "$message ";
101 0 my $response;
102  
103 # prompt the user
104 0 ▶ while ( defined( $response = $term->readline($prompt) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($response = $term->readline($prompt))) 0 0 0
105 0 ▶ return 1 if $response eq 'y';
Branch: 1 branch
BranchTrueFalseTotal
if $response eq "y" 0 0 0
106 0 ▶ return if $response eq 'n';
Branch: 1 branch
BranchTrueFalseTotal
if $response eq "n" 0 0 0
107 0 $prompt = "$message ('y' or 'n') ";
108 }
109 }
110  
111  
112 # If this ever needs to be faster, it can be implemented by opening
113 # .git/HEAD and parsing the one line contents. It would take a bit
114 # more effort to get it right, but it would avoid the fork+exec overhead
115 0 ▶sub current_branch {
Subroutine current_branch: not called CC=1 SCAR=6.9
Pod documented
116 0 my ($name) = grep /^[*]/, qx{ git branch --no-color };
117 0 chomp $name;
118 0 $name =~ s/^[*] //;
119 0 return $name;
120 }
121  
122  
123 0 ▶sub its_config {
Subroutine its_config: not called CC=1 SCAR=6.9
Pod documented
124 0 my $name = lc its()->label_service;
125  
126 0 return project_config()->{ "${name}_statuses" };
127 }
128  
129 # Eventum is the name of our internal ticketing system.
130 0 ▶sub eventum {
Subroutine eventum: not called CC=1 SCAR=6.9
Pod undocumented
131 0 return its()->get_issue( @_ );
132 }
133  
134 0 ▶sub eventum_transition_status {
Subroutine eventum_transition_status: not called CC=1 SCAR=6.9
Pod undocumented
135 0 return its()->transition_state( @_ );
136 }
137  
138  
139 0 ▶sub eventum_statuses {
Subroutine eventum_statuses: not called CC=7 SCAR=40.3
Pod documented
140 0 my ( $self, $command, $target ) = @_;
141  
142 0 ▶ my $statuses = project_config()->{'jira_statuses'}{$command}
Branch: 1 branch
BranchTrueFalseTotal
my $statuses = project_config()->{"jira_statuses"}{$command} or die "No JIRA statuses for $command" 0 0 0
143 or die "No JIRA statuses for $command";
144  
145 # handle the common case
146 0 ▶ if ( not $target ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target) 0 0 0
147 0 ▶ die "No initial status" unless $statuses->{from};
Branch: 1 branch
BranchTrueFalseTotal
unless $statuses->{"from"} 0 0 0
148 0 ▶ die "No final status" unless $statuses->{to};
Branch: 1 branch
BranchTrueFalseTotal
unless $statuses->{"to"} 0 0 0
149 0 return ( $statuses );
150 }
151  
152 # promotions need another level of dereference
153 0 ▶ die "No initial status for target $target" unless $statuses->{$target}{from};
Branch: 1 branch
BranchTrueFalseTotal
unless $statuses->{$target}{"from"} 0 0 0
154 0 ▶ die "No final status for target $target" unless $statuses->{$target}{to};
Branch: 1 branch
BranchTrueFalseTotal
unless $statuses->{$target}{"to"} 0 0 0
155 0 return $statuses->{$target};
156  
157 }
158  
159  
160 0 ▶sub _package_its {
Subroutine _package_its: not called CC=1 SCAR=6.9
161 0 my $its_type = shift;
162  
163 0 return 'App::Gitc::Its::'.ucfirst $its_type;
164 }
165  
166 0 ▶sub its {
Subroutine its: not called CC=4 SCAR=30.0
Pod documented
167 0 ▶ my $its = shift || project_config()->{'default_its'};
Condition0%0/3
shift() || project_config()->{'default_its'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || project_config()->{'default_its'}
shift() project_config()->{'default_its'}
Truth table0%0/3
A || B
A= shift()B= project_config()->{'default_its'}
ABresult
1X1
011
000
168
169 # They don't have to use an ITS if they don't want.
170 0 ▶ return undef unless $its;
Branch: 1 branch
BranchTrueFalseTotal
unless $its 0 0 0
171  
172 # But if one's specified, it has to work.
173 0 ▶ Class::MOP::load_class(_package_its($its))
Branch: 1 branch
BranchTrueFalseTotal
Class::MOP::load_class(_package_its($its)) or die "I can't load ${its}: $!.\n" 0 0 0
174 or die "I can't load $its: $!.\n";
175  
176 0 return _package_its($its)
177 }
178  
179 0 ▶sub user_lookup_class {
Subroutine user_lookup_class: not called CC=2 SCAR=17.9
Pod undocumented
180 my $lookup_class = project_config()->{ user_lookup_method }
181 0 ▶ // 'LocalGroup';
Condition0%0/2
project_config()->{"user_lookup_method"} // "LocalGroup"
l!l
00
MC/DC0%0/1
project_config()->{"user_lookup_method"} // "LocalGroup"
project_config()->{"user_lookup_method"}
Truth table0%0/2
A
A= project_config()->{"user_lookup_method"}
Aresult
11
00
182  
183 0 my $pkg = "App::Gitc::UserLookup::$lookup_class";
184  
185 0 Class::MOP::load_class( $pkg );
186  
187 0 return $pkg;
188 }
189  
190  
191 0 ▶sub its_for_changeset {
Subroutine its_for_changeset: not called CC=2 SCAR=17.9
Pod documented
192 0 my ( $changeset ) = @_;
193  
194 0 my $its = its();
195  
196 0 ▶ return $its->can( 'its_for_changeset' )
Branch: 1 branch
BranchTrueFalseTotal
$its->can('its_for_changeset') ? : 0 0 0
197 ? $its->its_for_changeset( $changeset )
198 : $its;
199 }
200  
201  
202 0 ▶sub git {
Subroutine git: not called CC=14 SCAR=53.5
Pod documented
203 0 my ($command_line) = @_;
204  
205 0 require Cwd;
206  
207 0 my $start = Cwd::cwd();
208 0 ▶ my $base = ( $command_line =~ /^clone / ? $start : toplevel() );
Branch: 1 branch
BranchTrueFalseTotal
$command_line =~ /^clone / ? : 0 0 0
209  
210 0 ▶ unless ( $start eq $base ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($start eq $base) 0 0 0
211 0 ▶ chdir $base || warn "Could not cd to $base";
Branch: 1 branch
BranchTrueFalseTotal
chdir $base or warn "Could not cd to $base" 0 0 0
212 }
213  
214 0 ▶ if ( not defined wantarray ) { # void context
Branch: 2 branches
BranchTrueFalseTotal
if (not defined wantarray) { } 0 0 0
elsif (wantarray) { } 0 0 0
215 0 ▶ warn "> git $command_line\n" if $ENV{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 0 0
216 0 ▶ system("git $command_line") == 0 and return;
Branch: 1 branch
BranchTrueFalseTotal
system("git $command_line") == 0 and return 0 0 0
217  
218 # uh oh, something went wrong
219 0 my $msg = '';
220 0 ▶ if ( $? == -1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($? == -1) { } 0 0 0
elsif ($? & 127) { } 0 0 0
221 0 $msg = "failed to execute: $!";
222 }
223 elsif ( $? & 127 ) {
224 0 $msg = sprintf "died with signal %d", ( $? & 127 );
225 }
226 else {
227 0 $msg = sprintf "exited with value %d", ( $? >> 8 );
228 }
229 0 require Carp;
230 0 Carp::croak("git $command_line failed: $msg");
231 }
232 elsif ( wantarray ) { # list context
233 0 ▶ warn "> git $command_line\n" if $ENV{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 0 0
234 0 my @output = qx{git $command_line};
235 # there's no reliable way to check if this failed
236 0 chomp @output;
237 0 return @output;
238 }
239  
240 # scalar context
241 0 ▶ warn "> git $command_line\n" if $ENV{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 0 0
242 0 my $output = qx{git $command_line};
243 0 ▶ if ( not defined $output ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
244 0 require Carp;
245 0 Carp::croak("git $command_line failed: $!");
246 }
247  
248 0 ▶ chdir $start unless $start eq $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $start eq $base 0 0 0
249  
250 0 chomp $output;
251 0 return $output;
252 }
253  
254  
255 0 ▶sub git_config {
Subroutine git_config: not called CC=5 SCAR=34.0
Pod documented
256 0 our %config;
257  
258 0 ▶ if ( not keys %config ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %App::Gitc::Util::config) 0 0 0
259 0 for my $line ( git "config -l" ) {
260 0 my ($name, $value) = split /=/, $line;
261 0 my @parts = split /[.]/, $name;
262 0 my $here = \%config;
263 0 for my $part ( @parts[ 0 .. $#parts-1 ] ) {
264 0 ▶ $here->{$part} = {} if not $here->{$part};
Branch: 1 branch
BranchTrueFalseTotal
unless $here->{$part} 0 0 0
265 0 $here = $here->{$part};
266 }
267 0 $here->{ $parts[-1] } = $value;
268 }
269 }
270  
271 0 return \%config;
272 }
273  
274  
275 0 ▶sub guarantee_a_clean_working_directory {
Subroutine guarantee_a_clean_working_directory: not called CC=6 SCAR=37.4
Pod documented
276 0 my $arguments = "diff -C -M --name-status";
277 0 my $staged = git "$arguments --cached";
278 0 my $changed = git $arguments;
279 0 ▶ return if not $staged and not $changed;
Branch: 1 branch
BranchTrueFalseTotal
unless $staged or $changed 0 0 0
Condition0%0/3
$staged or $changed
l!l&&r!l&&!r
000
MC/DC0%0/2
$staged or $changed
$staged $changed
Truth table0%0/3
A or B
A= $stagedB= $changed
ABresult
1X1
011
000
280  
281 # the tree is dirty, verify whether to continue
282 0 ▶ warn "It looks like you have uncommitted changes. If this is expected,\n"
Branch: 2 branches
BranchTrueFalseTotal
$staged ? : 0 0 0
$changed ? : 0 0 0
283 . "type 'y' to continue. If it's not expected, type 'n'.\n"
284 . ( $staged ? "staged:\n$staged\n" : '' )
285 . ( $changed ? "changed:\n$changed\n" : '' )
286 ;
287 0 ▶ die "Aborting at the user's request.\n" if not confirm('Continue?');
Branch: 1 branch
BranchTrueFalseTotal
unless confirm("Continue?") 0 0 0
288  
289 # stash the changes to let them be restored later
290 0 my $stash = git "stash create";
291 0 git "reset --hard";
292 0 return $stash;
293 }
294  
295  
296 0 ▶sub let_user_edit {
Subroutine let_user_edit: not called CC=3 SCAR=24.8
Pod documented
297 0 my ($filename) = @_;
298  
299 0 ▶ my $editor = $ENV{EDITOR} || $ENV{VISUAL} || '/usr/bin/vim';
Condition0%0/5
$ENV{'EDITOR'} || $ENV{'VISUAL'} || '/usr/bin/vim'
l!l
00
$ENV{"EDITOR"} or $ENV{"VISUAL"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'EDITOR'} || $ENV{'VISUAL'} || '/usr/bin/vim'
$ENV{"EDITOR"} $ENV{"VISUAL"}
Truth table0%0/3
A or B
A= $ENV{"EDITOR"}B= $ENV{"VISUAL"}
ABresult
1X1
011
000
300 0 system "$editor $filename";
301 }
302  
303 0 ▶sub create_blob {
Subroutine create_blob: not called CC=1 SCAR=6.9
Pod undocumented
304 0 my ($data_ref) = @_;
305  
306 0 my $tmp_file = "meta-$$.tmp";
307  
308 0 open my $tmp, ">", $tmp_file;
309 0 print {$tmp} Dump($data_ref);
310 0 print {$tmp} "\n";
311  
312 0 my $blob = git "hash-object -w $tmp_file";
313  
314 0 close $tmp;
315 0 unlink $tmp_file;
316  
317 0 return $blob;
318 }
319  
320 0 ▶sub view_blob {
Subroutine view_blob: not called CC=3 SCAR=24.8
Pod undocumented
321 0 my ($ref) = @_;
322  
323 0 my $output = git "show $ref";
324
325 0 ▶ return ($output and $output !~ /^fatal:/) ? Load($output) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$output && !($output =~ /^fatal:/) ? : 0 0 0
Condition0%0/3
$output and not $output =~ /^fatal:/
!ll&&!rl&&r
000
MC/DC0%0/2
$output and not $output =~ /^fatal:/
$output not $output =~ /^fatal:/
Truth table0%0/3
A and not(B)
A= $outputB= not $output =~ /^fatal:/
ABresult
0X0
100
111
326 }
327  
328 0 ▶sub get_user_name {
Subroutine get_user_name: not called CC=3 SCAR=24.8
Pod undocumented
329 0 my $git_user = git 'config --get user.name';
330 0 my $git_config = git_config();
331  
332 0 ▶ return $git_user || $git_config->{user}{name} || getpwuid $>;
Condition0%0/6
$git_user || $git_config->{'user'}{'name'} || getpwuid $>
l!l&&r!l&&!r
000
$git_user or $git_config->{"user"}{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$git_user || $git_config->{'user'}{'name'} || getpwuid $>
$git_user $git_config->{"user"}{"name"} getpwuid $>
Truth table0%0/4
A or B || C
A= $git_userB= $git_config->{"user"}{"name"}C= getpwuid $>
ABCresult
1XX1
01X1
0011
0000
333 }
334  
335 0 ▶sub get_user_email {
Subroutine get_user_email: not called CC=5 SCAR=34.0
Pod undocumented
336 0 my ($user) = @_;
337 0 ▶ return git 'config --get user.email' unless $user;
Branch: 1 branch
BranchTrueFalseTotal
unless $user 0 0 0
338 0 fetch_tags();
339 0 my $git_config = git_config();
340  
341 0 ▶ my $user_info = view_blob("user/$user") || {};
Condition0%0/2
view_blob("user/$user") || {}
l!l
00
MC/DC0%0/1
view_blob("user/$user") || {}
view_blob("user/$user")
Truth table0%0/2
A
A= view_blob("user/$user")
Aresult
11
00
342  
343 0 ▶ return $user_info->{email} || $git_config->{user}{email} || $user;
Condition0%0/6
$user_info->{'email'} || $git_config->{'user'}{'email'} || $user
l!l&&r!l&&!r
000
$user_info->{"email"} or $git_config->{"user"}{"email"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$user_info->{'email'} || $git_config->{'user'}{'email'} || $user
$user_info->{"email"} $git_config->{"user"}{"email"} $user
Truth table0%0/4
A or B || C
A= $user_info->{"email"}B= $git_config->{"user"}{"email"}C= $user
ABCresult
1XX1
01X1
0011
0000
344 }
345  
346 0 ▶sub add_current_user {
Subroutine add_current_user: not called CC=3 SCAR=24.8
Pod undocumented
347 0 my $user = get_user_name();
348 0 my $email = get_user_email();
349 # get user email defaults to returning username if not configured in git
350 # die if not configured
351 0 ▶ die "You need to configure a git username and email." unless $user ne $email;
Branch: 1 branch
BranchTrueFalseTotal
unless $user ne $email 0 0 0
352  
353 0 my $user_info = {email => $email};
354 0 my $blob = create_blob($user_info);
355  
356 0 ▶ git_tag('-d', "user/$user") if view_blob("user/$user");
Branch: 1 branch
BranchTrueFalseTotal
if view_blob("user/$user") 0 0 0
357 0 git_tag("user/$user", $blob);
358 0 return git "push --force origin user/$user";
359 }
360  
361  
362 0 ▶sub meta_data_add {
Subroutine meta_data_add: not called CC=18 SCAR=58.3
Pod documented
363 0 my ($entries) = @_;
364 0 ▶ if (ref($entries) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entries ne "ARRAY") 0 0 0
365 0 ▶ $entries = $entries ? [ $entries ] : [];
Branch: 1 branch
BranchTrueFalseTotal
$entries ? : 0 0 0
366 }
367  
368 0 my @meta_tags = get_meta_tags();
369 0 my %meta_tags;
370 0 ++$meta_tags{$_} for @meta_tags;
371  
372 0 our $tag_buffer;
373 0 ▶ initialize_tag_buffer() unless $tag_buffer;
Branch: 1 branch
BranchTrueFalseTotal
unless $App::Gitc::Util::tag_buffer 0 0 0
374 0 my @tags;
375 my $single_id;
376  
377 0 my $flush = 1;
378 0 for my $data (@$entries) {
379 # remember which user performed this action
380 0 ▶ $data->{user} = get_user_name() if not exists $data->{user};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{"user"} 0 0 0
381 0 my $changeset = $data->{changeset};
382  
383 0 ▶ my $meta_info = $meta_tags{"meta/$changeset"} ? view_blob("meta/$changeset") : [];
Branch: 1 branch
BranchTrueFalseTotal
$meta_tags{"meta/$changeset"} ? : 0 0 0
384 0 my $id = scalar @$meta_info;
385 0 ▶ $single_id = $id if @$entries == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$entries == 1 0 0 0
386  
387 0 my $flag = delete $data->{flush};
388 0 ▶ $flush = 0 if defined $flag and $flag == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $flag and $flag == 0 0 0 0
Condition0%0/3
defined $flag and $flag == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $flag and $flag == 0
defined $flag $flag == 0
Truth table0%0/3
A and B
A= defined $flagB= $flag == 0
ABresult
0X0
100
111
389 0 $data->{stamp} = time;
390 0 $meta_info->[$id] = $data;
391  
392 0 my $blob = create_blob($meta_info);
393
394 0 my $exists = grep {m|^meta/$changeset|} get_meta_tags();
395 0 ▶ git_tag('-d', "meta/$changeset") if $exists;
Branch: 1 branch
BranchTrueFalseTotal
if $exists 0 0 0
396 0 git_tag("meta/$changeset", $blob);
397 0 push @tags, "meta/$changeset";
398 }
399  
400 0 push @{$tag_buffer->{meta_add}}, @tags;
401
402 # this makes sure we dont update the same tag twice(on add and rm)
403 # not dangerous to do, just a little bit slower
404 0 ▶ if (my @rm_tags = @{$tag_buffer->{meta_rm}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@rm_tags) = @{$App::Gitc::Util::tag_buffer->{"meta_rm"};}) 0 0 0
405 0 for my $tag (@tags) {
406 0 ▶ my $i = first_index {$_ eq $tag} @rm_tags;
Subroutine __ANON__: not called CC=1 SCAR=6.9
407 0 ▶ next unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
408 0 splice(@rm_tags, $i, 1);
409 }
410 $tag_buffer->{meta_rm} = \@rm_tags
411 0 }
412  
413 0 ▶ if ($flush) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flush) 0 0 0
414 0 my @buffered_tags = @{$tag_buffer->{meta_add}};
415 0 ▶ git "push --force origin @buffered_tags" if @buffered_tags;
Branch: 1 branch
BranchTrueFalseTotal
if @buffered_tags 0 0 0
416 }
417  
418 # the return value only makes sense for single inserts
419 0 ▶ return if @$entries > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$entries > 1 0 0 0
420 0 return $single_id;
421 }
422  
423 0 ▶sub initialize_tag_buffer {
Subroutine initialize_tag_buffer: not called CC=1 SCAR=6.9
Pod undocumented
424 0 our $tag_buffer = {};
425 0 $tag_buffer->{meta_add} = [];
426 0 $tag_buffer->{meta_rm} = [];
427  
428 0 return;
429 }
430  
431  
432 0 ▶sub meta_data_rm {
Subroutine meta_data_rm: not called CC=15 SCAR=54.8
Pod documented
433 0 ▶ my @args = (ref $_[0] eq 'HASH') ? @_ : @_ ? {@_} : ();
Branch: 2 branches
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
@_ ? : 0 0 0
434 # force into array of hashrefs
435  
436 0 our $recent_meta_data;
437 0 ▶ ++$recent_meta_data and git "fetch origin --tags" if not $recent_meta_data;
Branch: 1 branch
BranchTrueFalseTotal
unless $App::Gitc::Util::recent_meta_data 0 0 0
Condition0%0/6
$App::Gitc::Util::recent_meta_data || ++$App::Gitc::Util::recent_meta_data && git('fetch origin --tags')
l!l&&r!l&&!r
000
++$App::Gitc::Util::recent_meta_data and git("fetch origin --tags")
!ll&&!rl&&r
000
MC/DC0%0/3
$App::Gitc::Util::recent_meta_data || ++$App::Gitc::Util::recent_meta_data && git('fetch origin --tags')
$App::Gitc::Util::recent_meta_data ++$App::Gitc::Util::recent_meta_data git("fetch origin --tags")
Truth table0%0/4
A || B and C
A= $App::Gitc::Util::recent_meta_dataB= ++$App::Gitc::Util::recent_meta_dataC= git("fetch origin --tags")
ABCresult
1XX1
0111
00X0
0100
438  
439 0 our $tag_buffer;
440 0 ▶ initialize_tag_buffer() unless $tag_buffer;
Branch: 1 branch
BranchTrueFalseTotal
unless $App::Gitc::Util::tag_buffer 0 0 0
441  
442 0 my @tags;
443 0 my $flush = 1;
444 0 for my $arg (@args) {
445 0 my $meta_info = view_blob("meta/$arg->{changeset}");
446 0 ▶ return unless $meta_info;
Branch: 1 branch
BranchTrueFalseTotal
unless $meta_info 0 0 0
447  
448 0 splice(@$meta_info, $arg->{id}, 1);
449 0 my $blob = create_blob($meta_info);
450 0 git_tag('-d', "meta/$arg->{changeset}");
451 0 git_tag("meta/$arg->{changeset}", $blob);
452 0 push @tags, "meta/$arg->{changeset}";
453 0 ▶ $flush = 0 if exists $arg->{flush} and $arg->{flush} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg->{"flush"} and $arg->{"flush"} == 0 0 0 0
Condition0%0/3
exists $arg->{"flush"} and $arg->{"flush"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
exists $arg->{"flush"} and $arg->{"flush"} == 0
exists $arg->{"flush"} $arg->{"flush"} == 0
Truth table0%0/3
A and B
A= exists $arg->{"flush"}B= $arg->{"flush"} == 0
ABresult
0X0
100
111
454 }
455  
456 0 push @{$tag_buffer->{meta_rm}}, @tags;
457  
458 # this makes sure we dont update the same tag twice(on add and rm)
459 # not dangerous to do, just a little bit slower
460 0 ▶ if (my @add_tags = @{$tag_buffer->{meta_add}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@add_tags) = @{$App::Gitc::Util::tag_buffer->{"meta_add"};}) 0 0 0
461 0 for my $tag (@tags) {
462 0 ▶ my $i = first_index {$_ eq $tag} @add_tags;
Subroutine __ANON__: not called CC=1 SCAR=6.9
463 0 ▶ next unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
464 0 splice(@add_tags, $i, 1);
465 }
466 0 $tag_buffer->{meta_rm} = \@add_tags;
467 }
468  
469 0 ▶ if ($flush) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flush) 0 0 0
470 0 my @buffered_tags = @{$tag_buffer->{meta_rm}};
471 0 ▶ git "push --force origin @buffered_tags" if @buffered_tags;
Branch: 1 branch
BranchTrueFalseTotal
if @buffered_tags 0 0 0
472 }
473  
474 0 return;
475 }
476  
477  
478 0 ▶sub meta_data_rm_all {
Subroutine meta_data_rm_all: not called CC=2 SCAR=17.9
Pod documented
479 0 my ($changeset) = @_;
480  
481 0 git "fetch origin --tags";
482 0 ▶ my $meta_tag = ($changeset =~ m{^meta/}) ? $changeset :
Branch: 1 branch
BranchTrueFalseTotal
$changeset =~ m[^meta/] ? : 0 0 0
483 "meta/$changeset";
484  
485 0 git_tag('-d', "$meta_tag");
486 0 git "push origin :$meta_tag";
487 }
488  
489 0 ▶sub fetch_tags {
Subroutine fetch_tags: not called CC=3 SCAR=24.8
Pod undocumented
490 0 our $recent_tags;
491 0 ▶ ++$recent_tags and git "fetch origin --tags" unless $recent_tags;
Branch: 1 branch
BranchTrueFalseTotal
unless $App::Gitc::Util::recent_tags 0 0 0
Condition0%0/6
$App::Gitc::Util::recent_tags || ++$App::Gitc::Util::recent_tags && git('fetch origin --tags')
l!l&&r!l&&!r
000
++$App::Gitc::Util::recent_tags and git("fetch origin --tags")
!ll&&!rl&&r
000
MC/DC0%0/3
$App::Gitc::Util::recent_tags || ++$App::Gitc::Util::recent_tags && git('fetch origin --tags')
$App::Gitc::Util::recent_tags ++$App::Gitc::Util::recent_tags git("fetch origin --tags")
Truth table0%0/4
A || B and C
A= $App::Gitc::Util::recent_tagsB= ++$App::Gitc::Util::recent_tagsC= git("fetch origin --tags")
ABCresult
1XX1
0111
00X0
0100
492 }
493  
494 0 ▶sub get_meta_tags {
Subroutine get_meta_tags: not called CC=3 SCAR=24.8
Pod undocumented
495 0 my (%args) = @_;
496 0 ▶ $args{fetch} //= 1;
Condition0%0/2
$args{"fetch"} //= 1
l!l
00
MC/DC0%0/1
$args{"fetch"} //= 1
$args{"fetch"}
Truth table0%0/2
A
A= $args{"fetch"}
Aresult
11
00
497 0 ▶ fetch_tags() if $args{fetch};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"fetch"} 0 0 0
498  
499 0 my $meta_tag_string = git "tag -l 'meta/*'";
500 0 return split "\n", $meta_tag_string;
501 }
502  
503  
504 0 ▶sub meta_data_rm_project {
Subroutine meta_data_rm_project: not called CC=2 SCAR=17.9
Pod documented
505 0 my ($project) = @_;
506  
507 0 my @meta_tags = get_meta_tags();
508 0 meta_data_rm_all($_) for @meta_tags;
509  
510 0 return;
511 }
512  
513  
514 0 ▶sub new_branch_version {
Subroutine new_branch_version: not called CC=2 SCAR=17.9
Pod documented
515 0 my ($branch, $new_major_version) = @_;
516  
517 0 my $latest = current_branch_version_details( $branch );
518 0 my $major = $latest->{major_version};
519 0 my $minor = $latest->{minor_version} + 1;
520  
521 0 ▶ if ($new_major_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_major_version) 0 0 0
522 0 $major += 1;
523 0 $minor = 0;
524 }
525  
526 0 return "$major.$minor";
527 }
528  
529  
530 0 ▶sub new_version_tag {
Subroutine new_version_tag: not called CC=1 SCAR=6.9
Pod documented
531 0 my ($branch, $new_major_version) = @_;
532  
533 0 my $tag_prefix = version_tag_prefix( $branch );
534 0 my $version = new_branch_version( $branch, $new_major_version );
535  
536 0 return "$tag_prefix$version";
537 }
538  
539  
540 0 ▶sub project_config {
Subroutine project_config: not called CC=12 SCAR=50.5
Pod documented
541 0 my $project_name = shift;
542  
543 0 my @files = (GITC_CONFIG);
544 # we can't pull from the per-project dir if we specify the project_name
545 0 my $project_file;
546 0 ▶ unless ($project_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_name) 0 0 0
547 0 my $root = project_root();
548 0 $project_file = $root . '/gitc.config';
549 0 push(@files, $project_file);
550 }
551  
552 0 push(@files, $ENV{HOME} . '/.gitc/gitc.config');
553 # we default to looking up the project name via git if not passed in
554 0 ▶ $project_name ||= project_name();
Condition0%0/3
$project_name ||= project_name()
l!l&&r!l&&!r
000
MC/DC0%0/2
$project_name ||= project_name()
$project_name project_name()
Truth table0%0/3
A ||= B
A= $project_nameB= project_name()
ABresult
1X1
011
000
555 0 ▶ if ($ENV{GITC_CONFIG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"GITC_CONFIG"}) 0 0 0
556 0 push(@files, split(':', $ENV{GITC_CONFIG}));
557 }
558
559 0 my $projects;
560 0 local $YAML::Syck::UseCode = 1;
561 0 foreach my $file (@files) {
562 0 ▶ next unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
563 0 my $data = eval {YAML::Syck::LoadFile($file)};
564 # Allow the config file that is in the project_dir to not have to
565 # specify itself This will allow that configuration file to be
566 # formatted slightly differently but in a way which would make more
567 # sense locally to that project
568 0 ▶ if ($file eq $project_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq $project_file) 0 0 0
569 0 ▶ if (!$data->{$project_name} and keys %{$data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $data->{$project_name} and keys %{$data;}) 0 0 0
Condition0%0/3
not $data->{$project_name} and keys %{$data;}
!ll&&!rl&&r
000
MC/DC0%0/2
not $data->{$project_name} and keys %{$data;}
not $data->{$project_name} keys %{$data;}
Truth table0%0/3
not(A) and B
A= not $data->{$project_name}B= keys %{$data;}
ABresult
0X0
100
111
570 0 $data = {$project_name => $data};
571 }
572 }
573
574 0 $projects = merge $projects, $data;
575 }
576  
577 0 ▶ my $project_config = $projects->{ $project_name } // $projects;
Condition0%0/3
$projects->{$project_name} // $projects
l!l&&r!l&&!r
000
MC/DC0%0/2
$projects->{$project_name} // $projects
$projects->{$project_name} $projects
Truth table0%0/3
A // B
A= $projects->{$project_name}B= $projects
ABresult
1X1
011
000
578
579 0 ▶ die "No config found!\n" if !keys %{ $project_config // {} };
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$project_config // {};} 0 0 0
Condition0%0/2
$project_config // {}
l!l
00
MC/DC0%0/1
$project_config // {}
$project_config
Truth table0%0/2
A
A= $project_config
Aresult
11
00
580  
581 0 return $project_config;
582 }
583  
584  
585 0 ▶sub archived_tags {
Subroutine archived_tags: not called CC=3 SCAR=24.8
Pod documented
586 0 my $tag_portion = shift;
587 0 my $dbh = dbh();
588 0 my $project_name = project_name();
589  
590 # sort with 'BINARY' to force case sensitive sorting
591 # so that it matches Git's sort order
592 0 my $sql = q{
593 SELECT sha1, tag_name
594 FROM tag_archive
595 WHERE project = ?
596 };
597  
598 0 ▶ if ($tag_portion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag_portion) 0 0 0
599 0 $sql .= 'AND tag_name LIKE ?';
600 0 $tag_portion = '%' . $tag_portion . '%';
601 }
602  
603 0 $sql .= q{
604 ORDER BY BINARY tag_name
605 };
606 0 ▶ my $refs = $dbh->selectall_arrayref( $sql, undef, $project_name, $tag_portion || () );
Condition0%0/3
$tag_portion || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag_portion || ()
$tag_portion ()
Truth table0%0/3
A || B
A= $tag_portionB= ()
ABresult
1X1
011
000
607 0 return $refs;
608 }
609  
610  
611 0 ▶sub branch_basis {
Subroutine branch_basis: not called CC=8 SCAR=42.8
Pod documented
612 0 ▶ my $branch_point = shift or return 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
my $branch_point = shift() or return "unknown" 0 0 0
613  
614 0 my @decorations = commit_decorations($branch_point);
615 0 for (@decorations) {
616 0 ▶ return $1 if m{/to-(master|test|stage|prod)$};
Branch: 1 branch
BranchTrueFalseTotal
if m[/to-(master|test|stage|prod)$] 0 0 0
617 0 ▶ return $1 if m{^refs/remotes/origin/(master|test|stage|prod)$};
Branch: 1 branch
BranchTrueFalseTotal
if m[^refs/remotes/origin/(master|test|stage|prod)$] 0 0 0
618 0 ▶ return $1 if m{^refs/tags/cs/(.*)/head$};
Branch: 1 branch
BranchTrueFalseTotal
if m[^refs/tags/cs/(.*)/head$] 0 0 0
619 0 ▶ return $1 if m{^refs/tags/(test|stage|prod)/[\dTZ_-]{20}$};
Branch: 1 branch
BranchTrueFalseTotal
if m[^refs/tags/(test|stage|prod)/[\dTZ_-]{20}$] 0 0 0
620 0 ▶ return $1 if m{^refs/remotes/origin/pu/(.*)$};
Branch: 1 branch
BranchTrueFalseTotal
if m[^refs/remotes/origin/pu/(.*)$] 0 0 0
621 }
622  
623 0 return 'unknown';
624 }
625  
626  
627 # Implementation note:
628 #
629 # To find the branch point, we traverse the branch's commit history looking
630 # for the first commit. The branch point is that commit's parent. There are
631 # a few edge cases that need to be handled along the way.
632 0 ▶sub branch_point {
Subroutine branch_point: not called CC=8 SCAR=42.8
Pod documented
633 0 my $ref = shift;
634 0 ▶ $ref = current_branch() if not defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 0 0 0
635 0 ▶ my $changeset = short_ref_name($ref)
Branch: 1 branch
BranchTrueFalseTotal
my $changeset = short_ref_name($ref) or die "You can only find branch points for changeset branches\n" 0 0 0
636 or die "You can only find branch points for changeset branches\n";
637 0 ▶ my $ref_ptr = is_valid_ref($ref)
Branch: 1 branch
BranchTrueFalseTotal
my $ref_ptr = is_valid_ref($ref) or die "You gave branch_point an invalid ref\n" 0 0 0
638 or die "You gave branch_point an invalid ref\n";
639  
640 # build the log command
641 0 ▶ my %to = map { m{/to-(.*)$} ? ( $1 => 1 ) : () }
Branch: 1 branch
BranchTrueFalseTotal
m[/to-(.*)$] ? : 0 0 0
642 git "tag -l cs/$changeset/*";
643 0 ▶ my @excludes = map { $to{$_} ? "^cs/$changeset/to-$_~1" : "^origin/$_" }
Branch: 1 branch
BranchTrueFalseTotal
$to{$_} ? : 0 0 0
644 qw( master test stage prod );
645  
646 # traverse the commits along this changeset branch
647 0 my $saw_a_commit;
648 my $parent;
649 0 my $done;
650 0 ▶ traverse_commits( "--first-parent $ref @excludes --", sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
651 0 my ($args) = @_;
652 0 $saw_a_commit = 1;
653 0 ▶ return if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
654 0 my @parents = @{ $args->{parents} };
655 0 ▶ if ( @parents > 1 ) { # merge commit
Branch: 1 branch
BranchTrueFalseTotal
if (@parents > 1) 0 0 0
656 0 $done = 1;
657 0 $parent = $parents[1]; # second parent is merge source
658 0 return;
659 }
660 0 for my $decoration ( commit_decorations($args->{commit}) ) {
661 0 ▶ if ( $decoration =~ m{/cs/(.*)/head$} and $1 ne $changeset ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($decoration =~ m[/cs/(.*)/head$] and $1 ne $changeset) { } 0 0 0
elsif ($decoration =~ m[/pu/(.*)$] and $1 ne $changeset) { } 0 0 0
Condition0%0/3
$decoration =~ m[/cs/(.*)/head$] and $1 ne $changeset
!ll&&!rl&&r
000
MC/DC0%0/2
$decoration =~ m[/cs/(.*)/head$] and $1 ne $changeset
$decoration =~ m[/cs/(.*)/head$] $1 ne $changeset
Truth table0%0/3
A and B
A= $decoration =~ m[/cs/(.*)/head$]B= $1 ne $changeset
ABresult
0X0
100
111
662 0 $done = 1;
663 0 $parent = $args->{commit};
664 0 return;
665 }
666 ▶ elsif( $decoration =~ m{/pu/(.*)$} and $1 ne $changeset ) {
Condition0%0/3
$decoration =~ m[/pu/(.*)$] and $1 ne $changeset
!ll&&!rl&&r
000
MC/DC0%0/2
$decoration =~ m[/pu/(.*)$] and $1 ne $changeset
$decoration =~ m[/pu/(.*)$] $1 ne $changeset
Truth table0%0/3
A and B
A= $decoration =~ m[/pu/(.*)$]B= $1 ne $changeset
ABresult
0X0
100
111
667 0 $done = 1;
668 0 $parent = $args->{commit};
669 0 return;
670 }
671 }
672 0 ($parent) = @{ $args->{parents} };
673 0 });
674  
675 0 ▶ return $ref_ptr if not $saw_a_commit; # no changeset commits yet
Branch: 1 branch
BranchTrueFalseTotal
unless $saw_a_commit 0 0 0
676 0 ▶ return if not $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
677 0 return $parent;
678 }
679  
680  
681 0 ▶sub changeset_group {
Subroutine changeset_group: not called CC=6 SCAR=37.4
Pod documented
682 0 my ($changeset) = @_;
683  
684 # handle the trivial cases
685 0 ▶ die "Cannot determine the changeset group for undef"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $changeset 0 0 0
686 if not defined $changeset;
687 0 my ( $prefix, $number ) = $changeset =~ m{
688 ^ ([a-zA-Z-]+) # 'e', 'TE-' or 'quickfix' probably
689 (\d*) # the Eventum number
690 }xms;
691  
692 0 my $project_name = project_name();
693  
694 0 my @meta_tags = get_meta_tags();
695 0 ▶ my @changesets = grep {defined $prefix ? /$prefix$number/ : $_ eq $changeset}
Branch: 1 branch
BranchTrueFalseTotal
defined $prefix ? : 0 0 0
696 0 map {s{^meta/}{}} @meta_tags;
697 0 my @open_changesets = grep {my $meta_info = view_blob($_); $meta_info->[-1]{action} eq 'open'} @changesets;
698 0 my $changesets = \@open_changesets;
699  
700 0 ▶ return $changesets if not defined $prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prefix 0 0 0
701 0 ▶ return $changesets if $prefix ne 'e';
Branch: 1 branch
BranchTrueFalseTotal
if $prefix ne "e" 0 0 0
702  
703 # Eventum changesets
704 0 ▶ my @peers = grep { /(\d+)/ and $1 == $number } @$changesets;
Condition0%0/3
/(\d+)/ && $1 == $number
!ll&&!rl&&r
000
MC/DC0%0/2
/(\d+)/ && $1 == $number
/(\d+)/ $1 == $number
Truth table0%0/3
A && B
A= /(\d+)/B= $1 == $number
ABresult
0X0
100
111
705 0 sort_changesets_by_name(\@peers);
706 0 return \@peers;
707 }
708  
709  
710 0 ▶sub changeset_merged_to {
Subroutine changeset_merged_to: not called CC=4 SCAR=30.0
Pod documented
711 0 my ($changeset) = @_;
712  
713 0 my @merged_to;
714 0 for my $env (qw( master test stage prod )) {
715 0 ▶ push @merged_to, $env if is_valid_ref("cs/$changeset/to-$env");
Branch: 1 branch
BranchTrueFalseTotal
if is_valid_ref("cs/$changeset/to-$env") 0 0 0
716 }
717  
718 0 ▶ return wantarray ? @merged_to : join(', ', @merged_to);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
719 }
720  
721  
722 1 ▶use Date::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
723  
724 0 ▶sub changesets_promoted_between {
Subroutine changesets_promoted_between: not called CC=13 SCAR=52.0
Pod documented
725 0 my ($args) = @_;
726 0 ▶ my $project = $args->{project} or die "No project\n";
Branch: 1 branch
BranchTrueFalseTotal
my $project = $args->{"project"} or die "No project\n" 0 0 0
727 0 ▶ my $target = $args->{target} or die "No target\n";
Branch: 1 branch
BranchTrueFalseTotal
my $target = $args->{"target"} or die "No target\n" 0 0 0
728 0 ▶ my $start = $args->{start} or die "No start time\n";
Branch: 1 branch
BranchTrueFalseTotal
my $start = $args->{"start"} or die "No start time\n" 0 0 0
729 0 ▶ my $end = $args->{end} or die "No end time\n";
Branch: 1 branch
BranchTrueFalseTotal
my $end = $args->{"end"} or die "No end time\n" 0 0 0
730  
731 0 $start = str2time($start);
732 0 $end = str2time($end);
733  
734 0 my @meta_tags = get_meta_tags();
735 0 my $changesets = [];
736 0 for my $tag (@meta_tags) {
737 0 my ($cs_name) = $tag =~ m{^meta/(.*)};
738 0 my $meta_info = view_blob($tag);
739 0 my ($ok_target, $ok_time);
740 0 for my $entry (@$meta_info) {
741 0 ($ok_target, $ok_time) = ();
742 0 ▶ next unless $entry->{action} eq 'promote';
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"action"} eq "promote" 0 0 0
743 0 my $stamp = $entry->{stamp};
744 0 ▶ ++$ok_target if $entry->{target} eq $target;
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"target"} eq $target 0 0 0
745 0 ▶ ++$ok_time if ($stamp > $start and $stamp < $end);
Branch: 1 branch
BranchTrueFalseTotal
if $stamp > $start and $stamp < $end 0 0 0
Condition0%0/3
$stamp > $start and $stamp < $end
!ll&&!rl&&r
000
MC/DC0%0/2
$stamp > $start and $stamp < $end
$stamp > $start $stamp < $end
Truth table0%0/3
A and B
A= $stamp > $startB= $stamp < $end
ABresult
0X0
100
111
746 }
747 0 ▶ push @$changesets, $cs_name if ($ok_target and $ok_time);
Branch: 1 branch
BranchTrueFalseTotal
if $ok_target and $ok_time 0 0 0
Condition0%0/3
$ok_target and $ok_time
!ll&&!rl&&r
000
MC/DC0%0/2
$ok_target and $ok_time
$ok_target $ok_time
Truth table0%0/3
A and B
A= $ok_targetB= $ok_time
ABresult
0X0
100
111
748 }
749  
750 0 return @$changesets;
751 }
752  
753  
754 0 ▶sub commit_decorations {
Subroutine commit_decorations: not called CC=14 SCAR=53.5
Pod documented
755 0 my ($commit) = @_;
756 0 our %decorations;
757 0 our $decorations_populated_from_disk;
758  
759 # build the decorations cache
760 0 ▶ if ( not $decorations_populated_from_disk ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($App::Gitc::Util::decorations_populated_from_disk) 0 0 0
761 0 $decorations_populated_from_disk = 1;
762 0 %decorations = (); # start fresh
763 0 my %packed_refs; # map refs to commits (inverse of %decorations)
764  
765 # process packed refs (before loose refs)
766 0 ▶ if ( -e '.git/packed-refs' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e ".git/packed-refs") 0 0 0
767 0 ▶ open my $refs, '<', '.git/packed-refs'
Branch: 1 branch
BranchTrueFalseTotal
open my $refs, "<", ".git/packed-refs" or die "Unable to open packed refs: $!\n" 0 0 0
768 or die "Unable to open packed refs: $!\n";
769 0 ▶ while ( my $line = <$refs> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $refs)) 0 0 0
770 0 chomp $line;
771 0 ▶ next if $line =~ m/^#/; # skip comments
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 0 0 0
772 0 my ( $commit, $ref ) = split / /, $line, 2;
773 0 ▶ next if not $commit;
Branch: 1 branch
BranchTrueFalseTotal
unless $commit 0 0 0
774 0 ▶ next if not $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 0 0
775 0 $packed_refs{$ref} = $commit;
776 0 $decorations{$commit}{$ref} = 1;
777 }
778 }
779  
780 # process all loose refs
781 0 ▶ open my $refs, '-|', 'find .git/refs -type f'
Branch: 1 branch
BranchTrueFalseTotal
open my $refs, "-|", "find .git/refs -type f" or die "Unable to run find: $!\n" 0 0 0
782 or die "Unable to run find: $!\n";
783 0 ▶ while ( my $ref = <$refs> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ref = readline $refs)) 0 0 0
784 0 chomp $ref;
785 0 my $commit = do {
786 0 open my $fh, '<', "$ref";
787 0 local $/;
788 0 <$fh>;
789 };
790 0 chomp $commit;
791 0 $ref =~ s{\.git/refs/}{};
792 0 ▶ if ( my $stale_commit = delete $packed_refs{"refs/$ref"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stale_commit = delete $packed_refs{"refs/$ref"}) 0 0 0
793 0 delete $decorations{$stale_commit}{"refs/$ref"};
794 }
795 0 $decorations{$commit}{"refs/$ref"} = 1;
796 }
797 }
798  
799 0 ▶ if ( not $decorations{$commit} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($App::Gitc::Util::decorations{$commit}) 0 0 0
800 0 ▶ return if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
801 0 return [];
802 }
803 0 my @ds = keys %{ $decorations{$commit} };
804 0 ▶ return wantarray ? @ds : \@ds;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
805 }
806  
807  
808 0 ▶sub current_branch_version {
Subroutine current_branch_version: not called CC=1 SCAR=6.9
Pod documented
809 0 my ($branch) = @_;
810  
811 0 return current_branch_version_details( $branch )->{full_version};
812 }
813  
814 0 ▶sub current_branch_version_details {
Subroutine current_branch_version_details: not called CC=3 SCAR=24.8
Pod undocumented
815 0 my ($branch) = @_;
816  
817 die "Project not setup to support version tagging"
818 0 ▶ unless project_config()->{use_version_tags};
Branch: 1 branch
BranchTrueFalseTotal
unless project_config()->{"use_version_tags"} 0 0 0
819  
820 0 my $tag_prefix = version_tag_prefix( $branch );
821 0 my @versions = git("tag -l $tag_prefix*");
822 #XXX Would be nice to support different version # formats
823 return {
824 0 ▶ major_version => 1,
Branch: 1 branch
BranchTrueFalseTotal
unless @versions 0 0 0
825 minor_version => 0,
826 full_version => '1.0',
827 } unless @versions;
828  
829 # Get rid of tag prefixes so we have numbers to work with...
830 0 @versions = map { s/$tag_prefix//; $_ } @versions;
831 0 @versions = sort { $a <=> $b } @versions;
832  
833 0 my $major_version = $versions[-1];
834 # remove the minor version number at the end
835 0 $major_version =~ s/\.\d+$//;
836  
837 # Get all tags for the current major version...
838 0 @versions = grep { /^$major_version\./ } @versions;
839 # ...then remove the tag major version and sort by minor version
840 0 @versions = map { s/^$major_version\.//; $_ } @versions;
841 # ...then sort numerically
842 0 @versions = sort { $a <=> $b } @versions;
843 # ...so our latest minor version is the last in the list
844 0 my $minor_version = pop @versions;
845  
846 return {
847 0 major_version => $major_version,
848 minor_version => $minor_version,
849 full_version => "$major_version.$minor_version",
850 };
851 }
852  
853  
854 0 ▶sub environment_preceding {
Subroutine environment_preceding: not called CC=3 SCAR=24.8
Pod documented
855 0 my ($target) = @_;
856  
857 0 my @environments = qw( master test stage prod );
858 0 ▶ my $i = first_index { $target eq $_ } @environments;
Subroutine __ANON__: not called CC=1 SCAR=6.9
859 0 ▶ die "Unknown environment name: $target\n" if $i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 0 0
860 0 ▶ return if $i == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 0 0 0
861 0 return $environments[ $i-1 ];
862 }
863  
864  
865 0 ▶sub full_changeset_name {
Subroutine full_changeset_name: not called CC=8 SCAR=42.8
Pod documented
866 0 my ($name, %params) = @_;
867 0 ▶ die "'$name' doesn't look like a changeset name\n" if $name =~ m{/};
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ m[/] 0 0 0
868  
869 # cache searches since they're slow
870 0 our %cache;
871 0 ▶ return $cache{$name} if exists $cache{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $App::Gitc::Util::cache{$name} 0 0 0
872  
873 0 ▶ my $full_name
Branch: 3 branches
BranchTrueFalseTotal
is_valid_ref("cs/$name/head") ? : 0 0 0
is_valid_ref("origin/pu/$name") ? : 0 0 0
is_valid_ref($name) ? : 0 0 0
874 = is_valid_ref("cs/$name/head") ? "cs/$name/head" # merged
875 : is_valid_ref("origin/pu/$name") ? "origin/pu/$name" # pending
876 : is_valid_ref($name) ? $name # open
877 : undef;
878  
879 0 ▶ unless (defined $full_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $full_name) 0 0 0
880 0 ▶ return if $params{missing_ok};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"missing_ok"} 0 0 0
881 0 die "Cannot determine a full changeset name for '$name'\n";
882 }
883  
884 0 return $cache{$name} = $full_name;
885 }
886  
887  
888 0 ▶sub git_dir {
Subroutine git_dir: not called CC=2 SCAR=17.9
Pod documented
889  
890 # perhaps the path is already cached?
891 0 our $git_dir;
892 0 ▶ return $git_dir if defined $git_dir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $App::Gitc::Util::git_dir 0 0 0
893  
894 # nope, ask Git where .git is
895 0 require Cwd;
896 0 my ($raw) = git "rev-parse --git-dir";
897 0 return $git_dir = Cwd::realpath($raw);
898 }
899  
900  
901 0 ▶sub git_fetch_and_clean_up {
Subroutine git_fetch_and_clean_up: not called CC=1 SCAR=6.9
Pod documented
902 0 git "remote update -p origin";
903 0 git "gc --auto";
904 0 return;
905 }
906  
907  
908 0 ▶sub git_tag {
Subroutine git_tag: not called CC=4 SCAR=30.0
Pod documented
909 0 our %decorations;
910 0 ▶ if ( $_[0] eq '-d' ) { # deleting a tag
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] eq '-d') { } 0 0 0
911 0 my ( $d, $name ) = @_;
912 0 my $commit = git "rev-parse $name";
913 0 git "tag $d $name";
914 0 delete $decorations{$commit}{"refs/tags/$name"};
915 }
916 else {
917 0 ▶ my ( $f, $name, $commit ) = @_ == 3 ? @_ : ( '', @_ );
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 ? : 0 0 0
918 0 ▶ $commit = git "rev-parse $commit" if $commit eq 'HEAD';
Branch: 1 branch
BranchTrueFalseTotal
if $commit eq "HEAD" 0 0 0
919 0 git "tag $f $name $commit";
920 0 $decorations{$commit}{"refs/tags/$name"} = 1;
921 }
922  
923 0 return;
924 }
925  
926  
927 0 ▶sub highest_quickfix_number {
Subroutine highest_quickfix_number: not called CC=3 SCAR=24.8
Pod documented
928 0 my ($project_name) = @_;
929  
930 0 git 'fetch origin --tags';
931 0 my @quickfixes = grep {m|^meta/quickfix|} get_meta_tags();
932 0 ▶ my @numbers = map { /quickfix(\d+)$/ ? $1 : () } @quickfixes;
Branch: 1 branch
BranchTrueFalseTotal
/quickfix(\d+)$/ ? : 0 0 0
933 0 ▶ return 0 if not @numbers;
Branch: 1 branch
BranchTrueFalseTotal
unless @numbers 0 0 0
934 0 return max @numbers;
935 }
936  
937  
938 1 ▶use Date::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
939  
940 0 ▶sub history {
Subroutine history: not called CC=5 SCAR=34.0
Pod documented
941 0 ▶ my ( $project_name, $changeset )
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 0 0
942 = @_ == 2 ? @_ : ( project_name(), @_ );
943  
944 0 my $changeset_exists = grep {m|^meta/$changeset|} get_meta_tags();
945 0 ▶ return [] unless $changeset_exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $changeset_exists 0 0 0
946  
947 0 my $events = view_blob("meta/$changeset");
948 0 for (@$events) {
949 0 my @lt = localtime $_->{stamp};
950 0 $_->{stamp} = strftime("%Y-%m-%d %T", @lt);
951 }
952  
953 0 ▶ return wantarray ? @$events : $events;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
954 }
955  
956  
957 0 ▶sub history_owner {
Subroutine history_owner: not called CC=1 SCAR=6.9
Pod documented
958 0 my $history = shift;
959 0 ▶ my $open = first { $_->{action} eq 'open' } @$history;
Subroutine __ANON__: not called CC=1 SCAR=6.9
960 0 return $open->{user};
961 }
962  
963  
964 0 ▶sub history_reviewer {
Subroutine history_reviewer: not called CC=2 SCAR=17.9
Pod documented
965 0 my $history = shift;
966 0 my $last;
967  
968 # the most recent person to whom the changeset was submitted
969 0 ▶ $last = first { $_->{action} eq 'submit' } reverse @$history;
Subroutine __ANON__: not called CC=1 SCAR=6.9
970 0 ▶ return if not $last;
Branch: 1 branch
BranchTrueFalseTotal
unless $last 0 0 0
971 0 return $last->{reviewer};
972 }
973  
974  
975 0 ▶sub history_status {
Subroutine history_status: not called CC=1 SCAR=6.9
Pod documented
976 0 my $history = shift;
977 my $last
978 0 ▶ = first { $_->{action} !~ m/^(touch|promote|demote)$/ } reverse @$history;
Subroutine __ANON__: not called CC=1 SCAR=6.9
979 0 my $action = $last->{action};
980 return {
981 open => 'open',
982 submit => 'submitted',
983 review => 'reviewing',
984 fail => 'failed',
985 pass => 'merged',
986 edit => 'open',
987 0 }->{$action};
988 }
989  
990  
991 0 ▶sub history_submitter {
Subroutine history_submitter: not called CC=2 SCAR=17.9
Pod documented
992 0 my ($history) = @_;
993 0 ▶ my $last = first { $_->{action} eq 'submit' } reverse @$history;
Subroutine __ANON__: not called CC=1 SCAR=6.9
994 0 ▶ return if not $last;
Branch: 1 branch
BranchTrueFalseTotal
unless $last 0 0 0
995 0 return $last->{user};
996 }
997  
998  
999 0 ▶sub is_auto_fetch {
Subroutine is_auto_fetch: not called CC=2 SCAR=17.9
Pod documented
1000 0 my $config = git_config();
1001 0 ▶ my $value = $config->{gitc}{fetch} || 'auto';
Condition0%0/2
$config->{'gitc'}{'fetch'} || 'auto'
l!l
00
MC/DC0%0/1
$config->{'gitc'}{'fetch'} || 'auto'
$config->{'gitc'}{'fetch'}
Truth table0%0/2
A
A= $config->{'gitc'}{'fetch'}
Aresult
11
00
1002 0 return $value eq 'auto';
1003 }
1004  
1005  
1006 0 ▶sub is_merge_commit {
Subroutine is_merge_commit: not called CC=2 SCAR=17.9
Pod documented
1007 0 my ($ref) = @_;
1008 0 my ($parents) = git "log -1 --no-color --pretty=format:%P $ref";
1009 0 ▶ return if not $parents; # the root commit is not a merge
Branch: 1 branch
BranchTrueFalseTotal
unless $parents 0 0 0
1010 0 my @parents = split / /, $parents;
1011 0 return @parents > 1;
1012 }
1013  
1014  
1015 0 ▶sub is_suspendable {
Subroutine is_suspendable: not called CC=2 SCAR=17.9
Pod documented
1016 0 our $suspend_file = '.git/gitc-suspended-process';
1017 0 ▶ open my $fh, '>', $suspend_file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $App::Gitc::Util::suspend_file or die "Unable to create $App::Gitc::Util::suspend_file: $!\n" 0 0 0
1018 or die "Unable to create $suspend_file: $!\n";
1019 0 print $fh "$$\n";
1020 0 my $command = command_name();
1021 0 print $fh "gitc $command is suspended. Resume it with 'fg'\n";
1022 0 our $is_suspendable = 1;
1023 0 close $fh;
1024 }
1025 1 ▶END {
Subroutine END: called CC=3 SCAR=12.5
1026 1 our $is_suspendable;
1027 1 our $suspend_file;
1028 1 ▶ unlink $suspend_file if $is_suspendable and -e $suspend_file;
Branch: 1 branch
BranchTrueFalseTotal
if $App::Gitc::Util::is_suspendable and -e $App::Gitc::Util::suspend_file 0 1 1
Condition33%1/3
$App::Gitc::Util::is_suspendable and -e $App::Gitc::Util::suspend_file
!ll&&!rl&&r
100
MC/DC0%0/2
$App::Gitc::Util::is_suspendable and -e $App::Gitc::Util::suspend_file
$App::Gitc::Util::is_suspendable -e $App::Gitc::Util::suspend_file
Truth table33%1/3
A and B
A= $App::Gitc::Util::is_suspendableB= -e $App::Gitc::Util::suspend_file
ABresult
0X0
100
111
1029 }
1030  
1031  
1032 0 ▶sub is_valid_ref {
Subroutine is_valid_ref: not called CC=3 SCAR=24.8
Pod documented
1033 0 my ($name) = @_;
1034 0 ▶ return if not defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
1035 0 my $sha1 = eval { git "rev-parse --verify --quiet $name" };
1036 0 ▶ return $sha1 if $sha1;
Branch: 1 branch
BranchTrueFalseTotal
if $sha1 0 0 0
1037 0 return;
1038 }
1039  
1040  
1041 0 ▶sub open_packed_refs {
Subroutine open_packed_refs: not called CC=6 SCAR=37.4
Pod documented
1042 0 my ($prefix) = @_;
1043 0 require File::Temp;
1044 0 ▶ if ( not defined $prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $prefix) 0 0 0
1045 0 require Carp;
1046 0 Carp::croak("open_packed_refs requires a prefix argument");
1047 }
1048 0 my $git_dir = git_dir();
1049 0 my $packed_refs = "$git_dir/packed-refs";
1050 0 ▶ return if not -e $packed_refs;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $packed_refs 0 0 0
1051 0 ▶ open my $old_fh, '<', $packed_refs or die "Can't open $packed_refs: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $old_fh, "<", $packed_refs or die "Can't open ${packed_refs}: $!" 0 0 0
1052  
1053 # verify that refs were packed with 'peeled'
1054 0 my $header = <$old_fh>;
1055 0 my ($technique) = $header =~ /^# pack-refs with: (\S+)/;
1056 0 ▶ $technique ||= '';
Condition0%0/2
$technique ||= ""
l!l
00
MC/DC0%0/1
$technique ||= ""
$technique
Truth table0%0/2
A
A= $technique
Aresult
11
00
1057 0 ▶ die "Unknown ref packing technique: $technique\n"
Branch: 1 branch
BranchTrueFalseTotal
if $technique ne "peeled" 0 0 0
1058 if $technique ne 'peeled';
1059  
1060 # open a temporary file to store the new tags
1061 0 my ( $new_fh, $new_filename )
1062 = File::Temp::tempfile( "$prefix-XXXX", DIR => $git_dir );
1063  
1064 0 print $new_fh $header;
1065 0 return ( $old_fh, $new_fh, $new_filename );
1066 }
1067  
1068  
1069 0 ▶sub parse_changeset_spec {
Subroutine parse_changeset_spec: not called CC=4 SCAR=30.0
Pod documented
1070 0 my ($spec) = @_;
1071  
1072 # no $spec means to infer everything from pwd
1073 0 ▶ if ( not defined $spec ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $spec) 0 0 0
1074 0 my $changeset = current_branch();
1075 0 my $project = project_name();
1076 0 return ( $project, $changeset );
1077 }
1078  
1079 # handle the traditional, full changeset name
1080 0 ▶ return ( $1, $2 ) if $spec =~ m/^(.*)#(.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $spec =~ /^(.*)#(.*)$/ 0 0 0
1081  
1082 0 my $project = project_name();
1083 0 ▶ die "Unable to determine the project for changeset spec '$spec'.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $project 0 0 0
1084 . "You either need to be inside a gitc repository or specify\n"
1085 . "the full changeset name like project#changeset\n"
1086 if not $project;
1087 0 return ( $project, $spec );
1088 }
1089  
1090  
1091 0 ▶sub project_name {
Subroutine project_name: not called CC=3 SCAR=24.8
Pod documented
1092 0 our $project_name;
1093 0 ▶ return $project_name if defined $project_name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $App::Gitc::Util::project_name 0 0 0
1094 0 my ($line) = git "show HEAD:.gitc";
1095 0 ▶ die "You need to specify a project name in a .gitc file. See the HOWTO for more details." unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
1096 0 my ($name) = $line =~ m/^\s*name\s*:\s*(.*)$/;
1097 0 return $project_name = $name;
1098 }
1099  
1100  
1101 0 ▶sub project_root {
Subroutine project_root: not called CC=2 SCAR=17.9
Pod documented
1102 0 my $git_dir = git_dir();
1103 0 ▶ if ( not $git_dir =~ s{/.git$}{} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($git_dir =~ s[/.git$][]) 0 0 0
1104 0 require Carp;
1105 0 Carp::croak("Bare repositories don't have a meaningful project root");
1106 }
1107 0 return $git_dir;
1108 }
1109  
1110  
1111 0 ▶sub remote_branch_exists {
Subroutine remote_branch_exists: not called CC=1 SCAR=6.9
Pod documented
1112 0 my ($branch) = @_;
1113 0 my @remote_branches = git "branch --no-color -r";
1114 0 return scalar grep { $_ eq " origin/$branch" } @remote_branches
1115 }
1116  
1117  
1118 0 ▶sub sendmail {
Subroutine sendmail: not called CC=12 SCAR=50.5
Pod documented
1119 0 my ($args) = @_;
1120 0 ▶ my $recipient = $args->{to} || die "No mail recipient";
Condition0%0/2
$args->{'to'} || die('No mail recipient')
l!l
00
MC/DC0%0/1
$args->{'to'} || die('No mail recipient')
$args->{'to'}
Truth table0%0/2
A
A= $args->{'to'}
Aresult
11
00
1121 0 ▶ my $subject = $args->{subject} || die "No mail subject";
Condition0%0/2
$args->{'subject'} || die('No mail subject')
l!l
00
MC/DC0%0/1
$args->{'subject'} || die('No mail subject')
$args->{'subject'}
Truth table0%0/2
A
A= $args->{'subject'}
Aresult
11
00
1122 0 ▶ my $content = $args->{content} || q{};
Condition0%0/2
$args->{'content'} || ''
l!l
00
MC/DC0%0/1
$args->{'content'} || ''
$args->{'content'}
Truth table0%0/2
A
A= $args->{'content'}
Aresult
11
00
1123 0 ▶ my $link = $args->{link} || q{};
Condition0%0/2
$args->{'link'} || ''
l!l
00
MC/DC0%0/1
$args->{'link'} || ''
$args->{'link'}
Truth table0%0/2
A
A= $args->{'link'}
Aresult
11
00
1124 0 ▶ my $project = $args->{project} || project_name();
Condition0%0/3
$args->{'project'} || project_name()
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'project'} || project_name()
$args->{'project'} project_name()
Truth table0%0/3
A || B
A= $args->{'project'}B= project_name()
ABresult
1X1
011
000
1125 0 ▶ my $changeset = $args->{changeset} || die "No mail changeset ID";
Condition0%0/2
$args->{'changeset'} || die('No mail changeset ID')
l!l
00
MC/DC0%0/1
$args->{'changeset'} || die('No mail changeset ID')
$args->{'changeset'}
Truth table0%0/2
A
A= $args->{'changeset'}
Aresult
11
00
1126  
1127 # determine a temporary file name template
1128 0 ▶ my $command = eval { command_name() } || 'unknown';
Condition0%0/2
eval { do { command_name() } } || 'unknown'
l!l
00
MC/DC0%0/1
eval { do { command_name() } } || 'unknown'
eval { do { command_name() } }
Truth table0%0/2
A
A= eval { do { command_name() } }
Aresult
11
00
1129  
1130 # CONFIGURE (optional)
1131 # Add any site specific custom headers here
1132 # TODO this should be pulled from a configuration file
1133 0 my $extra_headers = '';
1134  
1135 # create the email template
1136 0 require File::Temp;
1137 0 my ( $temp_fh, $temp_file )
1138 = File::Temp::tempfile( "gitc-$command-XXXX", UNLINK => 1 );
1139 0 my $name = get_user_name() . ' <' . get_user_email() . '>';
1140 0 print $temp_fh <<ENDMAIL;
1141 To: $recipient
1142 From: $name
1143 Subject: [$project#$changeset] $subject
1144 $extra_headers
1145  
1146 $link
1147  
1148 $content
1149 ENDMAIL
1150 0 ▶ close $temp_fh or die "Couldn't close temporary file for mail";
Branch: 1 branch
BranchTrueFalseTotal
close $temp_fh or die "Couldn't close temporary file for mail" 0 0 0
1151  
1152 0 ▶ let_user_edit($temp_file) if -t STDOUT;
Branch: 1 branch
BranchTrueFalseTotal
if -t STDOUT 0 0 0
1153 0 ▶ die "Aborting at user's request\n" if -s $temp_file <= 10;
Branch: 1 branch
BranchTrueFalseTotal
if -s $temp_file <= 10 0 0 0
1154  
1155 # delay sending the email if necessary
1156 0 my $sendmail = find_sendmail();
1157 0 ▶ my $send_it = sub { system qq($sendmail -t < $temp_file) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1158 0 ▶ return $send_it if $args->{lazy};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"lazy"} 0 0 0
1159 0 $send_it->();
1160 0 return;
1161 }
1162  
1163  
1164 0 ▶sub find_sendmail {
Subroutine find_sendmail: not called CC=7 SCAR=40.3
Pod documented
1165 # We could cache this, but there's not much point - no single run
1166 # of gitc ever calls this method more than once.
1167  
1168 # Yanked from MIME::Lite, slightly tweaked
1169 0 my $sendmail = '/usr/sbin/sendmail';
1170 0 ▶ ( -x $sendmail ) or ($sendmail = '/usr/lib/sendmail' );
Branch: 1 branch
BranchTrueFalseTotal
-x $sendmail or $sendmail = "/usr/lib/sendmail" 0 0 0
1171 0 ▶ ( -x $sendmail ) or ($sendmail = 'sendmail' );
Branch: 1 branch
BranchTrueFalseTotal
-x $sendmail or $sendmail = "sendmail" 0 0 0
1172 0 ▶ unless (-x $sendmail) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $sendmail) 0 0 0
1173 0 require File::Spec;
1174 0 for my $dir (File::Spec->path) {
1175 0 ▶ if ( -x "$dir/sendmail" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-x "$dir/sendmail") 0 0 0
1176 0 $sendmail = "$dir/sendmail";
1177 0 last;
1178 }
1179 }
1180 }
1181 0 ▶ unless (-x $sendmail) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $sendmail) 0 0 0
1182 0 die "Couldn't find an executable sendmail";
1183 }
1184 0 return $sendmail;
1185 }
1186  
1187  
1188 0 ▶sub short_ref_name {
Subroutine short_ref_name: not called CC=4 SCAR=30.0
Pod documented
1189 0 my ($ref) = @_;
1190 0 ▶ return if not defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 0 0 0
1191  
1192 0 my $name = qr{[^/]+}o; # a name is anything except slashes
1193 0 my @patterns = (
1194 qr{cs/($name)/head}o, # merged changeset
1195 qr{origin/pu/($name)}o, # pending review
1196 qr{^($name)$}o, # already a short name
1197 );
1198 0 for my $pattern (@patterns) {
1199 0 ▶ return $1 if $ref =~ $pattern;
Branch: 1 branch
BranchTrueFalseTotal
if $ref =~ /$pattern/ 0 0 0
1200 }
1201  
1202 # we don't know how to shorten this kind of ref
1203 0 return;
1204 }
1205  
1206  
1207 2 ▶sub sort_changesets_by_name {
Subroutine sort_changesets_by_name: called CC=4 SCAR=13.9
Pod documented
1208 2 my ($ids) = @_;
1209 @$ids =
1210 13 map { $_->[0] }
1211 sort {
1212 22 ▶ $a->[1] cmp $b->[1]
Condition83%5/6
$App::Gitc::Util::a->[1] cmp $App::Gitc::Util::b->[1] || $App::Gitc::Util::a->[2] <=> $App::Gitc::Util::b->[2] || $App::Gitc::Util::a->[3] cmp $App::Gitc::Util::b->[3]
l!l&&r!l&&!r
1660
$App::Gitc::Util::a->[1] cmp $App::Gitc::Util::b->[1] or $App::Gitc::Util::a->[2] <=> $App::Gitc::Util::b->[2]
l!l&&r!l&&!r
796
MC/DC0%0/3
$App::Gitc::Util::a->[1] cmp $App::Gitc::Util::b->[1] || $App::Gitc::Util::a->[2] <=> $App::Gitc::Util::b->[2] || $App::Gitc::Util::a->[3] cmp $App::Gitc::Util::b->[3]
$App::Gitc::Util::a->[1] cmp $App::Gitc::Util::b->[1] $App::Gitc::Util::a->[2] <=> $App::Gitc::Util::b->[2] $App::Gitc::Util::a->[3] cmp $App::Gitc::Util::b->[3]
Truth table75%3/4
A or B || C
A= $App::Gitc::Util::a->[1] cmp $App::Gitc::Util::b->[1]B= $App::Gitc::Util::a->[2] <=> $App::Gitc::Util::b->[2]C= $App::Gitc::Util::a->[3] cmp $App::Gitc::Util::b->[3]
ABCresult
1XX1
01X1
0011
0000
1213 or
1214 $a->[2] <=> $b->[2]
1215 or
1216 $a->[3] cmp $b->[3]
1217 }
1218 map {
1219 2 ▶ m/^(\D+)(\d+)(\D*)$/ ? [ $_, $1, $2, $3 ]
Branch: 1 branch
BranchTrueFalseTotal
/^(\D+)(\d+)(\D*)$/ ? : 11 2 13
1220 : [ $_, $_, 999_999, '' ]
1221 } @$ids;
1222  
1223 2 return;
1224 }
1225  
1226  
1227 0 ▶sub split_decorations {
Subroutine split_decorations: not called CC=3 SCAR=24.8
Pod documented
1228 0 my ($decorations) = @_;
1229 0 ▶ return if not defined $decorations;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $decorations 0 0 0
1230 0 ▶ return if length($decorations) < 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $decorations < 4 0 0 0
1231 0 $decorations = substr $decorations, 2, -1; # remove " (" and ")"
1232 0 return split /, /, $decorations;
1233 }
1234  
1235  
1236 0 ▶sub toplevel {
Subroutine toplevel: not called CC=2 SCAR=17.9
Pod documented
1237 0 chomp( my $top = qx{git rev-parse --show-toplevel} );
1238  
1239 0 ▶ unless ( $top ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($top) 0 0 0
1240 0 die 'Not a git repository (or any of the parent directories): .git';
1241 }
1242  
1243 0 return $top;
1244 }
1245  
1246  
1247 # call a coderef for each commit in a "git log" invocation
1248 0 ▶sub traverse_commits {
Subroutine traverse_commits: not called CC=11 SCAR=48.8
Pod documented
1249 0 my ( $git_log_arguments, $callback ) = @_;
1250  
1251 0 ▶ open my $git, '-|', "git log --no-color --pretty=raw $git_log_arguments" or die;
Branch: 1 branch
BranchTrueFalseTotal
open my $git, "-|", "git log --no-color --pretty=raw $git_log_arguments" or die 0 0 0
1252  
1253 0 my @commit_lines;
1254 my @accumulator;
1255 0 my $finished = 0;
1256 COMMIT:
1257 0 ▶ while ( not $finished ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($finished) 0 0 0
1258  
1259 # collect all information about one commit
1260 0 while (1) {
1261 0 my $line = <$git>;
1262 0 ▶ if ( not defined $line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 0 0 0
1263 0 @commit_lines = @accumulator;
1264 0 @accumulator = ();
1265 0 $finished = 1;
1266 0 last;
1267 }
1268 0 chomp $line;
1269 0 ▶ if ( @accumulator and $line =~ m/^commit / ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@accumulator and $line =~ /^commit /) 0 0 0
Condition0%0/3
@accumulator and $line =~ /^commit /
!ll&&!rl&&r
000
MC/DC0%0/2
@accumulator and $line =~ /^commit /
@accumulator $line =~ /^commit /
Truth table0%0/3
A and B
A= @accumulatorB= $line =~ /^commit /
ABresult
0X0
100
111
1270 0 @commit_lines = @accumulator;
1271 0 @accumulator = ($line);
1272 0 last;
1273 }
1274 0 push @accumulator, $line;
1275 }
1276 0 ▶ last if not @commit_lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @commit_lines 0 0 0
1277  
1278 # extract commit ID and parentage
1279 0 my ($commit) = $commit_lines[0] =~ /^commit (\S+)/;
1280 0 ▶ my @parents = map { /^parent (.*)$/ ? $1 : () } @commit_lines[2,3];
Branch: 1 branch
BranchTrueFalseTotal
/^parent (.*)$/ ? : 0 0 0
1281 0 ▶ die "Unable to locate commit" if not $commit;
Branch: 1 branch
BranchTrueFalseTotal
unless $commit 0 0 0
1282 0 ▶ die "Unable to locate parents" if not @parents and not $finished;
Branch: 1 branch
BranchTrueFalseTotal
unless @parents or $finished 0 0 0
Condition0%0/3
@parents or $finished
l!l&&r!l&&!r
000
MC/DC0%0/2
@parents or $finished
@parents $finished
Truth table0%0/3
A or B
A= @parentsB= $finished
ABresult
1X1
011
000
1283  
1284 # call the coderef
1285 0 $callback->({
1286 commit => $commit,
1287 parents => \@parents,
1288 message => [ @commit_lines[ 6 .. $#commit_lines ] ],
1289 });
1290 }
1291  
1292 0 return;
1293 }
1294  
1295  
1296  
1297 0 ▶sub unmerged_changesets {
Subroutine unmerged_changesets: not called CC=6 SCAR=37.4
Pod documented
1298 0 my ($project_name) = @_;
1299  
1300 0 my @meta_tags = get_meta_tags();
1301 0 my @unmerged;
1302 0 for my $tag (@meta_tags) {
1303 0 my $meta_info = view_blob($tag);
1304 0 my $passed;
1305 0 for my $entry (@$meta_info) {
1306 0 ▶ ++$passed if $entry->{action} eq 'pass';
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"action"} eq "pass" 0 0 0
1307 }
1308 0 ▶ push @unmerged, @$meta_info unless $passed;
Branch: 1 branch
BranchTrueFalseTotal
unless $passed 0 0 0
1309 }
1310  
1311 0 my %result;
1312 0 for my $event (sort {$a->{stamp} <=> $b->{stamp}} @unmerged) {
1313 0 my @lt = localtime $event->{stamp};
1314 0 $event->{stamp} = strftime("%Y-%m-%d %T", @lt);
1315 0 push @{ $result{ $event->{changeset} } }, $event;
1316 }
1317  
1318 0 return \%result;
1319 }
1320  
1321  
1322 0 ▶sub unpromoted {
Subroutine unpromoted: not called CC=3 SCAR=24.8
Pod documented
1323 0 my ($from, $to) = @_;
1324 0 ▶ $from = [ $from ] if not ref $from;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $from 0 0 0
1325 0 ▶ $to = [ $to ] if not ref $to;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $to 0 0 0
1326  
1327 0 my $backstop = backstop_commit( $from, $to );
1328  
1329 0 my @source_changes = changesets_in( $from, $backstop );
1330 0 my @target_changes = changesets_in( $to, $backstop );
1331 0 return _missing_changesets( \@source_changes, \@target_changes );
1332 }
1333  
1334 1 our $meta_cache;
1335  
1336 0 ▶sub cache_meta_data {
Subroutine cache_meta_data: not called CC=3 SCAR=24.8
Pod undocumented
1337 0 my (@refs) = @_;
1338 0 ▶ @refs = get_meta_tags(fetch => 0) unless @refs;
Branch: 1 branch
BranchTrueFalseTotal
unless @refs 0 0 0
1339 0 ▶ @refs = map {m|^meta/| ? $_ : "meta/$_"} @refs;
Branch: 1 branch
BranchTrueFalseTotal
m[^meta/] ? : 0 0 0
1340  
1341 0 push @$meta_cache, map { {$_ => git "rev-parse $_"} } @refs;
1342  
1343 0 return;
1344 }
1345  
1346 0 ▶sub restore_meta_data {
Subroutine restore_meta_data: not called CC=4 SCAR=30.0
Pod undocumented
1347 0 our $meta_cache;
1348 0 ▶ die "You cannot restore meta data without caching any data" unless $meta_cache;
Branch: 1 branch
BranchTrueFalseTotal
unless $App::Gitc::Util::meta_cache 0 0 0
1349  
1350 0 git_tag('-d', $_) for map {keys %$_} @$meta_cache;
1351 0 git_tag(%$_) for @$meta_cache;
1352 0 git sprintf "push --force origin %s", join ' ', map {keys %$_} @$meta_cache;
1353  
1354 0 undef $meta_cache;
1355 0 return;
1356 }
1357  
1358 0 ▶sub version_tag_prefix {
Subroutine version_tag_prefix: not called CC=1 SCAR=6.9
Pod undocumented
1359 0 my ($branch) = @_;
1360  
1361 0 return "version/$branch/";
1362 }
1363  
1364 # find a commit shared by @$from and @$to beyond which changesets_in
1365 # need not traverse. This is strictly an optimization to try and make
1366 # changesets_in() faster for large repositories
1367 0 ▶sub backstop_commit {
Subroutine backstop_commit: not called CC=1 SCAR=6.9
Pod undocumented
1368 0 return is_valid_ref('cvs');
1369 }
1370  
1371 # returns a list of the changesets that are reachable from a list
1372 # of commits. In the resulting list, child commits come before their
1373 # parents.
1374 # Takes an optional commit ID ($backstop) beyond which it need not search.
1375 0 ▶sub changesets_in {
Subroutine changesets_in: not called CC=10 SCAR=47.0
Pod undocumented
1376 0 my ($commits, $backstop) = @_;
1377  
1378 # view all commits in $from that are not in $to
1379 0 my @command = qw( git log --no-color --first-parent --topo-order --pretty=format:%H );
1380 0 ▶ push @command, " ^$backstop" if $backstop;
Branch: 1 branch
BranchTrueFalseTotal
if $backstop 0 0 0
1381 0 ▶ open my $log, "-|", @command, @$commits or die;
Branch: 1 branch
BranchTrueFalseTotal
open my $log, "-|", @command, @$commits or die 0 0 0
1382  
1383 # extract the implied changesets (based on their merge points)
1384 0 my $env = qr/(?:master|test|stage|prod)/;
1385 0 my $cs = qr{[^/]+};
1386 0 my @rxen = (
1387 # promoted changeset
1388 qr{^refs/tags/cs/($cs)/to-$env$}o,
1389 qr{^refs/tags/cs/($cs)/head$}o, # merged changeset
1390 qr{^refs/remotes/origin/pu/(.+)$}o, # pending review
1391 );
1392 0 my @included;
1393 my %seen;
1394 0 ▶ while ( my $commit = <$log> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $commit = readline $log)) 0 0 0
1395 0 chomp $commit;
1396 0 for my $name ( commit_decorations($commit) ) {
1397 0 for my $rx (@rxen) {
1398 0 ▶ if ( $name =~ $rx ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /$rx/) { } 0 0 0
elsif ($name =~ m[^refs/tags/cs/($cs)/rm-$env$]o) { } 0 0 0
1399 0 my $changeset = $1;
1400 0 ▶ next if $seen{$changeset}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$changeset}++ 0 0 0
1401 0 push @included, $changeset;
1402 }
1403 elsif ( $name =~ m{^refs/tags/cs/($cs)/rm-$env$}o ) {
1404 0 my $changeset = $1;
1405 0 ▶ next if $seen{$changeset}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$changeset}++ 0 0 0
1406 }
1407 }
1408 }
1409 }
1410  
1411 0 return @included;
1412 }
1413  
1414 # returns a list of changesets that are present in $source_changes but
1415 # missing from $target_changes
1416 0 ▶sub _missing_changesets {
Subroutine _missing_changesets: not called CC=1 SCAR=6.9
1417 0 my ($source_changes, $target_changes) = @_;
1418  
1419 0 my %source = map { $_ => 1 } @$source_changes;
1420 0 my %target = map { $_ => 1 } @$target_changes;
1421 0 delete @source{ keys %target };
1422  
1423 # maintain the same changeset order
1424 0 return grep { $source{$_} } @$source_changes;
1425 }
1426  
1427  
1428  
1429 0 ▶sub command_name {
Subroutine command_name: not called CC=2 SCAR=17.9
Pod documented
1430 0 my ($command) = $0 =~ m{/gitc-(\w+)$};
1431 0 ▶ return $command if $command;
Branch: 1 branch
BranchTrueFalseTotal
if $command 0 0 0
1432 0 die "Unable to determine the command name from $0\n";
1433 }
1434  
1435  
1436 0 ▶sub _states {
Subroutine _states: not called CC=7 SCAR=40.3
1437 0 my ( $self, $command, $target ) = @_;
1438  
1439 0 ▶ my $statuses = its_config()->{ $command }
Branch: 1 branch
BranchTrueFalseTotal
my $statuses = its_config()->{$command} or die 'No ' . its()->label_service . " statuses for $command" 0 0 0
1440 or die 'No ' . its->label_service . " statuses for $command";
1441  
1442 # handle the common case
1443 0 ▶ if ( not $target ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target) 0 0 0
1444 0 ▶ die "No initial status" unless $statuses->{from};
Branch: 1 branch
BranchTrueFalseTotal
unless $statuses->{"from"} 0 0 0
1445 0 ▶ die "No final status" unless $statuses->{to};
Branch: 1 branch
BranchTrueFalseTotal
unless $statuses->{"to"} 0 0 0
1446 0 return ( $statuses );
1447 }
1448  
1449 # promotions need another level of dereference
1450 0 ▶ die "No initial status for target $target" unless $statuses->{$target}{from};
Branch: 1 branch
BranchTrueFalseTotal
unless $statuses->{$target}{"from"} 0 0 0
1451 0 ▶ die "No final status for target $target" unless $statuses->{$target}{to};
Branch: 1 branch
BranchTrueFalseTotal
unless $statuses->{$target}{"to"} 0 0 0
1452  
1453 0 return $statuses->{$target};
1454 }
1455  
1456  
1457 0 ▶sub state_blocked {
Subroutine state_blocked: not called CC=4 SCAR=30.0
Pod documented
1458 0 my ( $command, $state ) = @_;
1459  
1460 0 ▶ my $statuses = its_config()->{ $command }
Branch: 1 branch
BranchTrueFalseTotal
my $statuses = its_config()->{$command} or die 'No ' . its()->label_service . " statuses for $command" 0 0 0
1461 or die 'No ' . its()->label_service . " statuses for $command";
1462  
1463 # promotions need another level of dereference
1464 0 my $block = $statuses->{ block };
1465  
1466 0 ▶ return unless $block;
Branch: 1 branch
BranchTrueFalseTotal
unless $block 0 0 0
1467  
1468 0 ▶ return 1 if any { warn " \$_: $_, \$state: $state.\n";$_ eq $state } @{$block};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { warn " \$_: $_, \$state: $state.\n"; $_ eq $state; } , @{$block;}) 0 0 0
1469
1470 0 return;
1471 }
1472  
1473 1 1;
1474  
1475 __END__
↑ Summary Its/Eventum.pm »