LowLevel/Tree.pm

filter: Statementstmt 64.2% 79 / 123 Branchbran 41.6% 15 / 36 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 77.7% 14 / 18 Podpod 100% 13 / 13 totaltotal 63.0% 126 / 200 CC 28 SCAR 25.8
CC
28
Cov
59%
del
56.0
timestamp_added
12.0
timestamp_last
12.0
CRAP 13.2
↑ Summary LowLevel/Blob.pm »
1 package Git::LowLevel::Tree;
2 # ABSTRACT: class representing a tree object in a GIT Repository
3 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use MooseX::Privacy;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Git::LowLevel::Blob;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 has 'repository' => (is => 'ro', isa => 'Git::LowLevel', required => 1);
9  
10 4 has 'reference' => (is => 'ro', isa => 'Git::LowLevel::Reference', required => 1);
11  
12 4 has 'path' => (is => 'rw',isa=>'Str', default=> '.');
13  
14 4 has 'hash' => (is => 'rw', isa => 'Str', required => 1);
15  
16 8 ▶has 'tree' => (is => 'rw',isa=> 'ArrayRef', default=> sub {return [];});
Subroutine __ANON__: called CC=1 SCAR=0.0
17  
18 4 has 'parent' => (is => 'rw', isa => 'Git::LowLevel::Tree');
19  
20  
21 4 has 'changed' => (is => 'rw', isa => 'Bool', default=>0);
22  
23 sub timestamp_added
24 {
25 0 ▶ my $self = shift;
Subroutine timestamp_added: not called CC=3 SCAR=24.8
Pod documented
26 0 my $help = readpipe($self->repository->gitcmd() . " log --follow --diff-filter=A --date=raw " . $self->reference->reference . " -- \"" . $self->path . "\" 2>/dev/null");
27 0 my @lines = split /\n/,$help;
28 0 for my $line (@lines)
29 {
30 0 ▶ if ($line =~ /^Date:\s+(\d+)\s([+-]\d+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Date:\s+(\d+)\s([+-]\d+)$/) 0 0 0
31 {
32 0 return $1;
33 }
34 }
35  
36 0 return $help;
37 }
38  
39 sub timestamp_last
40 {
41 0 ▶ my $self = shift;
Subroutine timestamp_last: not called CC=3 SCAR=24.8
Pod documented
42 0 my $help = readpipe($self->repository->gitcmd() . " log --follow --date=raw " . $self->reference->reference . " -- \"" . $self->path . "\" 2>/dev/null");
43 0 my @lines = split /\n/,$help;
44 0 for my $line (@lines)
45 {
46 0 ▶ if ($line =~ /^Date:\s+(\d+)\s([+-]\d+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Date:\s+(\d+)\s([+-]\d+)$/) 0 0 0
47 {
48 0 return $1;
49 }
50 }
51  
52 0 return $help;
53 }
54  
55 sub committer
56 {
57 0 ▶ my $self = shift;
Subroutine committer: not called CC=3 SCAR=24.8
Pod documented
58 0 my $help = readpipe($self->repository->gitcmd() . " log --follow --date=raw " . $self->reference->reference . " -- \"" . $self->path . "\" 2>/dev/null");
59 0 my @lines = split /\n/,$help;
60 0 for my $line (@lines)
61 {
62 0 ▶ if ($line =~ /^Author:\s(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Author:\s(.*)$/) 0 0 0
63 {
64 0 return $1;
65 }
66 }
67  
68 0 return $help;
69 }
70  
71  
72 sub mypath
73 {
74 6 ▶ my $self = shift;
Subroutine mypath: called CC=1 SCAR=0.0
Pod documented
75 6 my $path = basename($self->path);
76  
77 6 return $path;
78 }
79  
80 sub get
81 {
82 13 ▶ my $self = shift;
Subroutine get: called CC=4 SCAR=15.2
Pod documented
83 13 my @ret;
84  
85 13 ▶ return @{$self->tree} unless @{$self->tree} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->tree;} == 0 5 8 13
86  
87 8 my $help = readpipe($self->repository->gitcmd() . " ls-tree " . $self->reference->reference . " \"" . $self->path . "/\" 2>/dev/null");
88 8 my @lines = split /\n/,$help;
89 8 for my $line (@lines)
90 {
91 0 $line =~ /^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
92  
93 0 ▶ if ($2 eq "blob")
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq 'blob') { } 0 0 0
94 {
95 0 push(@ret, Git::LowLevel::Blob->new(repository=>$self->repository, hash => $3, path => $4, parent=>$self));
96 }
97 else
98 {
99 0 push(@ret, Git::LowLevel::Tree->new(repository=>$self->repository, reference=> $self->reference, hash => $3, path => $4 . "/", parent=>$self));
100 }
101  
102 }
103 8 $self->tree(\@ret);
104  
105 8 return @ret;
106 }
107  
108 sub empty
109 {
110 5 ▶ my $self = shift;
Subroutine empty: called CC=2 SCAR=6.9
Pod documented
111 5 $self->get();
112  
113 5 ▶ if (@{$self->tree} == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->tree;} == 0) 3 2 5
114 {
115 3 return 1;
116 }
117  
118 2 return 0;
119 }
120  
121 sub newBlob
122 {
123 3 ▶ my $self = shift;
Subroutine newBlob: called CC=1 SCAR=0.0
Pod documented
124  
125 3 return Git::LowLevel::Blob->new(repository => $self->repository);
126 }
127  
128 sub newTree
129 {
130 1 ▶ my $self = shift;
Subroutine newTree: called CC=1 SCAR=0.0
Pod documented
131  
132 1 return Git::LowLevel::Tree->new(repository => $self->repository, reference => $self->reference, hash=>"empty", changed => 1);
133 }
134  
135 sub add
136 {
137 6 ▶ my $self = shift;
Subroutine add: called CC=6 SCAR=18.0
Pod documented
138 6 my $elem = shift;
139  
140 6 ▶ die("no supported object type " . ref($elem)) unless ref($elem) eq 'Git::LowLevel::Blob' || ref($elem) eq 'Git::LowLevel::Tree';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $elem eq "Git::LowLevel::Blob" or ref $elem eq "Git::LowLevel::Tree" 2 4 6
Condition100%3/3
ref $elem eq "Git::LowLevel::Blob" or ref $elem eq "Git::LowLevel::Tree"
l!l&&r!l&&!r
312
MC/DC100%2/2
ref $elem eq "Git::LowLevel::Blob" or ref $elem eq "Git::LowLevel::Tree"
ref $elem eq "Git::LowLevel::Blob" ref $elem eq "Git::LowLevel::Tree"
Truth table100%3/3
A or B
A= ref $elem eq "Git::LowLevel::Blob"B= ref $elem eq "Git::LowLevel::Tree"
ABresult
1X1
011
000
141  
142 4 ▶ if (ref($elem) eq "Git::LowLevel::Blob")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $elem eq "Git::LowLevel::Blob") 3 1 4
143 {
144 3 ▶ die("path missing in Blob") unless length($elem->path)>0;
Branch: 1 branch
BranchTrueFalseTotal
unless length $elem->path > 0 0 3 3
145 3 ▶ die("content missing in Blob") unless length($elem->_content)>0;
Branch: 1 branch
BranchTrueFalseTotal
unless length $elem->_content > 0 0 3 3
146 }
147  
148 4 $self->get();
149 4 $self->changed(1);
150 4 $elem->parent($self);
151 4 push(@{$self->tree}, $elem);
152 }
153  
154 sub del
155 {
156 0 ▶ my $self = shift;
Subroutine del: not called CC=7 SCAR=40.3
Pod documented
157 0 my $elem = shift;
158  
159 0 ▶ die("no supported object type " . ref($elem)) unless ref($elem) eq 'Git::LowLevel::Blob' || ref($elem) eq 'Git::LowLevel::Tree';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $elem eq "Git::LowLevel::Blob" or ref $elem eq "Git::LowLevel::Tree" 0 0 0
Condition0%0/3
ref $elem eq "Git::LowLevel::Blob" or ref $elem eq "Git::LowLevel::Tree"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $elem eq "Git::LowLevel::Blob" or ref $elem eq "Git::LowLevel::Tree"
ref $elem eq "Git::LowLevel::Blob" ref $elem eq "Git::LowLevel::Tree"
Truth table0%0/3
A or B
A= ref $elem eq "Git::LowLevel::Blob"B= ref $elem eq "Git::LowLevel::Tree"
ABresult
1X1
011
000
160  
161 0 $self->get();
162 0 my @tree;
163 0 for my $t (@{$self->tree})
164 {
165 0 my $path = fileparse($t->path);
166 0 ▶ if (length($path)==0)
Branch: 1 branch
BranchTrueFalseTotal
if (length $path == 0) 0 0 0
167 {
168 0 $path = $t->path;
169 0 $path =~ s/\///;
170 }
171  
172 0 my $path2 = fileparse($elem->path);
173 0 ▶ if (length($path2)==0)
Branch: 1 branch
BranchTrueFalseTotal
if (length $path2 == 0) 0 0 0
174 {
175 0 $path2 = $elem->path;
176 0 $path2 =~ s/\///;
177 }
178  
179 0 ▶ if ($path ne $path2)
Branch: 1 branch
BranchTrueFalseTotal
if ($path ne $path2) 0 0 0
180 {
181 0 push(@tree,$t);
182 }
183  
184 }
185 0 $self->changed(1);
186 0 $self->tree(\@tree);
187  
188 }
189  
190 sub save
191 {
192 4 ▶ my $self = shift;
Subroutine save: called CC=3 SCAR=11.0
Pod documented
193 4 my $str = "";
194  
195 4 for my $t (@{$self->tree})
196 {
197 4 $t->save;
198 4 $str .= $t->treeEntry;
199 }
200  
201 4 ▶ if ($self->changed()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->changed) 4 0 4
202 4 my $help = readpipe("/bin/echo -e \"" . $str. "\" | " . $self->repository->gitcmd() . " mktree --batch ");
203 4 chomp($help);
204 4 $self->hash($help);
205 4 $self->changed(0);
206 }
207  
208 }
209 sub treeEntry
210 {
211 1 ▶ my $self = shift;
Subroutine treeEntry: called CC=2 SCAR=7.1
Pod documented
212  
213 1 ▶ return "" unless $self->hash ne "empty";
Branch: 1 branch
BranchTrueFalseTotal
unless $self->hash ne "empty" 0 1 1
214  
215 1 return "040000 tree " . $self->hash . "\t" . $self->mypath() . "\n";
216 }
217  
218  
219 sub find
220 {
221 5 ▶ my $self = shift;
Subroutine find: called CC=4 SCAR=13.9
Pod documented
222 5 my $path = shift;
223  
224 5 ▶ return $self unless $self->mypath ne $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->mypath ne $path 1 4 5
225  
226 4 $self->get();
227 4 for my $t (@{$self->tree})
228 {
229 3 my $r = $t->find($path);
230 3 ▶ if (defined($r))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r) 3 0 3
231 {
232 3 return $r;
233 }
234 }
235  
236 1 return;
237 }
238  
239 4 1;
240  
241 __END__
242  
243 =pod
244  
245 =encoding UTF-8
246  
247 =head1 NAME
248  
249 Git::LowLevel::Tree - class representing a tree object in a GIT Repository
250  
251 =head1 VERSION
252  
253 version 0.3
254  
255 =head1 ATTRIBUTES
256  
257 =head2 repository
258  
259 the repository the tree lives in
260  
261 =head2 reference
262  
263 the reference the tree lives in
264  
265 =head2 path
266  
267 the path to the tree object
268  
269 =head2 hash
270  
271 the hash identifying the tree object
272  
273 =head2 tree
274  
275 the tree entries
276  
277 =head2 parent
278  
279 the parent of the object within the tree
280  
281 =head2 changed
282  
283 identifies if the tree has been changed
284 add,del or initial create of the tree
285  
286 =head1 METHODS
287  
288 =head2 timestamp_added
289  
290 returns the timestamp of the commit where this object was added or undef if
291 object has not been commited yet.
292  
293 =head2 timestamp_last
294  
295 returns the timestamp of the last commit of this object or undef if
296 object has not been commited yet.
297  
298 =head2 committer
299  
300 returns the committer of the the object
301  
302 =head2 mypath
303  
304 =head2 get
305  
306 returns an array of all the tree objects
307  
308 =head2 empty
309  
310 tests if the tree is empty
311  
312 =head2 newBlob
313  
314 create a new blob entry
315  
316 =head2 newTree
317  
318 create a new tree entry
319  
320 =head2 add
321  
322 add a new tree element
323  
324 =head2 del
325  
326 delete an element from the tree
327  
328 =head2 save
329  
330 save the full tree to the git object safe
331  
332 =head2 treeEntry
333  
334 return a string representing a tree entry
335  
336 =head2 find
337  
338 find a path within the tree
339  
340 =head1 AUTHOR
341  
342 Dominik Meyer <dmeyer@federationhq.de>
343  
344 =head1 COPYRIGHT AND LICENSE
345  
346 This software is Copyright (c) 2018 by Dominik Meyer.
347  
348 This is free software, licensed under:
349  
350 The GNU General Public License, Version 2, June 1991
351  
352 =cut
↑ Summary LowLevel/Blob.pm »