| 1 | package Git::Database::Backend::Git::Raw::Repository; | ||||||||||||||||||||||||||||
| 2 | 8 | $Git::Database::Backend::Git::Raw::Repository::VERSION = '0.012'; | |||||||||||||||||||||||||||
| 3 | 8 | ▶ | use Git::Raw; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 8 | with | |||||||||||||||||||||||||||
| 9 | 'Git::Database::Role::Backend', | ||||||||||||||||||||||||||||
| 10 | 'Git::Database::Role::ObjectReader', | ||||||||||||||||||||||||||||
| 11 | 'Git::Database::Role::ObjectWriter', | ||||||||||||||||||||||||||||
| 12 | 'Git::Database::Role::RefReader', | ||||||||||||||||||||||||||||
| 13 | 'Git::Database::Role::RefWriter', | ||||||||||||||||||||||||||||
| 14 | ; | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 8 | has '+store' => ( | |||||||||||||||||||||||||||
| 17 | isa => quote_sub( q{ | ||||||||||||||||||||||||||||
| 18 | die 'store is not a Git::Raw::Repository object' | ||||||||||||||||||||||||||||
| 19 | if !eval { $_[0]->isa('Git::Raw::Repository') } | ||||||||||||||||||||||||||||
| 20 | } ), | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 8 | my %type = ( | |||||||||||||||||||||||||||
| 24 | blob => Git::Raw::Object->BLOB, | ||||||||||||||||||||||||||||
| 25 | tree => Git::Raw::Object->TREE, | ||||||||||||||||||||||||||||
| 26 | commit => Git::Raw::Object->COMMIT, | ||||||||||||||||||||||||||||
| 27 | tag => Git::Raw::Object->TAG, | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | 8 | my @kind; | |||||||||||||||||||||||||||
| 30 | 8 | $kind[ $type{$_} ] = $_ for keys %type; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Git::Database::Role::Backend | ||||||||||||||||||||||||||||
| 33 | sub hash_object { | ||||||||||||||||||||||||||||
| 34 | 95 | ▶ | my ( $self, $object ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
hash_object: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 95 | return $self->store->odb->hash( $object->content, $type{ $object->kind } ); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Git::Database::Role::ObjectReader | ||||||||||||||||||||||||||||
| 39 | sub get_object_attributes { | ||||||||||||||||||||||||||||
| 40 | 213 | ▶ | my ( $self, $digest ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_object_attributes: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # get the Git::Raw::Odb::Object | ||||||||||||||||||||||||||||
| 43 | 213 | ▶ | my $object = eval { $self->store->odb->read($digest) } | ||||||||||||||||||||||||||
|
Condition66%2/3
$@ and do {
MC/DC0%0/2
$@ and do {
(my $at = $@) =~ s/ at .* line .*$//;
warn "$at\n"
}
$@
do {
(my $at = $@) =~ s/ at .* line .*$//;
warn "$at\n"
}
Truth table66%2/3
A and B
A= $@B= do {
(my $at = $@) =~ s/ at .* line .*$//;
warn "$at\n"
}
| |||||||||||||||||||||||||||||
| 44 | 213 | ▶ | or $@ and do { ( my $at = $@ ) =~ s/ at .* line .*$//; warn "$at\n" }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
(my $object = eval { || $@ && do {
MC/DC0%0/2
(my $object = eval {
do {
$self->store->odb->read($digest)
}
}) || $@ && do {
(my $at = $@) =~ s/ at .* line .*$//;
warn "$at\n"
}
(my $object = eval {
do {
$self->store->odb->read($digest)
}
})
$@ && do {
(my $at = $@) =~ s/ at .* line .*$//;
warn "$at\n"
}
Truth table66%2/3
A || B
A= (my $object = eval {
do {
$self->store->odb->read($digest)
}
})B= $@ && do {
(my $at = $@) =~ s/ at .* line .*$//;
warn "$at\n"
}
| |||||||||||||||||||||||||||||
| 45 | 213 | ▶ | return undef if !defined $object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | return { | ||||||||||||||||||||||||||||
| 48 | 120 | kind => $kind[ $object->type ], | |||||||||||||||||||||||||||
| 49 | size => $object->size, | ||||||||||||||||||||||||||||
| 50 | content => $object->data, | ||||||||||||||||||||||||||||
| 51 | digest => $object->id, | ||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub all_digests { | ||||||||||||||||||||||||||||
| 56 | 11 | ▶ | my ( $self, $kind ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
all_digests: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 11 | my $odb = $self->store->odb; | |||||||||||||||||||||||||||
| 58 | 11 | ▶ | my $type = $kind ? $type{$kind} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 11 | my @digests; | |||||||||||||||||||||||||||
| 61 | $odb->foreach( | ||||||||||||||||||||||||||||
| 62 | $kind | ||||||||||||||||||||||||||||
| 63 | ? sub { | ||||||||||||||||||||||||||||
| 64 | 44 | ▶ | my $o = $odb->read( shift ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 65 | 44 | ▶ | push @digests, $o->id if $o->type == $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 44 | return 0; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 11 | ▶ | : sub { push @digests, shift; return 0; } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 11 | ▶ | ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 11 | return sort @digests; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Git::Database::Role::ObjectWriter | ||||||||||||||||||||||||||||
| 74 | sub put_object { | ||||||||||||||||||||||||||||
| 75 | 13 | ▶ | my ( $self, $object ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
put_object: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 13 | return $self->store->odb->write( $object->content, $type{ $object->kind } ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Git::Database::Role::RefReader | ||||||||||||||||||||||||||||
| 80 | sub refs { | ||||||||||||||||||||||||||||
| 81 | 20 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
refs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | return { | ||||||||||||||||||||||||||||
| 83 | 20 | map +( $_->name => $self->_deref($_->target)->id ), | |||||||||||||||||||||||||||
| 84 | # we include HEAD explicitly to mimic `show-ref --head` | ||||||||||||||||||||||||||||
| 85 | Git::Raw::Reference->lookup('HEAD', $self->store), $self->store->refs | ||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub _deref { | ||||||||||||||||||||||||||||
| 90 | 132 | ▶ | my ($self, $maybe_ref) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_deref: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 91 | 132 | ▶ | return $maybe_ref->isa('Git::Raw::Reference') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | ? $self->_deref($maybe_ref->target) | ||||||||||||||||||||||||||||
| 93 | : $maybe_ref; | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # Git::Database::Role::RefWriter | ||||||||||||||||||||||||||||
| 97 | sub put_ref { | ||||||||||||||||||||||||||||
| 98 | 2 | ▶ | my ($self, $refname, $digest) = @_; | ||||||||||||||||||||||||||
|
Subroutine
put_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 2 | Git::Raw::Reference->create( | |||||||||||||||||||||||||||
| 100 | $refname, $self->store, $self->store->lookup($digest)); | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub delete_ref { | ||||||||||||||||||||||||||||
| 104 | 2 | ▶ | my ($self, $refname) = @_; | ||||||||||||||||||||||||||
|
Subroutine
delete_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 2 | Git::Raw::Reference->lookup($refname, $self->store)->delete; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 8 | 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =pod | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =for Pod::Coverage | ||||||||||||||||||||||||||||
| 115 | hash_object | ||||||||||||||||||||||||||||
| 116 | get_object_attributes | ||||||||||||||||||||||||||||
| 117 | all_digests | ||||||||||||||||||||||||||||
| 118 | put_object | ||||||||||||||||||||||||||||
| 119 | refs | ||||||||||||||||||||||||||||
| 120 | put_ref | ||||||||||||||||||||||||||||
| 121 | delete_ref | ||||||||||||||||||||||||||||
| 122 | _deref | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 NAME | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | Git::Database::Backend::Git::Raw::Repository - A Git::Database backend based on Git::Raw | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 VERSION | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | version 0.012 | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # get a store | ||||||||||||||||||||||||||||
| 135 | my $r = Git::Raw::Repository->open('path/to/some/git/repository'); | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # let Git::Database produce the backend | ||||||||||||||||||||||||||||
| 138 | my $db = Git::Database->new( store => $r ); | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | This backend reads data from a Git repository using the L<Git::Raw> | ||||||||||||||||||||||||||||
| 143 | bindings to the L<libgit2|http://libgit2.github.com> library. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head2 Git Database Roles | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | This backend does the following roles | ||||||||||||||||||||||||||||
| 148 | (check their documentation for a list of supported methods): | ||||||||||||||||||||||||||||
| 149 | L<Git::Database::Role::Backend>, | ||||||||||||||||||||||||||||
| 150 | L<Git::Database::Role::ObjectReader>, | ||||||||||||||||||||||||||||
| 151 | L<Git::Database::Role::ObjectWriter>, | ||||||||||||||||||||||||||||
| 152 | L<Git::Database::Role::RefReader>, | ||||||||||||||||||||||||||||
| 153 | L<Git::Database::Role::RefWriter>. | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head1 CAVEAT | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | This backend requires L<Git::Raw> version 0.74 or greater. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Sergey Romanov <sromanov@cpan.org> provided the initial version of | ||||||||||||||||||||||||||||
| 162 | the module, with support for the L<Git::Database::Role::RefReader> | ||||||||||||||||||||||||||||
| 163 | and L<Git::Database::Role::RefWriter> roles. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | Philippe Bruhat (BooK) <book@cpan.org> implemented | ||||||||||||||||||||||||||||
| 166 | the L<Git::Database::Role::ObjectReader> and | ||||||||||||||||||||||||||||
| 167 | L<Git::Database::Role::ObjectWriter> roles. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | Jacques Germishuys <jacquesg@cpan.org> added the features needed for | ||||||||||||||||||||||||||||
| 170 | the above roles to L<Git::Raw>. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | Copyright 2017 Philippe Bruhat (BooK), all rights reserved. | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 179 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =cut | ||||||||||||||||||||||||||||