| 1 | package Git::Database::Role::PurePerlBackend; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | $Git::Database::Role::PurePerlBackend::VERSION = '0.012'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use Path::Class qw( file ); # used by Git::PurePerl/Cogit | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Git::Database::Object::Raw; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | #use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | requires | |||||||||||||||||||||||||||||||||||||||||
| 12 | '_store_packs', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | with | |||||||||||||||||||||||||||||||||||||||||
| 16 | 'Git::Database::Role::Backend', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 'Git::Database::Role::ObjectReader', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 'Git::Database::Role::ObjectWriter', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 'Git::Database::Role::RefReader', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub _expand_abbrev { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | my ( $self, $abbrev ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expand_abbrev: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # some shortcuts | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | return '' if !defined $abbrev; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | return lc $abbrev if $abbrev =~ /^[0-9a-fA-F]{40}$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | return '' if length $abbrev < 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # basic implementation | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | my @matches = grep /^$abbrev/, $self->all_digests; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | warn "error: short SHA1 $abbrev is ambiguous.\n" if @matches > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | return @matches == 1 ? shift @matches : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # Git::Database::Role::ObjectReader | ||||||||||||||||||||||||||||||||||||||||||
| 37 | sub get_object_attributes { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 426 | ▶ | my ( $self, $digest ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_object_attributes: called CC=10 SCAR=24.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # expand abbreviated digests | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 426 | ▶ | $digest = $self->_expand_abbrev($digest) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$digest =~ /^[0-9a-f]{40}$/ || (($digest = $self->_expand_abbrev($digest)) || (return undef))
$digest = $self->_expand_abbrev($digest) or return undef
MC/DC0%0/2
$digest =~ /^[0-9a-f]{40}$/ || (($digest = $self->_expand_abbrev($digest)) || (return undef))
$digest =~ /^[0-9a-f]{40}$/
$digest = $self->_expand_abbrev($digest)
Truth table66%2/3
A || B
A= $digest =~ /^[0-9a-f]{40}$/B= $digest = $self->_expand_abbrev($digest)
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | or return undef | ||||||||||||||||||||||||||||||||||||||||||
| 43 | if $digest !~ /^[0-9a-f]{40}$/; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | # search packs | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 424 | for my $pack ( @{ $self->_store_packs } ) { | |||||||||||||||||||||||||||||||||||||||||
| 47 | 214 | my ( $kind, $size, $content ) = $pack->get_object($digest); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 214 | ▶ | if ( defined($kind) && defined($size) && defined($content) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $kind and defined $size and defined $content
defined $kind and defined $size
MC/DC0%0/3
defined $kind and defined $size and defined $content
defined $kind
defined $size
defined $content
Truth table25%1/4
A and B and C
A= defined $kindB= defined $sizeC= defined $content
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 214 | kind => $kind, | |||||||||||||||||||||||||||||||||||||||||
| 51 | digest => $digest, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | content => $content, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | size => $size, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # search loose objects | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 210 | my ( $kind, $size, $content ) = $self->store->loose->get_object($digest); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 210 | ▶ | if ( defined($kind) && defined($size) && defined($content) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $kind and defined $size and defined $content
defined $kind and defined $size
MC/DC33%1/3
defined $kind and defined $size and defined $content
defined $kind
defined $size
defined $content
Truth table50%2/4
A and B and C
A= defined $kindB= defined $sizeC= defined $content
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 26 | kind => $kind, | |||||||||||||||||||||||||||||||||||||||||
| 63 | digest => $digest, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | content => $content, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | size => $size, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 184 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | sub all_digests { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 28 | ▶ | my ( $self, $kind ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_digests: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 28 | ▶ | return $self->store->all_sha1s->all if !$kind; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 16 | return map $_->sha1, grep $_->kind eq $kind, $self->store->all_objects->all; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | # Git::Database::Role::ObjectWriter | ||||||||||||||||||||||||||||||||||||||||||
| 79 | sub put_object { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 26 | ▶ | my ( $self, $object ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put_object: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 26 | $self->store->loose->put_object( Git::Database::Object::Raw->new($object) ); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 26 | return $object->digest; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # Git::Database::Role::RefReader | ||||||||||||||||||||||||||||||||||||||||||
| 86 | sub refs { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 32 | ▶ | my $store = $_[0]->store; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refs: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 32 | my %refs = ( HEAD => $store->ref_sha1('HEAD') ); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 32 | @refs{ $store->ref_names } = $store->refs_sha1; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # get back to packed-refs to pick the primary target of the refs, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # since Git::PurePerl's ref_sha1 peels everything to reach the commit | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 32 | ▶ | if ( -f ( my $packed_refs = file( $store->gitdir, 'packed-refs' ) ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 32 | for my $line ( $packed_refs->slurp( chomp => 1 ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 95 | 96 | ▶ | next if $line =~ /^[#^]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 48 | my ( $sha1, $name ) = split ' ', $line; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 48 | $refs{$name} = $sha1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 32 | return \%refs; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =for Pod::Coverage | ||||||||||||||||||||||||||||||||||||||||||
| 111 | get_object_attributes | ||||||||||||||||||||||||||||||||||||||||||
| 112 | all_digests | ||||||||||||||||||||||||||||||||||||||||||
| 113 | put_object | ||||||||||||||||||||||||||||||||||||||||||
| 114 | refs | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | Git::Database::Role::PurePerlBackend - Code shared by the Cogit and Git::PurePerl backends | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | version 0.012 | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | package MyPurePerlBackend; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | use Moo; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | with 'Git::Database::Role::PurePerlBackend'; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # implement the required methods | ||||||||||||||||||||||||||||||||||||||||||
| 134 | sub _store_packs { ... } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 1; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | This role contains the code shared by the | ||||||||||||||||||||||||||||||||||||||||||
| 141 | L<Git::PurePerl> and L<Cogit> backends. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | Both backends share the same API, except for one tiny difference: | ||||||||||||||||||||||||||||||||||||||||||
| 144 | one returns its packs as a list, and the other as an array reference. | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | This role hides the difference behind a simple interface. | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | Philippe Bruhat (BooK) <book@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | Copyright 2016 Philippe Bruhat (BooK), all rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 159 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||||||||||||||||