| 1 | package Skilletor::Source::Git; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A git source: shallow fetch into the shared cache, refs, SHA pins, offline reuse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 234 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 234 | ▶ | use Path::Tiny qw( path ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 234 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 234 | ▶ | use Skilletor::Cache qw( git_cache_dir CACHE_NAME_RE ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 234 | ▶ | use Skilletor::Error::CacheRejected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 234 | ▶ | use Skilletor::Error::Source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 234 | ▶ | use Skilletor::FSUtil qw( decode_utf8_lossy path_join path_resolve ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 234 | ▶ | use Skilletor::GitEnv qw( git_env ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 234 | ▶ | use Skilletor::JSString qw( js_lc js_trim ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 234 | ▶ | use Skilletor::Process qw( run_command ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 234 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 234 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 234 | with 'Skilletor::Role::Source'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 234 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Git for Windows checks out with core.autocrlf=true; the cache holds the repository's bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # there as everywhere, and longpaths lifts the 260-character limit. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 234 | ▶ | my @CHECKOUT_AS_IS = $^O eq 'MSWin32' ? ( '-c', 'core.autocrlf=false', '-c', 'core.eol=lf', '-c', 'core.longpaths=true' ) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # The fetch refspec `git remote add` gives origin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 234 | my $ORIGIN_REFSPEC = '+refs/heads/*:refs/remotes/origin/*'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # git's order for a short ref name (ref_rev_parse_rules): the ref `git fetch` takes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my @REF_RULES = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1199 | ▶ | sub { $_[0] }, sub { 'refs/'.$_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 461 | ▶ | sub { 'refs/tags/'.$_[0] }, sub { 'refs/heads/'.$_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 123 | ▶ | sub { 'refs/remotes/'.$_[0] }, sub { 'refs/remotes/'.$_[0].'/HEAD' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 234 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # The lock files, relative to .git, that git takes for what resolve runs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 234 | my @LOCK_FILES = ( 'index.lock', 'shallow.lock', 'config.lock', 'HEAD.lock', 'ORIG_HEAD.lock', 'packed-refs.lock', 'reftable/tables.list.lock' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # How old a lock file must be to count as a dead git's: the sync lock's stale age. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 234 | my $STALE_LOCK_SECONDS = 5 * 60; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 234 | has url => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 234 | has ref => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 234 | has cache_root => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | has timeout_ms => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3048 | ▶ | default => sub { 60_000 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 234 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3898 | ▶ | sub cache_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3898 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3898 | return git_cache_dir( $self->cache_root, $self->url, $self->ref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3727 | ▶ | sub is_commitish { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_commitish: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3727 | my ( $self, $ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3727 | ▶ | return ( defined $ref && $ref =~ /\A[0-9a-f]{7,40}\z/i ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ref and $ref =~ /\A[0-9a-f]{7,40}\z/i
MC/DC50%1/2
defined $ref and $ref =~ /\A[0-9a-f]{7,40}\z/i
defined $ref
$ref =~ /\A[0-9a-f]{7,40}\z/i
Truth table66%2/3
A and B
A= defined $refB= $ref =~ /\A[0-9a-f]{7,40}\z/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 7620 | ▶ | sub _pinned { my ( $self ) = @_; my $ref = $self->ref; return ( defined $ref && length $ref && $self->is_commitish($ref) ) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pinned: called CC=4 SCAR=13.9
Branch: 1 branch
Condition83%5/6
defined $ref and length $ref and $self->is_commitish($ref)
defined $ref and length $ref
MC/DC66%2/3
defined $ref and length $ref and $self->is_commitish($ref)
defined $ref
length $ref
$self->is_commitish($ref)
Truth table75%3/4
A and B and C
A= defined $refB= length $refC= $self->is_commitish($ref)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # One git run: no shell, the repository-local variables dropped, never a repository above the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # cache. Fails with git's stderr – or Node's "Command failed: …" when git wrote none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 20398 | ▶ | sub _run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: called CC=13 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 20398 | my ( $self, $cwd, $args, $timeout_ms, $env ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 20398 | my @cmd = ( 'git', @CHECKOUT_AS_IS, @$args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 20398 | ▶ | my %extra = ( ( length( $cwd // '' ) ? ( GIT_CEILING_DIRECTORIES => path_resolve( $cwd, '..' ) ) : () ), %{ $env // {} } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$cwd // ""
$env // {}
MC/DC0%0/1
$cwd // ""
$cwd
MC/DC100%1/1
$env // {}
$env
Truth table50%1/2
A
A= $cwd
Truth table100%2/2
A
A= $env
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 20398 | ▶ | my $r = run_command( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$cwd // ""
$timeout_ms // $self->timeout_ms
MC/DC0%0/1
$cwd // ""
$cwd
MC/DC0%0/2
$timeout_ms // $self->timeout_ms
$timeout_ms
$self->timeout_ms
Truth table50%1/2
A
A= $cwd
Truth table66%2/3
A // B
A= $timeout_msB= $self->timeout_ms
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | cmd => \@cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | cwd => ( length( $cwd // '' ) ? $cwd : undef ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | env => git_env(%extra), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | timeout_ms => $timeout_ms // $self->timeout_ms, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 20176 | my $what = 'git '.join( ' ', @$args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 20176 | ▶ | if ( my $spawn = $r->{spawn_error} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | Skilletor::Error::Source->throw( $what.': spawn git '.( $spawn->{errno} == 2 ? 'ENOENT' : $spawn->{message} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 20176 | ▶ | if ( $r->{timed_out} || !defined $r->{code} || $r->{code} != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$r->{"timed_out"} or not defined $r->{"code"} or $r->{"code"} != 0
$r->{"timed_out"} or not defined $r->{"code"}
MC/DC33%1/3
$r->{"timed_out"} or not defined $r->{"code"} or $r->{"code"} != 0
$r->{"timed_out"}
not defined $r->{"code"}
$r->{"code"} != 0
Truth table50%2/4
A or not(B) or C
A= $r->{"timed_out"}B= not defined $r->{"code"}C= $r->{"code"} != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2161 | my $stderr = js_trim( decode_utf8_lossy( $r->{stderr} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2161 | ▶ | Skilletor::Error::Source->throw( $what.': '.( length $stderr ? $stderr : 'Command failed: '.join( ' ', @cmd ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 18015 | return decode_utf8_lossy( $r->{stdout} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3357 | ▶ | sub _ok { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ok: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3357 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 3357 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 3357 | ▶ | return eval { $out = $self->_run(@args); 1 } ? ( 1, $out ) : ( 0, $@ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 938 | ▶ | sub _msg { my ( $err ) = @_; return blessed $err && $err->can('message') ? $err->message : js_trim("$err") } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_msg: called CC=3 SCAR=13.1
Branch: 1 branch
Condition33%1/3
builtin::blessed($err) and $err->can("message")
MC/DC0%0/2
builtin::blessed($err) and $err->can("message")
builtin::blessed($err)
$err->can("message")
Truth table33%1/3
A and B
A= builtin::blessed($err)B= $err->can("message")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4288 | ▶ | sub _is_repo { -e path_join( $_[1], '.git' ) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_repo: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3232 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3232 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3232 | my $dir = $self->cache_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3232 | my $ref = $self->ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3232 | my $result = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3232 | ▶ | if ( !$self->_is_repo($dir) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2382 | path($dir)->mkpath; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2382 | $self->_run( $dir, [ 'init', '-q' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2360 | $self->_run( $dir, [ 'remote', 'add', '--', 'origin', $self->url ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 850 | $self->_repair($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3172 | my $reset_target = 'FETCH_HEAD'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3172 | ▶ | if ( $self->_pinned ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1049 | my ($fetched) = $self->_ok( $dir, [ 'fetch', '--depth', '1', '--', 'origin', $ref ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1040 | ▶ | unless ($fetched) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 455 | $self->_run( $dir, [ 'fetch', 'origin' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 122 | $reset_target = $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2123 | ▶ | $self->_run( $dir, [ 'fetch', '--depth', '1', '--', 'origin', ( defined $ref ? $ref : 'HEAD' ) ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2196 | $self->_run( $dir, [ 'reset', '--hard', $reset_target ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # reset --hard leaves every file its index does not track. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2173 | $self->_run( $dir, [ 'clean', '-ffdxq' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2150 | +{ dir => $dir, version => $self->_version($dir) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 3053 | ▶ | return $result if $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 938 | my $err = _msg($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 938 | ▶ | if ( $self->_is_repo($dir) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 938 | my $served = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 938 | my $version = $self->_version($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 401 | $self->_restore($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 393 | +{ dir => $dir, version => $version, warning => 'git fetch failed for '.$self->url.', using cache ('.$err.')' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 914 | ▶ | return $served if $served; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 521 | my $cache_error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # A repo without a commit is no cache; only a refused pin or checkout is worth naming. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 521 | ▶ | if ( blessed $cache_error && $cache_error->isa('Skilletor::Error::CacheRejected') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($cache_error) and $cache_error->isa("Skilletor::Error::CacheRejected")
MC/DC50%1/2
builtin::blessed($cache_error) and $cache_error->isa("Skilletor::Error::CacheRejected")
builtin::blessed($cache_error)
$cache_error->isa("Skilletor::Error::CacheRejected")
Truth table66%2/3
A and B
A= builtin::blessed($cache_error)B= $cache_error->isa("Skilletor::Error::CacheRejected")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 104 | Skilletor::Error::Source->throw( 'git source '.$self->url.' failed: '.$err.'; cache rejected ('.$cache_error->message.')' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 417 | Skilletor::Error::Source->throw( 'git source '.$self->url.' failed: '.$err ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # The cache as it is, without the network: what resolve serves when a fetch fails, without the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # warning – the checkout brought back to its HEAD, a pin checked against it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 118 | ▶ | sub cached { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cached: called CC=5 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 118 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 118 | my $dir = $self->cache_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 118 | ▶ | Skilletor::Error::Source->throw( 'git source '.$self->url.' is not in the cache (no fetch)' ) unless $self->_is_repo($dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 46 | my $served = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 46 | my $version = $self->_version($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 42 | $self->_restore($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 38 | +{ dir => $dir, version => $version }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 38 | ▶ | return $served if $served; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ( blessed $err && $err->isa('Skilletor::Error::CacheRejected') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($err) and $err->isa("Skilletor::Error::CacheRejected")
MC/DC0%0/2
builtin::blessed($err) and $err->isa("Skilletor::Error::CacheRejected")
builtin::blessed($err)
$err->isa("Skilletor::Error::CacheRejected")
Truth table0%0/3
A and B
A= builtin::blessed($err)B= $err->isa("Skilletor::Error::CacheRejected")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | Skilletor::Error::Source->throw( 'git source '.$self->url.': cache rejected ('.$err->message.')' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | Skilletor::Error::Source->throw( 'git source '.$self->url.' is not in the cache (no fetch; '._msg($err).')' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # Make a cache a killed run left half-made fit to fetch into, keeping what it holds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 850 | ▶ | sub _repair { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_repair: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 850 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 850 | my ( $ok, $out ) = $self->_ok( $dir, [ 'config', '--local', '-z', '--get-regexp', '^remote\\.origin\\.(url|fetch)$' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 838 | ▶ | my %origin = $ok ? %{ $self->_config_entries($out) } : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 838 | ▶ | unless ( exists $origin{'remote.origin.url'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 29 | $self->_run( $dir, [ 'init', '-q' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 28 | $self->_run( $dir, [ 'remote', 'add', '--', 'origin', $self->url ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 27 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 809 | ▶ | $self->_run( $dir, [ 'remote', 'set-url', '--', 'origin', $self->url ] ) if $origin{'remote.origin.url'} ne $self->url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 808 | ▶ | $self->_run( $dir, [ 'config', '--local', 'remote.origin.fetch', $ORIGIN_REFSPEC ] ) unless exists $origin{'remote.origin.fetch'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # Bring the checkout of a cache about to be served offline back to exactly its HEAD commit. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 443 | ▶ | sub _restore { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 443 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 443 | my ( $ok, $out ) = $self->_ok( $dir, [ 'status', '--porcelain', '--ignored', '--untracked-files=normal' ], undef, { GIT_OPTIONAL_LOCKS => '0' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 433 | ▶ | return if $ok && $out eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ok and $out eq ""
MC/DC50%1/2
$ok and $out eq ""
$ok
$out eq ""
Truth table66%2/3
A and B
A= $okB= $out eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 13 | my $fixed = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 13 | $self->_run( $dir, [ 'reset', '--hard', 'HEAD' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 12 | $self->_run( $dir, [ 'clean', '-ffdxq' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 11 | ▶ | return if $fixed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | Skilletor::Error::CacheRejected->throw( 'its checkout cannot be brought back to HEAD: '._msg($@) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3134 | ▶ | sub _version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_version: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 3134 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3134 | my $ref = $self->ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 3134 | ▶ | if ( $self->_pinned ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # Validate even on fallback: a repo's existence is no proof it holds this pin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1024 | my $head = js_trim( $self->_run( $dir, [ 'rev-parse', '--verify', 'HEAD^{commit}' ] ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1015 | my ( $ok, $out ) = $self->_ok( $dir, [ 'rev-parse', '--verify', '--quiet', $ref.'^{commit}' ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1006 | ▶ | my $pin = $ok ? js_trim($out) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # A prefix of HEAD must resolve to HEAD unambiguously; any other ref is taken as a name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # unless it names another commit here – or is a full SHA, never read as a name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1006 | ▶ | my $by_name = length($ref) < 40 && ( $pin eq '' || $pin eq $head ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
length $ref < 40 && ($pin eq '' || $pin eq $head)
$pin eq "" or $pin eq $head
MC/DC33%1/3
length $ref < 40 && ($pin eq '' || $pin eq $head)
length $ref < 40
$pin eq ""
$pin eq $head
Truth table75%3/4
A && B or C
A= length $ref < 40B= $pin eq ""C= $pin eq $head
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1006 | ▶ | my $held = index( $head, js_lc($ref) ) == 0 ? $pin eq $head : $by_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1006 | ▶ | Skilletor::Error::CacheRejected->throw( 'cached commit '.$head.' does not match requested pin '.$ref ) unless $held; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 3012 | my $sha = js_trim( $self->_run( $dir, [ 'rev-parse', '--short', 'HEAD' ] ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2558 | return 'git:'.$sha; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1648 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1648 | my ( $self, $cached_version ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1648 | ▶ | return 1 unless defined $cached_version && length $cached_version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cached_version and length $cached_version
MC/DC100%2/2
defined $cached_version and length $cached_version
defined $cached_version
length $cached_version
Truth table100%3/3
A and B
A= defined $cached_versionB= length $cached_version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1314 | my $ref = $self->ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1314 | ( my $cached = $cached_version ) =~ s/\Agit://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1314 | $cached = js_lc($cached); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # A SHA pin the lock already holds never moves: decided without the remote. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1314 | ▶ | return 0 if $self->_pinned && _same_prefix( $cached, js_lc($ref) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->_pinned and _same_prefix($cached, js_lc($ref))
MC/DC100%2/2
$self->_pinned and _same_prefix($cached, js_lc($ref))
$self->_pinned
_same_prefix($cached, js_lc($ref))
Truth table100%3/3
A and B
A= $self->_pinnedB= _same_prefix($cached, js_lc($ref))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # The commit the ref names upstream; nothing counts as changed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1152 | ▶ | my $name = defined $ref ? $ref : 'HEAD'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1152 | my @patterns = map { ( $_, $_.'^{}' ) } $name, $name.'/HEAD'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1152 | my $out = $self->_run( '', [ 'ls-remote', '--', $self->url, @patterns ], $self->timeout_ms ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1007 | my $remote = $self->remote_commit( $out, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1007 | ▶ | return ( length $cached && index( $remote, $cached ) == 0 ) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $cached and index($remote, $cached) == 0
MC/DC50%1/2
length $cached and index($remote, $cached) == 0
length $cached
index($remote, $cached) == 0
Truth table66%2/3
A and B
A= length $cachedB= index($remote, $cached) == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # The commit a ref names in `git ls-remote` output: of the refs listed, the one git ranks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # first, through its peeled ^{} line when it is a tag object. "" when none is listed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1199 | ▶ | sub remote_commit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remote_commit: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 1199 | my ( $self, $ls_remote, $ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1199 | my %shas; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1199 | for my $line ( split /\n/, $ls_remote, -1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2985 | my ( $sha, $name ) = split /\t/, $line, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 2985 | ▶ | $shas{$name} = js_lc($sha) if defined $sha && length $sha && defined $name && length $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
defined $sha and length $sha and defined $name and length $name
defined $sha and length $sha and defined $name
defined $sha and length $sha
MC/DC25%1/4
defined $sha and length $sha and defined $name and length $name
defined $sha
length $sha
defined $name
length $name
Truth table40%2/5
A and B and C and D
A= defined $shaB= length $shaC= defined $nameD= length $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1199 | for my $rule (@REF_RULES) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2490 | my $name = $rule->($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2490 | ▶ | my $sha = $shas{ $name.'^{}' } // $shas{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$shas{$name . '^{}'} // $shas{$name}
MC/DC100%2/2
$shas{$name . '^{}'} // $shas{$name}
$shas{$name . '^{}'}
$shas{$name}
Truth table100%3/3
A // B
A= $shas{$name . '^{}'}B= $shas{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2490 | ▶ | return $sha if defined $sha && length $sha; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $sha and length $sha
MC/DC50%1/2
defined $sha and length $sha
defined $sha
length $sha
Truth table66%2/3
A and B
A= defined $shaB= length $sha
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 123 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 243 | ▶ | sub _same_prefix { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_same_prefix: called CC=4 SCAR=15.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 243 | my ( $a, $b ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 243 | ▶ | return length $a && length $b && ( index( $a, $b ) == 0 || index( $b, $a ) == 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition55%5/9
length $a && length $b && (index($a, $b) == 0 || index($b, $a) == 0)
length $a and length $b
index($a, $b) == 0 or index($b, $a) == 0
MC/DC25%1/4
length $a && length $b && (index($a, $b) == 0 || index($b, $a) == 0)
length $a
length $b
index($a, $b) == 0
index($b, $a) == 0
Truth table40%2/5
A and B && C or D
A= length $aB= length $bC= index($a, $b) == 0D= index($b, $a) == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # `git config -z` output – key\nvalue\0 per entry – as key => last value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 809 | ▶ | sub _config_entries { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_config_entries: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 809 | my ( $self, $out ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 809 | my %entries; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 809 | for my $entry ( split /\0/, $out, -1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 2392 | ▶ | next if $entry eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1583 | my $nl = index $entry, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1583 | ▶ | $entries{ $nl < 0 ? $entry : substr( $entry, 0, $nl ) } = $nl < 0 ? '' : substr( $entry, $nl + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 809 | return \%entries; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Remove the lock files a git killed midway left in the git caches of a cache root – each once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # older than the sync lock's stale age. Only safe while no resolve runs: the caller holds the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # sync lock. Never throws. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 351 | ▶ | sub sweep_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sweep_cache: called CC=11 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 351 | my ( $class, $cache_root, $now ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 351 | ▶ | $now //= Time::HiRes::time(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$now //= &Time::HiRes::time()
MC/DC0%0/2
$now //= &Time::HiRes::time()
$now
&Time::HiRes::time()
Truth table33%1/3
A //= B
A= $nowB= &Time::HiRes::time()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 351 | ▶ | opendir( my $dh, $cache_root ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 68 | my @names = readdir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 68 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 68 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 205 | ▶ | next unless $name =~ CACHE_NAME_RE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 68 | my $git_dir = path_join( $cache_root, $name, '.git' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 68 | ▶ | next unless lstat($git_dir) && -d _; # a symlink or a gitfile: not one git init made | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
lstat $git_dir and -d _
MC/DC0%0/2
lstat $git_dir and -d _
lstat $git_dir
-d _
Truth table33%1/3
A and B
A= lstat $git_dirB= -d _
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 68 | for my $file ( ( map { path_join( $git_dir, $_ ) } @LOCK_FILES ), $class->_ref_locks( path_join( $git_dir, 'refs' ) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 477 | ▶ | my @st = lstat $file or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 5 | ▶ | next unless -f _; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 5 | ▶ | unlink $file if $now - $st[9] > $STALE_LOCK_SECONDS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 68 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 203 | ▶ | sub _ref_locks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ref_locks: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 203 | my ( $class, $dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 203 | ▶ | opendir( my $dh, $dir ) or return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 203 | ▶ | my @names = grep { $_ ne '.' && $_ ne '..' } readdir $dh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ ne '.' && $_ ne '..'
MC/DC100%2/2
$_ ne '.' && $_ ne '..'
$_ ne '.'
$_ ne '..'
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne '..'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 203 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 203 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 203 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 203 | my $p = path_join( $dir, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 203 | ▶ | lstat $p or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 203 | ▶ | if ( -d _ ) { push @out, $class->_ref_locks($p) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | ▶ | elsif ( -f _ && $name =~ /\.lock\z/ ) { push @out, $p } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
-f _ and $name =~ /\.lock\z/
MC/DC50%1/2
-f _ and $name =~ /\.lock\z/
-f _
$name =~ /\.lock\z/
Truth table66%2/3
A and B
A= -f _B= $name =~ /\.lock\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 203 | return @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 234 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||