| 1 | package Minilla::Git; | ||||||||||||||||||||||||||||
| 2 | 71 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 71 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 71 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 71 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 71 | our @EXPORT = qw(git_ls_files git_file_modes git_init git_add git_rm git_commit git_config git_remote git_submodules git_submodule_files git_show_toplevel); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 71 | ▶ | use Minilla::Logger qw(errorf); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 71 | ▶ | use Minilla::Util qw(cmd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub git_init { | ||||||||||||||||||||||||||
|
Subroutine
git_init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 0 | cmd('git', 'init'); | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub git_add { | ||||||||||||||||||||||||||
|
Subroutine
git_add: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | cmd('git', 'add', @_ ? @_ : '.'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub git_config { | ||||||||||||||||||||||||||
|
Subroutine
git_config: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | cmd('git', 'config', @_ ? @_ : '.'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub git_rm { | ||||||||||||||||||||||||||
|
Subroutine
git_rm: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 0 | cmd('git', 'rm', @_); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub git_commit { | ||||||||||||||||||||||||||
|
Subroutine
git_commit: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | cmd('git', 'commit', @_); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub git_remote { | ||||||||||||||||||||||||||
|
Subroutine
git_remote: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 0 | cmd('git', 'remote', @_); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub git_ls_files { | ||||||||||||||||||||||||||
|
Subroutine
git_ls_files: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 0 | my @files = split /\0/, `git ls-files -z`; | |||||||||||||||||||||||||||
| 39 | 0 | return @files; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub git_file_modes { | ||||||||||||||||||||||||||
|
Subroutine
git_file_modes: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | open my $fh, '-|', 'git', 'ls-files', '--stage', '--recurse-submodules', '-z' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | or die "Cannot read Git index: $!\n"; | ||||||||||||||||||||||||||||
| 45 | 0 | local $/ = "\0"; | |||||||||||||||||||||||||||
| 46 | 0 | my %modes; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | while (my $entry = <$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $entry =~ s/\0\z//; | |||||||||||||||||||||||||||
| 49 | 0 | my ($mode, $stage, $path) = $entry =~ /\A([0-9]+) [0-9a-f]+ ([0-3])\t(.*)\z/s; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | next unless defined $path && $stage == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $path and $stage == 0
MC/DC0%0/2
defined $path and $stage == 0
defined $path
$stage == 0
Truth table0%0/3
A and B
A= defined $pathB= $stage == 0
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $path =~ s!\\!/!g if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $modes{$path} = $mode eq '100755' ? 0755 : 0644; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | close $fh or die "Cannot read Git index\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | return \%modes; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub git_submodules { | ||||||||||||||||||||||||||
|
Subroutine
git_submodules: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 0 | my @submodules = split /\n/, `git submodule status --recursive`; | |||||||||||||||||||||||||||
| 60 | 0 | my @files; | |||||||||||||||||||||||||||
| 61 | 0 | for (@submodules) { | |||||||||||||||||||||||||||
| 62 | 0 | my ($path) = $_ =~ /^[+\-U\x20][0-9a-f]{40}\x20([^\x20]+).*$/; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | push @files, $path if $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | return @files; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub git_submodule_files { | ||||||||||||||||||||||||||
|
Subroutine
git_submodule_files: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | # XXX: `git ls-files -z` does *NOT* print new line in last. | ||||||||||||||||||||||||||||
| 70 | # So it breaks format when multiple submodules contains and combined with `git submodule foreach`. (and failed to parse.) | ||||||||||||||||||||||||||||
| 71 | 0 | my @output = split /\n/, `git submodule foreach --recursive "git ls-files -z"`; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | for (my $i = 1; $i <= @output-2; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $output[$i] =~ s/\0([^\0]*)$//; | |||||||||||||||||||||||||||
| 74 | 0 | splice @output, $i+1, 0, $1; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my @files; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | while (@output) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | my $submodule_line = shift @output; | |||||||||||||||||||||||||||
| 80 | 0 | my ($submodule_name) = $submodule_line =~ /'(.+)'/; | |||||||||||||||||||||||||||
| 81 | 0 | push @files, map "$submodule_name/$_", split /\0/, shift @output; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 0 | return @files; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub git_show_toplevel { | ||||||||||||||||||||||||||
|
Subroutine
git_show_toplevel: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 0 | my $top_level = `git rev-parse --show-toplevel`; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | errorf("Top-level git directory could not be found for %s: %s\n", Cwd::getcwd(), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 90 | $? == -1 ? "$!" : | ||||||||||||||||||||||||||||
| 91 | $? & 127 ? "git received signal ". ($? & 127) : "git exited ". ($? >> 8)) | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 0 | chomp $top_level; | |||||||||||||||||||||||||||
| 94 | 0 | return $top_level; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 71 | 1; | |||||||||||||||||||||||||||