line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Database::Role::PurePerlBackend; |
2
|
|
|
|
|
|
|
$Git::Database::Role::PurePerlBackend::VERSION = '0.012'; |
3
|
7
|
|
|
7
|
|
5068
|
use Sub::Quote; |
|
7
|
|
|
|
|
52
|
|
|
7
|
|
|
|
|
605
|
|
4
|
7
|
|
|
7
|
|
93
|
use Path::Class qw( file ); # used by Git::PurePerl/Cogit |
|
7
|
|
|
|
|
38
|
|
|
7
|
|
|
|
|
690
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
5140
|
use Git::Database::Object::Raw; |
|
7
|
|
|
|
|
41
|
|
|
7
|
|
|
|
|
283
|
|
7
|
|
|
|
|
|
|
#use namespace::clean; |
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
58
|
use Moo::Role; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
108
|
|
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
|
|
59
|
my ( $self, $abbrev ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# some shortcuts |
26
|
6
|
50
|
|
|
|
50
|
return '' if !defined $abbrev; |
27
|
6
|
50
|
|
|
|
37
|
return lc $abbrev if $abbrev =~ /^[0-9a-fA-F]{40}$/; |
28
|
6
|
50
|
|
|
|
54
|
return '' if length $abbrev < 4; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# basic implementation |
31
|
6
|
|
|
|
|
26
|
my @matches = grep /^$abbrev/, $self->all_digests; |
32
|
6
|
100
|
|
|
|
20995
|
warn "error: short SHA1 $abbrev is ambiguous.\n" if @matches > 1; |
33
|
6
|
100
|
|
|
|
287
|
return @matches == 1 ? shift @matches : ''; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Git::Database::Role::ObjectReader |
37
|
|
|
|
|
|
|
sub get_object_attributes { |
38
|
426
|
|
|
426
|
0
|
2079
|
my ( $self, $digest ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# expand abbreviated digests |
41
|
426
|
100
|
100
|
|
|
2519
|
$digest = $self->_expand_abbrev($digest) |
42
|
|
|
|
|
|
|
or return undef |
43
|
|
|
|
|
|
|
if $digest !~ /^[0-9a-f]{40}$/; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# search packs |
46
|
424
|
|
|
|
|
789
|
for my $pack ( @{ $self->_store_packs } ) { |
|
424
|
|
|
|
|
1690
|
|
47
|
214
|
|
|
|
|
319731
|
my ( $kind, $size, $content ) = $pack->get_object($digest); |
48
|
214
|
50
|
33
|
|
|
216467
|
if ( defined($kind) && defined($size) && defined($content) ) { |
|
|
|
33
|
|
|
|
|
49
|
|
|
|
|
|
|
return { |
50
|
214
|
|
|
|
|
1572
|
kind => $kind, |
51
|
|
|
|
|
|
|
digest => $digest, |
52
|
|
|
|
|
|
|
content => $content, |
53
|
|
|
|
|
|
|
size => $size, |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# search loose objects |
59
|
210
|
|
|
|
|
23235
|
my ( $kind, $size, $content ) = $self->store->loose->get_object($digest); |
60
|
210
|
50
|
66
|
|
|
63212
|
if ( defined($kind) && defined($size) && defined($content) ) { |
|
|
|
66
|
|
|
|
|
61
|
|
|
|
|
|
|
return { |
62
|
26
|
|
|
|
|
248
|
kind => $kind, |
63
|
|
|
|
|
|
|
digest => $digest, |
64
|
|
|
|
|
|
|
content => $content, |
65
|
|
|
|
|
|
|
size => $size, |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
184
|
|
|
|
|
1044
|
return undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub all_digests { |
73
|
28
|
|
|
28
|
0
|
995795
|
my ( $self, $kind ) = @_; |
74
|
28
|
100
|
|
|
|
268
|
return $self->store->all_sha1s->all if !$kind; |
75
|
16
|
|
|
|
|
225
|
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
|
124
|
my ( $self, $object ) = @_; |
81
|
26
|
|
|
|
|
722
|
$self->store->loose->put_object( Git::Database::Object::Raw->new($object) ); |
82
|
26
|
|
|
|
|
22412
|
return $object->digest; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Git::Database::Role::RefReader |
86
|
|
|
|
|
|
|
sub refs { |
87
|
32
|
|
|
32
|
0
|
147968
|
my $store = $_[0]->store; |
88
|
32
|
|
|
|
|
141
|
my %refs = ( HEAD => $store->ref_sha1('HEAD') ); |
89
|
32
|
|
|
|
|
102159
|
@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
|
|
|
|
551728
|
if ( -f ( my $packed_refs = file( $store->gitdir, 'packed-refs' ) ) ) { |
94
|
32
|
|
|
|
|
3960
|
for my $line ( $packed_refs->slurp( chomp => 1 ) ) { |
95
|
96
|
100
|
|
|
|
6511
|
next if $line =~ /^[#^]/; |
96
|
48
|
|
|
|
|
214
|
my ( $sha1, $name ) = split ' ', $line; |
97
|
48
|
|
|
|
|
158
|
$refs{$name} = $sha1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
32
|
|
|
|
|
870
|
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.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 |