| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
timestamp_added: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 0 | return $1; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | return $help; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub timestamp_last | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
timestamp_last: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 0 | return $1; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | return $help; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub committer | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
committer: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | 0 | return $1; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | return $help; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub mypath | ||||||||||||||||||||||||||||
| 73 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
mypath: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 6 | my $path = basename($self->path); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 6 | return $path; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub get | ||||||||||||||||||||||||||||
| 81 | 13 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | 13 | my @ret; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 13 | ▶ | return @{$self->tree} unless @{$self->tree} == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
empty: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 111 | 5 | $self->get(); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 5 | ▶ | if (@{$self->tree} == 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 3 | return 1; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | return 0; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | sub newBlob | ||||||||||||||||||||||||||||
| 122 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
newBlob: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 3 | return Git::LowLevel::Blob->new(repository => $self->repository); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub newTree | ||||||||||||||||||||||||||||
| 129 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
newTree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | return Git::LowLevel::Tree->new(repository => $self->repository, reference => $self->reference, hash=>"empty", changed => 1); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub add | ||||||||||||||||||||||||||||
| 136 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 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
Condition100%3/3
ref $elem eq "Git::LowLevel::Blob" or ref $elem eq "Git::LowLevel::Tree"
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"
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 4 | ▶ | if (ref($elem) eq "Git::LowLevel::Blob") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||
| 144 | 3 | ▶ | die("path missing in Blob") unless length($elem->path)>0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 3 | ▶ | die("content missing in Blob") unless length($elem->_content)>0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
del: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $elem eq "Git::LowLevel::Blob" or ref $elem eq "Git::LowLevel::Tree"
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"
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | $self->get(); | |||||||||||||||||||||||||||
| 162 | 0 | my @tree; | |||||||||||||||||||||||||||
| 163 | 0 | for my $t (@{$self->tree}) | |||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ($t->mypath ne $elem->mypath) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||
| 167 | 0 | push(@tree,$t); | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 0 | $self->changed(1); | |||||||||||||||||||||||||||
| 172 | 0 | $self->tree(\@tree); | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | sub save | ||||||||||||||||||||||||||||
| 177 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
save: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 178 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 179 | 4 | my $str = ""; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 4 | for my $t (@{$self->tree}) | |||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||
| 183 | 4 | $t->save; | |||||||||||||||||||||||||||
| 184 | 4 | $str .= $t->treeEntry; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 4 | ▶ | if ($self->changed()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 4 | my $help = readpipe("/bin/echo -e \"" . $str. "\" | " . $self->repository->gitcmd() . " mktree --batch "); | |||||||||||||||||||||||||||
| 189 | 4 | chomp($help); | |||||||||||||||||||||||||||
| 190 | 4 | $self->hash($help); | |||||||||||||||||||||||||||
| 191 | 4 | $self->changed(0); | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | sub treeEntry | ||||||||||||||||||||||||||||
| 196 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
treeEntry: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 1 | ▶ | return "" unless $self->hash ne "empty"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 1 | return "040000 tree " . $self->hash . "\t" . $self->mypath() . "\n"; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | sub find | ||||||||||||||||||||||||||||
| 206 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 207 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 208 | 5 | my $path = shift; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 5 | ▶ | return $self unless $self->mypath ne $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 4 | $self->get(); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 4 | for my $t (@{$self->tree}) | |||||||||||||||||||||||||||
| 215 | { | ||||||||||||||||||||||||||||
| 216 | 3 | my $r = $t->find($path); | |||||||||||||||||||||||||||
| 217 | 3 | ▶ | if (defined($r)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||
| 219 | 3 | return $r; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 1 | return; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 4 | 1; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | __END__ | ||||||||||||||||||||||||||||