| 1 | package Code::TidyAll::Git::Util; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use File::pushd qw(pushd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use IPC::System::Simple qw(capturex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use List::SomeUtils qw(uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Path::Tiny qw(path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '0.83'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | our @EXPORT_OK = qw(git_files_to_commit git_modified_files); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub git_files_to_commit { | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my ($dir) = @_; | ||||||||||||||||||||||||||
|
Subroutine
git_files_to_commit: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | return _relevant_files_from_status( $dir, 1 ); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub git_modified_files { | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my ($dir) = @_; | ||||||||||||||||||||||||||
|
Subroutine
git_modified_files: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | return _relevant_files_from_status( $dir, 0 ); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub _relevant_files_from_status { | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my ( $dir, $index_only ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_relevant_files_from_status: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | $dir = path($dir); | |||||||||||||||||||||||||||
| 31 | 0 | my $pushed = pushd( $dir->absolute ); | |||||||||||||||||||||||||||
| 32 | 0 | my $status = capturex(qw( git status --porcelain -z -uno )); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return unless $status; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | return map { $dir->child($_) } _parse_status( $status, $index_only ); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub _parse_status { | ||||||||||||||||||||||||||||
| 40 | 1 | ▶ | my ( $status, $index_only ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_status: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | local $_ = $status; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # There can't possibly be more records than nuls plus one, so we use this | ||||||||||||||||||||||||||||
| 45 | # as an upper bound on passes. | ||||||||||||||||||||||||||||
| 46 | 1 | my $times = tr/\0/\0/; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | my @files; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | for my $i ( 0 .. $times ) { | |||||||||||||||||||||||||||
| 51 | 7 | ▶ | last if /\G\Z/gc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 6 | /\G(..) /g; | |||||||||||||||||||||||||||
| 54 | 6 | my $mode = $1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 6 | /\G([^\0]+)\0/g; | |||||||||||||||||||||||||||
| 57 | 6 | my $name = $1; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # on renames, parse but throw away the "renamed from" filename | ||||||||||||||||||||||||||||
| 60 | 6 | ▶ | if ( $mode =~ /[CR]/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 2 | /\G([^\0]+)\0/g; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # deletions and renames don't cause tidying | ||||||||||||||||||||||||||||
| 65 | 6 | ▶ | next unless $mode =~ /[MA]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 3 | ▶ | next if $index_only && $mode =~ /^ /; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index_only and $mode =~ /^ /
MC/DC0%0/2
$index_only and $mode =~ /^ /
$index_only
$mode =~ /^ /
Truth table33%1/3
A and B
A= $index_onlyB= $mode =~ /^ /
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 3 | push @files, $name; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | return @files; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # ABSTRACT: Utilities for the git hook classes | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =pod | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 NAME | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | Code::TidyAll::Git::Util - Utilities for the git hook classes | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head1 VERSION | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | version 0.83 | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 SOURCE | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =over 4 | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =item * | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Jonathan Swartz <swartz@pobox.com> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =item * | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Dave Rolsky <autarch@urth.org> | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =back | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | This software is copyright (c) 2011 - 2022 by Jonathan Swartz. | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 119 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 122 | F<LICENSE> file included with this distribution. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||