Cogit.pm

filter: Statementstmt 86.9% 233 / 268 Branchbran 59.2% 45 / 76 Conditioncond 40.9% 18 / 44 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 94.1% 48 / 51 Podpod 26.0% 6 / 23 totaltotal 71.8% 350 / 487 CC 64 SCAR 19.7
CC
64
Cov
76%
ref_sha1
26.4
checkout
12.1
clone
12.0
CRAP 7.2
« Cogit/PackIndex/Version1.pm ↑ Summary Cogit/Object/Commit.pm »
1 package Cogit;
2 4 $Cogit::VERSION = '0.001001';
3 # ABSTRACT: A truly Pure Perl interface to Git repositories
4  
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Check::ISA;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use MooX::Types::MooseLike::Base qw( InstanceOf ArrayRef Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Data::Stream::Bulk::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Data::Stream::Bulk::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Cogit::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Cogit::Loose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Cogit::Object::Blob;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Cogit::Object::Commit;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Cogit::Object::Tag;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Cogit::Object::Tree;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use Cogit::Pack::WithIndex;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Cogit::Pack::WithoutIndex;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Cogit::Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 has directory => (
25 is => 'ro',
26 isa => InstanceOf ['Path::Class::Dir'],
27 6 ▶ coerce => sub { return dir($_[0]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 4 );
29  
30 has gitdir => (
31 is => 'ro',
32 isa => InstanceOf ['Path::Class::Dir'],
33 8 ▶ coerce => sub { return dir($_[0]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 4 required => 1,
35 );
36  
37 4 has loose => (
38 is => 'rw',
39 isa => InstanceOf ['Cogit::Loose'],
40 lazy => 1,
41 builder => '_build_loose',
42 );
43  
44 4 has packs => (
45 is => 'rw',
46 isa => ArrayRef [InstanceOf ['Cogit::Pack']],
47 lazy => 1,
48 builder => '_build_packs',
49 );
50  
51 has description => (
52 is => 'rw',
53 isa => Str,
54 lazy => 1,
55 2 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 2 my $self = shift;
57 2 file($self->gitdir, 'description')->slurp(chomp => 1);
58 4 });
59  
60 has config => (
61 is => 'ro',
62 isa => InstanceOf ['Cogit::Config'],
63 lazy => 1,
64 8 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
65 8 my $self = shift;
66 8 Cogit::Config->new(git => $self);
67 4 });
68  
69 8 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=2 SCAR=7.0
Pod undocumented
70 8 my $class = shift;
71 8 my $params = $class->SUPER::BUILDARGS(@_);
72  
73 8 ▶ $params->{'gitdir'} ||= dir($params->{'directory'}, '.git');
Condition66%2/3
$params->{"gitdir"} ||= dir($params->{"directory"}, ".git")
l!l&&r!l&&!r
350
MC/DC0%0/2
$params->{"gitdir"} ||= dir($params->{"directory"}, ".git")
$params->{"gitdir"} dir($params->{"directory"}, ".git")
Truth table66%2/3
A ||= B
A= $params->{"gitdir"}B= dir($params->{"directory"}, ".git")
ABresult
1X1
011
000
74 8 return $params;
75 }
76  
77 8 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=16.4
Pod undocumented
78 8 my $self = shift;
79  
80 8 ▶ unless (-d $self->gitdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $self->gitdir) 0 8 8
81 0 confess $self->gitdir . ' is not a directory';
82 }
83 8 ▶ unless (not defined $self->directory or -d $self->directory) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not defined $self->directory or -d $self->directory) 0 8 8
Condition66%2/3
not defined $self->directory or -d $self->directory
l!l&&r!l&&!r
260
MC/DC0%0/2
not defined $self->directory or -d $self->directory
not defined $self->directory -d $self->directory
Truth table66%2/3
not(A) or B
A= not defined $self->directoryB= -d $self->directory
ABresult
1X1
011
000
84 0 confess $self->directory . ' is not a directory';
85 }
86 }
87  
88 8 ▶sub _build_loose {
Subroutine _build_loose: called CC=1 SCAR=0.0
89 8 my $self = shift;
90 8 my $loose_dir = dir($self->gitdir, 'objects');
91 8 return Cogit::Loose->new(directory => $loose_dir);
92 }
93  
94 8 ▶sub _build_packs {
Subroutine _build_packs: called CC=3 SCAR=11.0
95 8 my $self = shift;
96 8 my $pack_dir = dir($self->gitdir, 'objects', 'pack');
97 8 my @packs;
98 8 for my $filename ($pack_dir->children) {
99 4 ▶ next unless $filename =~ /\.pack$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ /\.pack$/ 2 2 4
100 2 push @packs, Cogit::Pack::WithIndex->new(filename => $filename);
101 }
102 8 return \@packs;
103 }
104  
105 22 ▶sub _ref_names_recursive {
Subroutine _ref_names_recursive: called CC=3 SCAR=13.3
106 22 my ($dir, $base, $names) = @_;
107  
108 22 for my $file ($dir->children) {
109 5 ▶ if (-d $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) { } 0 5 5
110 0 my $reldir = $file->relative($dir);
111 0 my $subbase = $base . $reldir . "/";
112 0 _ref_names_recursive($file, $subbase, $names);
113 } else {
114 5 push @$names, $base . $file->basename;
115 }
116 }
117 }
118  
119 11 ▶sub ref_names {
Subroutine ref_names: called CC=7 SCAR=19.5
Pod undocumented
120 11 my $self = shift;
121 11 my @names;
122 11 for my $type (qw(heads remotes tags)) {
123 33 my $dir = dir($self->gitdir, 'refs', $type);
124 33 ▶ next unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 11 22 33
125 22 my $base = "refs/$type/";
126 22 _ref_names_recursive($dir, $base, \@names);
127 }
128 11 my $packed_refs = file($self->gitdir, 'packed-refs');
129 11 ▶ if (-f $packed_refs) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $packed_refs) 6 5 11
130 6 for my $line ($packed_refs->slurp(chomp => 1)) {
131 12 ▶ next if $line =~ /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 6 6 12
132 6 ▶ next if $line =~ /^\^/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\^/ 0 6 6
133 6 my ($sha1, $name) = split ' ', $line;
134 6 push @names, $name;
135 }
136 }
137 11 return @names;
138 }
139  
140 3 ▶sub refs_sha1 {
Subroutine refs_sha1: called CC=1 SCAR=0.0
Pod undocumented
141 3 my $self = shift;
142 3 return map { $self->ref_sha1($_) } $self->ref_names;
143 }
144  
145 3 ▶sub refs {
Subroutine refs: called CC=1 SCAR=0.0
Pod undocumented
146 3 my $self = shift;
147 3 return map { $self->ref($_) } $self->ref_names;
148 }
149  
150 31 ▶sub ref_sha1 {
Subroutine ref_sha1: called CC=15 SCAR=32.7
Pod undocumented
151 31 my ($self, $wantref) = @_;
152 31 my $dir = dir($self->gitdir, 'refs');
153 31 ▶ return unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 31 31
154  
155 31 ▶ if ($wantref eq "HEAD") {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantref eq "HEAD") 0 31 31
156 0 my $file = file($self->gitdir, 'HEAD');
157 0 ▶ my $sha1 = file($file)->slurp
Condition0%0/2
file($file)->slurp || confess("Error reading ${file}: $!")
l!l
00
MC/DC0%0/1
file($file)->slurp || confess("Error reading ${file}: $!")
file($file)->slurp
Truth table0%0/2
A
A= file($file)->slurp
Aresult
11
00
158 || confess("Error reading $file: $!");
159 0 chomp $sha1;
160 0 return _ensure_sha1_is_sha1($self, $sha1);
161 }
162  
163 31 for my $file (File::Find::Rule->new->file->in($dir)) {
164 17 my $ref = 'refs/' . file($file)->relative($dir)->as_foreign('Unix');
165 17 ▶ if ($ref eq $wantref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq $wantref) 17 0 17
166 17 ▶ my $sha1 = file($file)->slurp
Condition50%1/2
file($file)->slurp || confess("Error reading ${file}: $!")
l!l
170
MC/DC0%0/1
file($file)->slurp || confess("Error reading ${file}: $!")
file($file)->slurp
Truth table50%1/2
A
A= file($file)->slurp
Aresult
11
00
167 || confess("Error reading $file: $!");
168 17 chomp $sha1;
169 17 return _ensure_sha1_is_sha1($self, $sha1);
170 }
171 }
172  
173 14 my $packed_refs = file($self->gitdir, 'packed-refs');
174 14 ▶ if (-f $packed_refs) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $packed_refs) 14 0 14
175 14 my $last_name;
176 my $last_sha1;
177 14 for my $line ($packed_refs->slurp(chomp => 1)) {
178 28 ▶ next if $line =~ /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 14 14 28
179 14 my ($sha1, $name) = split ' ', $line;
180 14 $sha1 =~ s/^\^//;
181 14 ▶ $name ||= $last_name;
Condition33%1/3
$name ||= $last_name
l!l&&r!l&&!r
1400
MC/DC0%0/2
$name ||= $last_name
$name $last_name
Truth table33%1/3
A ||= B
A= $nameB= $last_name
ABresult
1X1
011
000
182  
183 14 ▶ return _ensure_sha1_is_sha1($self, $last_sha1)
Branch: 1 branch
BranchTrueFalseTotal
if $last_name and $last_name eq $wantref and $name ne $wantref 0 14 14
Condition33%2/6
$last_name and $last_name eq $wantref and $name ne $wantref
!ll&&!rl&&r
1400
$last_name and $last_name eq $wantref
!ll&&!rl&&r
1400
MC/DC0%0/3
$last_name and $last_name eq $wantref and $name ne $wantref
$last_name $last_name eq $wantref $name ne $wantref
Truth table25%1/4
A and B and C
A= $last_nameB= $last_name eq $wantrefC= $name ne $wantref
ABCresult
0XX0
10X0
1100
1111
184 if $last_name
185 and $last_name eq $wantref
186 and $name ne $wantref;
187  
188 14 $last_name = $name;
189 14 $last_sha1 = $sha1;
190 }
191 14 ▶ return _ensure_sha1_is_sha1($self, $last_sha1) if $last_name eq $wantref;
Branch: 1 branch
BranchTrueFalseTotal
if $last_name eq $wantref 14 0 14
192 }
193 0 return undef;
194 }
195  
196 31 ▶sub _ensure_sha1_is_sha1 {
Subroutine _ensure_sha1_is_sha1: called CC=2 SCAR=7.1
197 31 my ($self, $sha1) = @_;
198 31 ▶ return $self->ref_sha1($1) if $sha1 =~ /^ref: (.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $sha1 =~ /^ref: (.*)/ 0 31 31
199 31 return $sha1;
200 }
201  
202 22 ▶sub ref {
Subroutine ref: called CC=1 SCAR=0.0
Pod undocumented
203 22 my ($self, $wantref) = @_;
204 22 return $self->get_object($self->ref_sha1($wantref));
205 }
206  
207 3 ▶sub master_sha1 {
Subroutine master_sha1: called CC=1 SCAR=0.0
Pod undocumented
208 3 my $self = shift;
209 3 return $self->ref_sha1('refs/heads/master');
210 }
211  
212 10 ▶sub master {
Subroutine master: called CC=1 SCAR=0.0
Pod documented
213 10 my $self = shift;
214 10 return $self->ref('refs/heads/master');
215 }
216  
217 0 ▶sub head_sha1 {
Subroutine head_sha1: not called CC=1 SCAR=6.9
Pod undocumented
218 0 my $self = shift;
219 0 return $self->ref_sha1('HEAD');
220 }
221  
222 0 ▶sub head {
Subroutine head: not called CC=1 SCAR=6.9
Pod undocumented
223 0 my $self = shift;
224 0 return $self->ref('HEAD');
225 }
226  
227 125 ▶sub get_object {
Subroutine get_object: called CC=3 SCAR=11.0
Pod documented
228 125 my ($self, $sha1) = @_;
229 125 ▶ return unless $sha1;
Branch: 1 branch
BranchTrueFalseTotal
unless $sha1 7 118 125
230 118 ▶ return $self->get_object_packed($sha1) || $self->get_object_loose($sha1);
Condition66%2/3
$self->get_object_packed($sha1) || $self->get_object_loose($sha1)
l!l&&r!l&&!r
46720
MC/DC0%0/2
$self->get_object_packed($sha1) || $self->get_object_loose($sha1)
$self->get_object_packed($sha1) $self->get_object_loose($sha1)
Truth table66%2/3
A || B
A= $self->get_object_packed($sha1)B= $self->get_object_loose($sha1)
ABresult
1X1
011
000
231 }
232  
233 9 ▶sub get_objects {
Subroutine get_objects: called CC=1 SCAR=0.0
Pod undocumented
234 9 my ($self, @sha1s) = @_;
235 9 return map { $self->get_object($_) } @sha1s;
236 }
237  
238 118 ▶sub get_object_packed {
Subroutine get_object_packed: called CC=5 SCAR=18.1
Pod documented
239 118 my ($self, $sha1) = @_;
240  
241 118 for my $pack (@{$self->packs}) {
242 46 my ($kind, $size, $content) = $pack->get_object($sha1);
243 46 ▶ if (defined($kind) && defined($size) && defined($content)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kind and defined $size and defined $content) 46 0 46
Condition33%2/6
defined $kind and defined $size and defined $content
!ll&&!rl&&r
0046
defined $kind and defined $size
!ll&&!rl&&r
0046
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
ABCresult
0XX0
10X0
1100
1111
244 46 return $self->create_object($sha1, $kind, $size, $content);
245 }
246 }
247 }
248  
249 72 ▶sub get_object_loose {
Subroutine get_object_loose: called CC=4 SCAR=16.4
Pod documented
250 72 my ($self, $sha1) = @_;
251  
252 72 my ($kind, $size, $content) = $self->loose->get_object($sha1);
253 72 ▶ if (defined($kind) && defined($size) && defined($content)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kind and defined $size and defined $content) 72 0 72
Condition33%2/6
defined $kind and defined $size and defined $content
!ll&&!rl&&r
0072
defined $kind and defined $size
!ll&&!rl&&r
0072
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
ABCresult
0XX0
10X0
1100
1111
254 72 return $self->create_object($sha1, $kind, $size, $content);
255 }
256 }
257  
258 118 ▶sub create_object {
Subroutine create_object: called CC=5 SCAR=17.8
Pod documented
259 118 my ($self, $sha1, $kind, $size, $content) = @_;
260 118 ▶ if ($kind eq 'commit') {
Branch: 4 branches
BranchTrueFalseTotal
if ($kind eq 'commit') { } 48 70 118
elsif ($kind eq 'tree') { } 31 39 70
elsif ($kind eq 'blob') { } 39 0 39
elsif ($kind eq 'tag') { } 0 0 0
261 48 return Cogit::Object::Commit->new(
262 sha1 => $sha1,
263 kind => $kind,
264 size => $size,
265 content => $content,
266 git => $self,
267 );
268 } elsif ($kind eq 'tree') {
269 31 return Cogit::Object::Tree->new(
270 sha1 => $sha1,
271 kind => $kind,
272 size => $size,
273 content => $content,
274 git => $self,
275 );
276 } elsif ($kind eq 'blob') {
277 39 return Cogit::Object::Blob->new(
278 sha1 => $sha1,
279 kind => $kind,
280 size => $size,
281 content => $content,
282 git => $self,
283 );
284 } elsif ($kind eq 'tag') {
285 0 return Cogit::Object::Tag->new(
286 sha1 => $sha1,
287 kind => $kind,
288 size => $size,
289 content => $content,
290 git => $self,
291 );
292 } else {
293 0 confess "unknown kind $kind: $content";
294 }
295 }
296  
297 18 ▶sub all_sha1s {
Subroutine all_sha1s: called CC=2 SCAR=6.9
Pod documented
298 18 my $self = shift;
299 18 my $dir = dir($self->gitdir, 'objects');
300  
301 18 my @streams;
302 18 push @streams, $self->loose->all_sha1s;
303  
304 18 for my $pack (@{$self->packs}) {
305 4 push @streams, $pack->all_sha1s;
306 }
307  
308 18 return Data::Stream::Bulk::Cat->new(streams => \@streams);
309 }
310  
311 9 ▶sub all_objects {
Subroutine all_objects: called CC=1 SCAR=0.0
Pod undocumented
312 9 my $self = shift;
313 9 my $stream = $self->all_sha1s;
314 return Data::Stream::Bulk::Filter->new(
315 9 ▶ filter => sub { return [$self->get_objects(@$_)] },
Subroutine __ANON__: called CC=1 SCAR=0.0
316 9 stream => $stream,
317 );
318 }
319  
320 14 ▶sub put_object {
Subroutine put_object: called CC=3 SCAR=11.0
Pod undocumented
321 14 my ($self, $object, $ref) = @_;
322 14 $self->loose->put_object($object);
323  
324 14 ▶ if ($object->kind eq 'commit') {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->kind eq "commit") 4 10 14
325 4 ▶ $ref = 'master' unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 4 0 4
326 4 $self->update_ref($ref, $object->sha1);
327 }
328 }
329  
330 4 ▶sub update_ref {
Subroutine update_ref: called CC=3 SCAR=11.1
Pod undocumented
331 4 my ($self, $refname, $sha1) = @_;
332 4 my $ref = file($self->gitdir, 'refs', 'heads', $refname);
333 4 $ref->parent->mkpath;
334 4 my $ref_fh = $ref->openw;
335 4 ▶ $ref_fh->print($sha1) || die "Error writing to $ref";
Branch: 1 branch
BranchTrueFalseTotal
$ref_fh->print($sha1) or die "Error writing to $ref" 4 0 4
336  
337 # FIXME is this always what we want?
338 4 my $head = file($self->gitdir, 'HEAD');
339 4 my $head_fh = $head->openw;
340 4 ▶ $head_fh->print("ref: refs/heads/$refname")
Branch: 1 branch
BranchTrueFalseTotal
$head_fh->print("ref: refs/heads/$refname") or die "Error writing to $head" 4 0 4
341 || die "Error writing to $head";
342 }
343  
344 2 ▶sub init {
Subroutine init: called CC=5 SCAR=16.1
Pod undocumented
345 2 my ($class, %arguments) = @_;
346  
347 2 my $directory = $arguments{directory};
348 2 my $git_dir;
349  
350 2 ▶ unless (defined $directory) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $directory) { } 1 1 2
351 $git_dir = $arguments{gitdir}
352 1 ▶ || confess "init() needs either a 'directory' or a 'gitdir' argument";
Condition50%1/2
$arguments{'gitdir'} || confess(q[init() needs either a 'directory' or a 'gitdir' argument])
l!l
10
MC/DC0%0/1
$arguments{'gitdir'} || confess(q[init() needs either a 'directory' or a 'gitdir' argument])
$arguments{'gitdir'}
Truth table50%1/2
A
A= $arguments{'gitdir'}
Aresult
11
00
353 } else {
354 1 ▶ if (not defined $arguments{gitdir}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arguments{"gitdir"}) 1 0 1
355 1 $git_dir = $arguments{gitdir} = dir($directory, '.git');
356 }
357 1 dir($directory)->mkpath;
358 }
359  
360 2 dir($git_dir)->mkpath;
361 2 dir($git_dir, 'refs', 'tags')->mkpath;
362 2 dir($git_dir, 'objects', 'info')->mkpath;
363 2 dir($git_dir, 'objects', 'pack')->mkpath;
364 2 dir($git_dir, 'branches')->mkpath;
365 2 dir($git_dir, 'hooks')->mkpath;
366  
367 2 ▶ my $bare = defined($directory) ? 'false' : 'true';
Branch: 1 branch
BranchTrueFalseTotal
defined $directory ? : 1 1 2
368 2 $class->_add_file(
369 file($git_dir, 'config'),
370 "[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = $bare\n\tlogallrefupdates = true\n"
371 );
372 2 $class->_add_file(file($git_dir, 'description'),
373 "Unnamed repository; edit this file to name it for gitweb.\n");
374 2 $class->_add_file(file($git_dir, 'hooks', 'applypatch-msg'),
375 "# add shell script and make executable to enable\n");
376 2 $class->_add_file(file($git_dir, 'hooks', 'post-commit'),
377 "# add shell script and make executable to enable\n");
378 2 $class->_add_file(file($git_dir, 'hooks', 'post-receive'),
379 "# add shell script and make executable to enable\n");
380 2 $class->_add_file(file($git_dir, 'hooks', 'post-update'),
381 "# add shell script and make executable to enable\n");
382 2 $class->_add_file(file($git_dir, 'hooks', 'pre-applypatch'),
383 "# add shell script and make executable to enable\n");
384 2 $class->_add_file(file($git_dir, 'hooks', 'pre-commit'),
385 "# add shell script and make executable to enable\n");
386 2 $class->_add_file(file($git_dir, 'hooks', 'pre-rebase'),
387 "# add shell script and make executable to enable\n");
388 2 $class->_add_file(file($git_dir, 'hooks', 'update'),
389 "# add shell script and make executable to enable\n");
390  
391 2 dir($git_dir, 'info')->mkpath;
392 2 $class->_add_file(file($git_dir, 'info', 'exclude'), "# *.[oa]\n# *~\n");
393  
394 2 return $class->new(%arguments);
395 }
396  
397 5 ▶sub checkout {
Subroutine checkout: called CC=8 SCAR=24.9
Pod undocumented
398 5 my ($self, $directory, $tree) = @_;
399 5 ▶ $directory ||= $self->directory;
Condition33%1/3
$directory ||= $self->directory
l!l&&r!l&&!r
500
MC/DC0%0/2
$directory ||= $self->directory
$directory $self->directory
Truth table33%1/3
A ||= B
A= $directoryB= $self->directory
ABresult
1X1
011
000
400 5 ▶ $tree ||= $self->master->tree;
Condition33%1/3
$tree ||= $self->master->tree
l!l&&r!l&&!r
050
MC/DC0%0/2
$tree ||= $self->master->tree
$tree $self->master->tree
Truth table33%1/3
A ||= B
A= $treeB= $self->master->tree
ABresult
1X1
011
000
401 5 ▶ confess("Missing tree") unless $tree;
Branch: 1 branch
BranchTrueFalseTotal
unless $tree 0 5 5
402 5 for my $directory_entry (@{$tree->directory_entries}) {
403 7 my $filename = file($directory, $directory_entry->filename);
404 7 my $sha1 = $directory_entry->sha1;
405 7 my $mode = $directory_entry->mode;
406 7 my $object = $self->get_object($sha1);
407 7 ▶ if ($object->kind eq 'blob') {
Branch: 2 branches
BranchTrueFalseTotal
if ($object->kind eq 'blob') { } 7 0 7
elsif ($object->kind eq 'tree') { } 0 0 0
408 7 $self->_add_file($filename, $object->content);
409 7 ▶ chmod(oct('0' . $mode), $filename)
Branch: 1 branch
BranchTrueFalseTotal
chmod oct '0' . $mode, $filename or die "Error chmoding $filename to ${mode}: $!" 7 0 7
410 || die "Error chmoding $filename to $mode: $!";
411 } elsif ($object->kind eq 'tree') {
412 0 dir($filename)->mkpath;
413 0 $self->checkout($filename, $object);
414 } else {
415 0 die $object->kind;
416 }
417 }
418 }
419  
420 0 ▶sub clone {
Subroutine clone: not called CC=3 SCAR=24.8
Pod undocumented
421 0 my $self = shift;
422  
423 0 my $remote;
424 0 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 0 0 0
425  
426 # For backwards compatibility
427 0 $remote = "git://$_[0]";
428 0 ▶ $remote .= "/" unless $_[1] =~ m{^/};
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] =~ m[^/] 0 0 0
429 0 $remote .= $_[1];
430 } else {
431 0 $remote = shift;
432 }
433  
434 0 my $protocol = Cogit::Protocol->new(remote => $remote)->connect;
435  
436 0 my $sha1s = $protocol->fetch;
437 0 my $head = $sha1s->{HEAD};
438 0 my $data = $protocol->fetch_pack($head);
439  
440 0 my $filename =
441 file($self->gitdir, 'objects', 'pack', 'pack-' . $head . '.pack');
442 0 $self->_add_file($filename, $data);
443  
444 0 my $pack = Cogit::Pack::WithoutIndex->new(filename => $filename);
445 0 $pack->create_index();
446  
447 0 $self->update_ref(master => $head);
448 }
449  
450 29 ▶sub _add_file {
Subroutine _add_file: called CC=4 SCAR=14.6
451 29 my ($class, $filename, $contents) = @_;
452 29 ▶ my $fh = $filename->openw || confess "Error opening to $filename: $!";
Condition50%1/2
$filename->openw || confess("Error opening to ${filename}: $!")
l!l
290
MC/DC0%0/1
$filename->openw || confess("Error opening to ${filename}: $!")
$filename->openw
Truth table50%1/2
A
A= $filename->openw
Aresult
11
00
453 29 binmode($fh); #important for Win32
454 29 ▶ $fh->print($contents) || confess "Error writing to $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->print($contents) or confess("Error writing to ${filename}: $!") 29 0 29
455 29 ▶ $fh->close || confess "Error closing $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->close or confess("Error closing ${filename}: $!") 29 0 29
456 }
457  
458 4 1;
459  
460 __END__
« Cogit/PackIndex/Version1.pm ↑ Summary Cogit/Object/Commit.pm »