| 1 | package Git::LowLevel::Blob; | ||||||||||||||||||||||||||||
| 2 | #ABSTRACT: class representing a GIT Blow Object | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | has 'repository' => (is => 'ro', isa => 'Git::LowLevel', required => 1); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | has 'hash' => (is => 'rw', isa => 'Str'); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | has 'path' => (is => 'rw', isa => 'Str'); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | has 'parent' => (is => 'rw', isa => 'Git::LowLevel::Tree'); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | has '_content' => (is =>'rw'); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub timestamp_added | ||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
timestamp_added: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 0 | my $help = readpipe($self->repository->gitcmd() . " log --follow --diff-filter=A --date=raw " . $self->reference->reference . " -- \"" . $self->path . "\" 2>/dev/null"); | |||||||||||||||||||||||||||
| 24 | 0 | my @lines = split /\n/,$help; | |||||||||||||||||||||||||||
| 25 | 0 | for my $line (@lines) | |||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($line =~ /^Date:\s+(\d+)\s([+-]\d+)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 0 | return $1; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | return $help; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub timestamp_last | ||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
timestamp_last: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my $help = readpipe($self->repository->gitcmd() . " log --follow --date=raw " . $self->reference->reference . " -- \"" . $self->path . "\" 2>/dev/null"); | |||||||||||||||||||||||||||
| 40 | 0 | my @lines = split /\n/,$help; | |||||||||||||||||||||||||||
| 41 | 0 | for my $line (@lines) | |||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($line =~ /^Date:\s+(\d+)\s([+-]\d+)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 0 | return $1; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | return $help; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | sub committer | ||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
committer: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | my $help = readpipe($self->repository->gitcmd() . " log --follow --date=raw " . $self->reference->reference . " -- \"" . $self->path . "\" 2>/dev/null"); | |||||||||||||||||||||||||||
| 56 | 0 | my @lines = split /\n/,$help; | |||||||||||||||||||||||||||
| 57 | 0 | for my $line (@lines) | |||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($line =~ /^Author:\s(.*)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 0 | return $1; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | return $help; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub mypath | ||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||
| 70 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
mypath: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 5 | my $path = fileparse($self->path); | |||||||||||||||||||||||||||
| 72 | 5 | ▶ | if (!defined($path) || length($path)==0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $path or length $path == 0
MC/DC0%0/2
not defined $path or length $path == 0
not defined $path
length $path == 0
Truth table33%1/3
not(A) or B
A= not defined $pathB= length $path == 0
| |||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||
| 74 | 0 | $path = $self->path; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 5 | $path=~s/\///g; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 5 | return $path; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub content | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2 | my $help = readpipe($self->repository->gitcmd() . " cat-file blob " . $self->hash); | |||||||||||||||||||||||||||
| 89 | 2 | chomp($help); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 2 | $self->_content($help); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | return $help; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub save | ||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
save: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 3 | ▶ | return unless defined($self->_content()) && length($self->_content)>0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->_content and length $self->_content > 0
MC/DC0%0/2
defined $self->_content and length $self->_content > 0
defined $self->_content
length $self->_content > 0
Truth table33%1/3
A and B
A= defined $self->_contentB= length $self->_content > 0
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | #TODO: perhaps do not use stdin ... better for binary files | ||||||||||||||||||||||||||||
| 104 | 3 | my $help = readpipe("echo \'".$self->_content."\' |" . $self->repository->gitcmd() . " hash-object -w --stdin "); | |||||||||||||||||||||||||||
| 105 | 3 | chomp($help); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 3 | $self->hash($help); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub treeEntry | ||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||
| 113 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
treeEntry: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 3 | ▶ | if (defined($self->hash) && length($self->hash)>30 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->hash and length $self->hash > 30
MC/DC0%0/2
defined $self->hash and length $self->hash > 30
defined $self->hash
length $self->hash > 30
Truth table33%1/3
A and B
A= defined $self->hashB= length $self->hash > 30
| |||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | 3 | return "100644 blob " . $self->hash . "\t" . $self->mypath . "\n"; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | return ""; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | sub find | ||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||
| 125 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 2 | my $path = shift; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 2 | ▶ | return $self unless $self->mypath ne $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | return; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub del | ||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
del: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | $self->_content(""); | |||||||||||||||||||||||||||
| 138 | 0 | $self->hash(" "); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 4 | 1; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =pod | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 NAME | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Git::LowLevel::Blob - class representing a GIT Blow Object | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head1 VERSION | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | version 0.3 | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | Class representing a Blob object within the Git::LowLevel distribution. | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | Blobs in B<git> normally hold any type of file data. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head2 repository | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | the repository the blob lives in | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =head2 hash | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | the hash identifying the blob, only set if the blob exist/is created in the repository | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head2 path | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | the path identifying the blob | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =head2 parent | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | the parent of the object within the tree | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =head1 METHODS | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head2 timestamp_added | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | returns the timestamp of the commit where this object was added or undef if | ||||||||||||||||||||||||||||
| 187 | object has not been commited yet. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =head2 timestamp_last | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | returns the timestamp of the last commit of this object or undef if | ||||||||||||||||||||||||||||
| 192 | object has not been commited yet. | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =head2 committer | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | returns the committer of the the object | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =head2 mypath | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =head2 content | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | return the content of the Blob | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =head2 save | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | save content to git object and update hash | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =head2 treeEntry | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | return a string representing a tree entry | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =head2 find | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | find a path within the tree | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =head2 del | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | delete the blob | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | Dominik Meyer <dmeyer@federationhq.de> | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | This software is Copyright (c) 2018 by Dominik Meyer. | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | The GNU General Public License, Version 2, June 1991 | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =cut | ||||||||||||||||||||||||||||