line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Database::Role::PurePerlBackend; |
2
|
|
|
|
|
|
|
$Git::Database::Role::PurePerlBackend::VERSION = '0.011'; |
3
|
7
|
|
|
7
|
|
5080
|
use Sub::Quote; |
|
7
|
|
|
|
|
44
|
|
|
7
|
|
|
|
|
622
|
|
4
|
7
|
|
|
7
|
|
86
|
use Path::Class qw( file ); # used by Git::PurePerl/Cogit |
|
7
|
|
|
|
|
31
|
|
|
7
|
|
|
|
|
632
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
5355
|
use Git::Database::Object::Raw; |
|
7
|
|
|
|
|
28
|
|
|
7
|
|
|
|
|
333
|
|
7
|
|
|
|
|
|
|
#use namespace::clean; |
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
79
|
use Moo::Role; |
|
7
|
|
|
|
|
32
|
|
|
7
|
|
|
|
|
103
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
requires |
12
|
|
|
|
|
|
|
'_store_packs', |
13
|
|
|
|
|
|
|
; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
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
|
|
|
6
|
|
51
|
my ( $self, $abbrev ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# some shortcuts |
26
|
6
|
50
|
|
|
|
45
|
return '' if !defined $abbrev; |
27
|
6
|
50
|
|
|
|
28
|
return lc $abbrev if $abbrev =~ /^[0-9a-fA-F]{40}$/; |
28
|
6
|
50
|
|
|
|
43
|
return '' if length $abbrev < 4; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# basic implementation |
31
|
6
|
|
|
|
|
36
|
my @matches = grep /^$abbrev/, $self->all_digests; |
32
|
6
|
100
|
|
|
|
21473
|
warn "error: short SHA1 $abbrev is ambiguous.\n" if @matches > 1; |
33
|
6
|
100
|
|
|
|
341
|
return @matches == 1 ? shift @matches : ''; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Git::Database::Role::ObjectReader |
37
|
|
|
|
|
|
|
sub get_object_attributes { |
38
|
426
|
|
|
426
|
0
|
2014
|
my ( $self, $digest ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# expand abbreviated digests |
41
|
426
|
100
|
100
|
|
|
2697
|
$digest = $self->_expand_abbrev($digest) |
42
|
|
|
|
|
|
|
or return undef |
43
|
|
|
|
|
|
|
if $digest !~ /^[0-9a-f]{40}$/; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# search packs |
46
|
424
|
|
|
|
|
775
|
for my $pack ( @{ $self->_store_packs } ) { |
|
424
|
|
|
|
|
1851
|
|
47
|
214
|
|
|
|
|
312150
|
my ( $kind, $size, $content ) = $pack->get_object($digest); |
48
|
214
|
50
|
33
|
|
|
219151
|
if ( defined($kind) && defined($size) && defined($content) ) { |
|
|
|
33
|
|
|
|
|
49
|
|
|
|
|
|
|
return { |
50
|
214
|
|
|
|
|
1700
|
kind => $kind, |
51
|
|
|
|
|
|
|
digest => $digest, |
52
|
|
|
|
|
|
|
content => $content, |
53
|
|
|
|
|
|
|
size => $size, |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# search loose objects |
59
|
210
|
|
|
|
|
27800
|
my ( $kind, $size, $content ) = $self->store->loose->get_object($digest); |
60
|
210
|
50
|
66
|
|
|
71746
|
if ( defined($kind) && defined($size) && defined($content) ) { |
|
|
|
66
|
|
|
|
|
61
|
|
|
|
|
|
|
return { |
62
|
26
|
|
|
|
|
322
|
kind => $kind, |
63
|
|
|
|
|
|
|
digest => $digest, |
64
|
|
|
|
|
|
|
content => $content, |
65
|
|
|
|
|
|
|
size => $size, |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
184
|
|
|
|
|
1193
|
return undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub all_digests { |
73
|
28
|
|
|
28
|
0
|
948762
|
my ( $self, $kind ) = @_; |
74
|
28
|
100
|
|
|
|
256
|
return $self->store->all_sha1s->all if !$kind; |
75
|
16
|
|
|
|
|
203
|
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
|
|
|
26
|
0
|
133
|
my ( $self, $object ) = @_; |
81
|
26
|
|
|
|
|
721
|
$self->store->loose->put_object( Git::Database::Object::Raw->new($object) ); |
82
|
26
|
|
|
|
|
23791
|
return $object->digest; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Git::Database::Role::RefReader |
86
|
|
|
|
|
|
|
sub refs { |
87
|
32
|
|
|
32
|
0
|
157190
|
my $store = $_[0]->store; |
88
|
32
|
|
|
|
|
149
|
my %refs = ( HEAD => $store->ref_sha1('HEAD') ); |
89
|
32
|
|
|
|
|
100250
|
@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
|
50
|
|
|
|
552640
|
if ( -f ( my $packed_refs = file( $store->gitdir, 'packed-refs' ) ) ) { |
94
|
32
|
|
|
|
|
3998
|
for my $line ( $packed_refs->slurp( chomp => 1 ) ) { |
95
|
96
|
100
|
|
|
|
6443
|
next if $line =~ /^[#^]/; |
96
|
48
|
|
|
|
|
183
|
my ( $sha1, $name ) = split ' ', $line; |
97
|
48
|
|
|
|
|
133
|
$refs{$name} = $sha1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
32
|
|
|
|
|
959
|
return \%refs; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
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.011 |
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 |