line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Database::Backend::Git::Raw::Repository; |
2
|
|
|
|
|
|
|
$Git::Database::Backend::Git::Raw::Repository::VERSION = '0.012'; |
3
|
7
|
|
|
7
|
|
178448
|
use Git::Raw; |
|
7
|
|
|
|
|
55
|
|
|
7
|
|
|
|
|
459
|
|
4
|
7
|
|
|
7
|
|
123
|
use Sub::Quote; |
|
7
|
|
|
|
|
47
|
|
|
7
|
|
|
|
|
1207
|
|
5
|
7
|
|
|
7
|
|
73
|
use Moo; |
|
7
|
|
|
|
|
40
|
|
|
7
|
|
|
|
|
189
|
|
6
|
7
|
|
|
7
|
|
25992
|
use namespace::clean; |
|
7
|
|
|
|
|
284
|
|
|
7
|
|
|
|
|
144
|
|
7
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my @kind; |
30
|
|
|
|
|
|
|
$kind[ $type{$_} ] = $_ for keys %type; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Git::Database::Role::Backend |
33
|
|
|
|
|
|
|
sub hash_object { |
34
|
95
|
|
|
95
|
0
|
24502
|
my ( $self, $object ) = @_; |
35
|
95
|
|
|
|
|
3114
|
return $self->store->odb->hash( $object->content, $type{ $object->kind } ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Git::Database::Role::ObjectReader |
39
|
|
|
|
|
|
|
sub get_object_attributes { |
40
|
213
|
|
|
213
|
0
|
1040
|
my ( $self, $digest ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# get the Git::Raw::Odb::Object |
43
|
213
|
|
|
|
|
22387
|
my $object = eval { $self->store->odb->read($digest) } |
44
|
213
|
100
|
66
|
|
|
463
|
or $@ and do { ( my $at = $@ ) =~ s/ at .* line .*$//; warn "$at\n" }; |
|
1
|
|
|
|
|
34
|
|
|
1
|
|
|
|
|
117
|
|
45
|
213
|
100
|
|
|
|
1333
|
return undef if !defined $object; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
return { |
48
|
120
|
|
|
|
|
1972
|
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
|
|
|
11
|
0
|
137604
|
my ( $self, $kind ) = @_; |
57
|
11
|
|
|
|
|
784
|
my $odb = $self->store->odb; |
58
|
11
|
100
|
|
|
|
167
|
my $type = $kind ? $type{$kind} : ''; |
59
|
|
|
|
|
|
|
|
60
|
11
|
|
|
|
|
40
|
my @digests; |
61
|
|
|
|
|
|
|
$odb->foreach( |
62
|
|
|
|
|
|
|
$kind |
63
|
|
|
|
|
|
|
? sub { |
64
|
44
|
|
|
44
|
|
1145
|
my $o = $odb->read( shift ); |
65
|
44
|
100
|
|
|
|
268
|
push @digests, $o->id if $o->type == $type; |
66
|
44
|
|
|
|
|
1203
|
return 0; |
67
|
|
|
|
|
|
|
} |
68
|
11
|
|
|
11
|
|
37
|
: sub { push @digests, shift; return 0; } |
|
11
|
|
|
|
|
242
|
|
69
|
11
|
100
|
|
|
|
996
|
); |
70
|
11
|
|
|
|
|
326
|
return sort @digests; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Git::Database::Role::ObjectWriter |
74
|
|
|
|
|
|
|
sub put_object { |
75
|
13
|
|
|
13
|
0
|
58
|
my ( $self, $object ) = @_; |
76
|
13
|
|
|
|
|
385
|
return $self->store->odb->write( $object->content, $type{ $object->kind } ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Git::Database::Role::RefReader |
80
|
|
|
|
|
|
|
sub refs { |
81
|
20
|
|
|
20
|
0
|
69362
|
my ($self) = @_; |
82
|
|
|
|
|
|
|
return { |
83
|
20
|
|
|
|
|
7957
|
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
|
|
|
132
|
|
332
|
my ($self, $maybe_ref) = @_; |
91
|
132
|
100
|
|
|
|
3262
|
return $maybe_ref->isa('Git::Raw::Reference') |
92
|
|
|
|
|
|
|
? $self->_deref($maybe_ref->target) |
93
|
|
|
|
|
|
|
: $maybe_ref; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Git::Database::Role::RefWriter |
97
|
|
|
|
|
|
|
sub put_ref { |
98
|
2
|
|
|
2
|
0
|
1062
|
my ($self, $refname, $digest) = @_; |
99
|
2
|
|
|
|
|
1169
|
Git::Raw::Reference->create( |
100
|
|
|
|
|
|
|
$refname, $self->store, $self->store->lookup($digest)); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub delete_ref { |
104
|
2
|
|
|
2
|
0
|
22
|
my ($self, $refname) = @_; |
105
|
2
|
|
|
|
|
529
|
Git::Raw::Reference->lookup($refname, $self->store)->delete; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
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 |