| 1 | package Git::ObjectStore; | ||||||||||||||||||||||||||||
| 2 | 1 | $Git::ObjectStore::VERSION = '0.007'; | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Git::Raw; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Git::Raw::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # ABSTRACT: abstraction layer for Git::Raw and libgit2 | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub new | ||||||||||||||||||||||||||||
| 18 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 3 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 20 | 3 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | $self->{'author_name'} = 'ObjectStore'; | |||||||||||||||||||||||||||
| 23 | 3 | $self->{'author_email'} = 'ObjectStore@localhost'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | foreach my $arg (qw(repodir branchname)) { | |||||||||||||||||||||||||||
| 26 | 6 | ▶ | if ( defined( $args{$arg} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 6 | $self->{$arg} = $args{$arg}; | |||||||||||||||||||||||||||
| 28 | } else { | ||||||||||||||||||||||||||||
| 29 | 0 | croak('Mandatory argument missing: ' . $arg); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | foreach my $arg (qw(writer author_name author_email)) { | |||||||||||||||||||||||||||
| 34 | 9 | ▶ | if ( defined( $args{$arg} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 1 | $self->{$arg} = $args{$arg}; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | ▶ | if ( $self->{'writer'} and $args{'goto'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"writer"} and $args{"goto"}
MC/DC0%0/2
$self->{"writer"} and $args{"goto"}
$self->{"writer"}
$args{"goto"}
Truth table66%2/3
A and B
A= $self->{"writer"}B= $args{"goto"}
| |||||||||||||||||||||||||||||
| 40 | 0 | croak('Cannot use goto in writer mode'); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | my $branchname = $self->{'branchname'}; | |||||||||||||||||||||||||||
| 44 | 3 | my $repodir = $self->{'repodir'}; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | if ( not -e $repodir . '/config' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | if( $self->{'writer'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 1 | Git::Raw::Repository->init($repodir, 1); | |||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 0 | croak($repodir . ' does not contain a bare Git repository'); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | my $repo = $self->{'repo'} = Git::Raw::Repository->open($repodir); | |||||||||||||||||||||||||||
| 55 | 3 | my $objdir = catfile($repodir, 'objects'); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # We do not use loose backend, so we explicitly exclude it from ODB. | ||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 3 | my $odb = Git::Raw::Odb->new(); | |||||||||||||||||||||||||||
| 60 | 3 | $odb->add_backend(Git::Raw::Odb::Backend::Pack->new($objdir), 10); | |||||||||||||||||||||||||||
| 61 | 3 | $repo->odb($odb); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | if ( $self->{'writer'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | my $refname = 'refs/heads/' . $branchname; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # in-memory store that will write a single pack file for all objects | ||||||||||||||||||||||||||||
| 69 | 1 | $self->{'packdir'} = catfile($objdir, 'pack'); | |||||||||||||||||||||||||||
| 70 | 1 | my $mempack = $self->{'mempack'} = Git::Raw::Mempack->new; | |||||||||||||||||||||||||||
| 71 | 1 | $repo->odb->add_backend($mempack, 99); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | my $branch = Git::Raw::Branch->lookup($repo, $branchname, 1); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | ▶ | if( defined($branch) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | # If previous run of the writer crashed, we have a reference that | ||||||||||||||||||||||||||||
| 78 | # points to nonexistent commit, because mempack was not written. | ||||||||||||||||||||||||||||
| 79 | 0 | eval { $branch->peel('commit') }; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 0 | $branch = undef; | |||||||||||||||||||||||||||
| 83 | 0 | Git::Raw::Reference->lookup($refname, $repo)->delete(); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | if ( not defined($branch) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | # This is a fresh repo, create the branch | ||||||||||||||||||||||||||||
| 89 | 1 | my $builder = Git::Raw::Tree::Builder->new($repo); | |||||||||||||||||||||||||||
| 90 | 1 | my $tree = $builder->write(); | |||||||||||||||||||||||||||
| 91 | 1 | my $me = $self->_signature(); | |||||||||||||||||||||||||||
| 92 | 1 | my $commit = $repo->commit("Initial empty commit in $branchname", | |||||||||||||||||||||||||||
| 93 | $me, $me, [], $tree, $refname); | ||||||||||||||||||||||||||||
| 94 | 1 | $self->{'created_init_commit'} = $commit; | |||||||||||||||||||||||||||
| 95 | 1 | $branch = Git::Raw::Branch->lookup($repo, $branchname, 1); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | croak('expected a branch') unless defined($branch); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # in-memory index for preparing a commit | ||||||||||||||||||||||||||||
| 101 | 1 | my $index = Git::Raw::Index->new(); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # assign the index to our repo | ||||||||||||||||||||||||||||
| 104 | 1 | $repo->index($index); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # initiate the index with the top of the branch | ||||||||||||||||||||||||||||
| 107 | 1 | my $commit = $branch->peel('commit'); | |||||||||||||||||||||||||||
| 108 | 1 | $index->read_tree($commit->tree()); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # memorize the index for quick write access | ||||||||||||||||||||||||||||
| 111 | 1 | $self->{'gitindex'} = $index; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | $self->{'current_commit_id'} = $commit->id(); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||
| 116 | # open the repo for read-only access | ||||||||||||||||||||||||||||
| 117 | 2 | my $commit; | |||||||||||||||||||||||||||
| 118 | 2 | ▶ | if ( defined($args{'goto'}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | # read from a specified commit | ||||||||||||||||||||||||||||
| 120 | 0 | $commit = Git::Raw::Commit->lookup($repo, $args{'goto'}); | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | croak('Cannot lookup commit ' . $args{'goto'}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | unless defined($commit); | ||||||||||||||||||||||||||||
| 123 | } else { | ||||||||||||||||||||||||||||
| 124 | # read from the top of the branch | ||||||||||||||||||||||||||||
| 125 | 2 | my $branch = Git::Raw::Branch->lookup($repo, $branchname, 1); | |||||||||||||||||||||||||||
| 126 | 2 | $commit = $branch->peel('commit'); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # memorize the tree that we will read | ||||||||||||||||||||||||||||
| 130 | 2 | $self->{'gittree'} = $commit->tree(); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 2 | $self->{'current_commit_id'} = $commit->id(); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 3 | return $self; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | sub _signature | ||||||||||||||||||||||||||||
| 140 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_signature: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 141 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 142 | return Git::Raw::Signature->now | ||||||||||||||||||||||||||||
| 143 | 3 | ($self->{'author_name'}, $self->{'author_email'}); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | sub created_init_commit | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
created_init_commit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 151 | 0 | return $self->{'created_init_commit'}; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub repo | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
repo: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 160 | 0 | return $self->{'repo'}; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | sub read_file | ||||||||||||||||||||||||||||
| 168 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
read_file: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 169 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 170 | 6 | my $filename = shift; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 6 | ▶ | if ( $self->{'writer'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 2 | my $entry = $self->{'gitindex'}->find($filename); | |||||||||||||||||||||||||||
| 174 | 2 | ▶ | if ( defined($entry) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 1 | return $entry->blob()->content(); | |||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||
| 177 | 1 | return undef; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||
| 180 | 4 | my $entry = $self->{'gittree'}->entry_bypath($filename); | |||||||||||||||||||||||||||
| 181 | 4 | ▶ | if ( defined($entry) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 4 | return $entry->object()->content(); | |||||||||||||||||||||||||||
| 183 | } else { | ||||||||||||||||||||||||||||
| 184 | 0 | return undef; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | sub file_exists | ||||||||||||||||||||||||||||
| 192 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
file_exists: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 194 | 2 | my $filename = shift; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 2 | ▶ | if ( $self->{'writer'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 2 | return defined($self->{'gitindex'}->find($filename)); | |||||||||||||||||||||||||||
| 198 | } else { | ||||||||||||||||||||||||||||
| 199 | 0 | return defined($self->{'gittree'}->entry_bypath($filename)); | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | sub current_commit_id | ||||||||||||||||||||||||||||
| 205 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
current_commit_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 206 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 207 | 4 | return $self->{'current_commit_id'}; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub write_and_check | ||||||||||||||||||||||||||||
| 213 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
write_and_check: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 215 | 2 | my $filename = shift; | |||||||||||||||||||||||||||
| 216 | 2 | my $data = shift; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | croak('write_and_check() is called for a read-only ObjectStore object') | ||||||||||||||||||||||||||||
| 219 | 2 | ▶ | unless $self->{'writer'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 2 | my $prev_blob_id = ''; | |||||||||||||||||||||||||||
| 222 | 2 | ▶ | if( defined(my $entry = $self->{'gitindex'}->find($filename)) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 1 | $prev_blob_id = $entry->blob()->id(); | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 2 | my $entry = $self->{'gitindex'}->add_frombuffer($filename, $data); | |||||||||||||||||||||||||||
| 227 | 2 | my $new_blob_id = $entry->blob()->id(); | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 2 | return ($new_blob_id ne $prev_blob_id); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | sub write_file | ||||||||||||||||||||||||||||
| 235 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
write_file: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 236 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 237 | 7 | my $filename = shift; | |||||||||||||||||||||||||||
| 238 | 7 | my $data = shift; | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | croak('write_file() is called for a read-only ObjectStore object') | ||||||||||||||||||||||||||||
| 241 | 7 | ▶ | unless $self->{'writer'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 7 | $self->{'gitindex'}->add_frombuffer($filename, $data); | |||||||||||||||||||||||||||
| 244 | 7 | return; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | sub delete_file | ||||||||||||||||||||||||||||
| 250 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
delete_file: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 251 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 252 | 2 | my $path = shift; | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | croak('delete_file() is called for a read-only ObjectStore object') | ||||||||||||||||||||||||||||
| 255 | 2 | ▶ | unless $self->{'writer'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 2 | $self->{'gitindex'}->remove($path); | |||||||||||||||||||||||||||
| 257 | 2 | return; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | sub create_commit | ||||||||||||||||||||||||||||
| 263 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
create_commit: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 264 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 265 | 3 | my $msg = shift; | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | croak('create_commit() is called for a read-only ObjectStore object') | ||||||||||||||||||||||||||||
| 268 | 3 | ▶ | unless $self->{'writer'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 3 | ▶ | if( not defined($msg) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 3 | $msg = scalar(localtime(time())); | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 3 | my $branchname = $self->{'branchname'}; | |||||||||||||||||||||||||||
| 275 | 3 | my $repo = $self->{'repo'}; | |||||||||||||||||||||||||||
| 276 | 3 | my $index = $self->{'gitindex'}; | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 3 | my $branch = Git::Raw::Branch->lookup($self->{'repo'}, $branchname, 1); | |||||||||||||||||||||||||||
| 279 | 3 | my $parent = $branch->peel('commit'); | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | # this creates a new tree object from changes in the index | ||||||||||||||||||||||||||||
| 282 | 3 | my $tree = $index->write_tree(); | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 3 | ▶ | if( $tree->id() eq $parent->tree()->id() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | # The tree identifier has not changed, hence there are no | ||||||||||||||||||||||||||||
| 286 | # changes in content | ||||||||||||||||||||||||||||
| 287 | 1 | return 0; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 2 | my $me = $self->_signature(); | |||||||||||||||||||||||||||
| 291 | 2 | my $commit = $repo->commit | |||||||||||||||||||||||||||
| 292 | ($msg, $me, $me, [$parent], $tree, $branch->name()); | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | # re-initialize the index | ||||||||||||||||||||||||||||
| 295 | 2 | $index->clear(); | |||||||||||||||||||||||||||
| 296 | 2 | $index->read_tree($tree); | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 2 | $self->{'current_commit_id'} = $commit->id(); | |||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 2 | return 1; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | sub write_packfile | ||||||||||||||||||||||||||||
| 306 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
write_packfile: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 307 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | croak('write_packfile() is called for a read-only ObjectStore object') | ||||||||||||||||||||||||||||
| 310 | 3 | ▶ | unless $self->{'writer'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 3 | my $repo = $self->{'repo'}; | |||||||||||||||||||||||||||
| 313 | 3 | my $tp = Git::Raw::TransferProgress->new(); | |||||||||||||||||||||||||||
| 314 | 3 | my $indexer = Git::Raw::Indexer->new($self->{'packdir'}, $repo->odb()); | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 3 | $indexer->append($self->{'mempack'}->dump($repo), $tp); | |||||||||||||||||||||||||||
| 317 | 3 | $indexer->commit($tp); | |||||||||||||||||||||||||||
| 318 | 3 | $self->{'mempack'}->reset; | |||||||||||||||||||||||||||
| 319 | 3 | return; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | sub create_commit_and_packfile | ||||||||||||||||||||||||||||
| 325 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
create_commit_and_packfile: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 326 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 327 | 3 | my $msg = shift; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 3 | ▶ | if( $self->create_commit($msg) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 330 | 2 | $self->write_packfile(); | |||||||||||||||||||||||||||
| 331 | 2 | return 1; | |||||||||||||||||||||||||||
| 332 | } elsif ( defined($self->{'created_init_commit'}) ) { | ||||||||||||||||||||||||||||
| 333 | 1 | $self->write_packfile(); | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 1 | return 0; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | sub recursive_read | ||||||||||||||||||||||||||||
| 342 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
recursive_read: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||
| 343 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 344 | 4 | my $path = shift; | |||||||||||||||||||||||||||
| 345 | 4 | my $callback = shift; | |||||||||||||||||||||||||||
| 346 | 4 | my $no_content = shift; | |||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | croak('recursive_read() is called for a read-write ObjectStore object') | ||||||||||||||||||||||||||||
| 349 | 4 | ▶ | if $self->{'writer'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 4 | ▶ | if( $path eq '' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||
| 353 | 2 | foreach my $entry ($self->{'gittree'}->entries()) { | |||||||||||||||||||||||||||
| 354 | 9 | $self->_do_recursive_read | |||||||||||||||||||||||||||
| 355 | ($entry, $entry->name(), $callback, $no_content); | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | } else { | ||||||||||||||||||||||||||||
| 358 | 2 | my $entry = $self->{'gittree'}->entry_bypath($path); | |||||||||||||||||||||||||||
| 359 | 2 | ▶ | if( defined($entry) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | 2 | $self->_do_recursive_read($entry, $path, $callback, $no_content); | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | else | ||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||
| 364 | 0 | croak("No such path in the branch: $path"); | |||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 4 | return; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | sub _do_recursive_read | ||||||||||||||||||||||||||||
| 372 | 26 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_do_recursive_read: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 373 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 374 | 26 | my $entry = shift; # Git::Raw::Tree::Entry object | |||||||||||||||||||||||||||
| 375 | 26 | my $path = shift; | |||||||||||||||||||||||||||
| 376 | 26 | my $callback = shift; | |||||||||||||||||||||||||||
| 377 | 26 | my $no_content = shift; | |||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 26 | $entry->type(); | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 26 | ▶ | if( $entry->type() == Git::Raw::Object->TREE ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | # this is a subtree, we read it recursively | ||||||||||||||||||||||||||||
| 383 | 15 | foreach my $child_entry ($entry->object()->entries()) { | |||||||||||||||||||||||||||
| 384 | 15 | $self->_do_recursive_read | |||||||||||||||||||||||||||
| 385 | ($child_entry, $path . '/' . $child_entry->name(), $callback); | ||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | } else { | ||||||||||||||||||||||||||||
| 388 | 11 | ▶ | if( $no_content ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 389 | 0 | &{$callback}($path); | |||||||||||||||||||||||||||
| 390 | } else { | ||||||||||||||||||||||||||||
| 391 | 11 | &{$callback}($path, $entry->object()->content()); | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 26 | return; | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | sub read_updates | ||||||||||||||||||||||||||||
| 403 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
read_updates: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 404 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 405 | 2 | my $old_commit_id = shift; | |||||||||||||||||||||||||||
| 406 | 2 | my $cb_updated = shift; | |||||||||||||||||||||||||||
| 407 | 2 | my $cb_deleted = shift; | |||||||||||||||||||||||||||
| 408 | 2 | my $no_content = shift; | |||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 2 | my $old_commit = Git::Raw::Commit->lookup($self->{'repo'}, $old_commit_id); | |||||||||||||||||||||||||||
| 411 | 2 | ▶ | croak("Cannot lookup commit $old_commit_id") unless defined($old_commit); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 412 | 2 | my $old_tree = $old_commit->tree(); | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 2 | my $new_tree = $self->{'gittree'}; | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 2 | my $diff = $old_tree->diff | |||||||||||||||||||||||||||
| 417 | ( | ||||||||||||||||||||||||||||
| 418 | { | ||||||||||||||||||||||||||||
| 419 | 'tree' => $new_tree, | ||||||||||||||||||||||||||||
| 420 | 'flags' => { | ||||||||||||||||||||||||||||
| 421 | 'skip_binary_check' => 1, | ||||||||||||||||||||||||||||
| 422 | }, | ||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | ); | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 2 | my @deltas = $diff->deltas(); | |||||||||||||||||||||||||||
| 427 | 2 | foreach my $delta (@deltas) { | |||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 10 | my $path = $delta->new_file()->path(); | |||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 10 | ▶ | if( $delta->status() eq 'deleted') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | 4 | &{$cb_deleted}($path); | |||||||||||||||||||||||||||
| 433 | } else { | ||||||||||||||||||||||||||||
| 434 | 6 | ▶ | if( $no_content ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 435 | 3 | &{$cb_updated}($path); | |||||||||||||||||||||||||||
| 436 | } else { | ||||||||||||||||||||||||||||
| 437 | 3 | my $entry = $new_tree->entry_bypath($path); | |||||||||||||||||||||||||||
| 438 | 3 | &{$cb_updated}($path, $entry->object()->content()); | |||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 2 | return; | |||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 1 | 1; | |||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | # Local Variables: | ||||||||||||||||||||||||||||
| 455 | # mode: cperl | ||||||||||||||||||||||||||||
| 456 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||
| 457 | # cperl-indent-level: 4 | ||||||||||||||||||||||||||||
| 458 | # cperl-continued-statement-offset: 4 | ||||||||||||||||||||||||||||
| 459 | # cperl-continued-brace-offset: -4 | ||||||||||||||||||||||||||||
| 460 | # cperl-brace-offset: 0 | ||||||||||||||||||||||||||||
| 461 | # cperl-label-offset: -2 | ||||||||||||||||||||||||||||
| 462 | # End: | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | __END__ | ||||||||||||||||||||||||||||