| 1 | package Yukki::Model::Repository; | ||||||||||||||||||||||||||||||||
| 2 | 3 | $Yukki::Model::Repository::VERSION = '0.991_002'; # TRIAL | |||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | $Yukki::Model::Repository::VERSION = '0.991002';use v5.24; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 3 | extends 'Yukki::Model'; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Yukki::Error qw( http_throw ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Yukki::Model::File; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use DateTime::Format::Mail; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Git::Repository v1.18; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Type::Utils; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Types::Path::Tiny qw( Path ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Types::Standard qw( Str ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | # ABSTRACT: model for accessing objects in a git repository | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 3 | has name => ( | |||||||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 27 | isa => Str, | ||||||||||||||||||||||||||||||||
| 28 | required => 1, | ||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | has repository_settings => ( | ||||||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 34 | isa => class_type('Yukki::Settings::Repository'), | ||||||||||||||||||||||||||||||||
| 35 | required => 1, | ||||||||||||||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 37 | default => sub { | ||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||||||
| 39 | 3 | my $repo_config = $self->app->settings->repositories->{$self->name}; | |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | if (!$repo_config) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 0 | my $file = $self->app->locate('repo_path', $self->name); | |||||||||||||||||||||||||||||||
| 43 | 0 | $repo_config = Yukki::Settings::Repository->load_yaml( | |||||||||||||||||||||||||||||||
| 44 | $file->slurp_utf8 | ||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 3 | return $repo_config; | |||||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||||||
| 50 | 3 | handles => { | |||||||||||||||||||||||||||||||
| 51 | 'title' => 'name', | ||||||||||||||||||||||||||||||||
| 52 | 'branch' => 'site_branch', | ||||||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 3 | has repository_path => ( | |||||||||||||||||||||||||||||||
| 58 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 59 | isa => Path, | ||||||||||||||||||||||||||||||||
| 60 | coerce => 1, | ||||||||||||||||||||||||||||||||
| 61 | required => 1, | ||||||||||||||||||||||||||||||||
| 62 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 63 | builder => '_build_repository_path', | ||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | sub _build_repository_path { | ||||||||||||||||||||||||||||||||
| 67 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_build_repository_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 3 | my $repo_settings = $self->repository_settings; | |||||||||||||||||||||||||||||||
| 70 | 3 | return $self->locate_dir('repository_path', $repo_settings->repository); | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 3 | has git => ( | |||||||||||||||||||||||||||||||
| 75 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 76 | isa => class_type('Git::Repository'), | ||||||||||||||||||||||||||||||||
| 77 | required => 1, | ||||||||||||||||||||||||||||||||
| 78 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 79 | builder => '_build_git', | ||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | sub _build_git { | ||||||||||||||||||||||||||||||||
| 83 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_build_git: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 84 | 3 | return Git::Repository->new( git_dir => $self->repository_path ); | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub author_name { shift->app->settings->anonymous->author_name } | ||||||||||||||||||||||||||||||
|
Subroutine
author_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub author_email { shift->app->settings->anonymous->author_email } | ||||||||||||||||||||||||||||||
|
Subroutine
author_email: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | sub make_tree { | ||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
make_tree: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 96 | 0 | my $base = shift; | |||||||||||||||||||||||||||||||
| 97 | 0 | my $path = shift; | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 0 | my (@new_path, @old_path, $blob); | |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | # This is a rename | ||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (ref $_[0]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 103 | 0 | my $new_path = shift; | |||||||||||||||||||||||||||||||
| 104 | 0 | $blob = shift; | |||||||||||||||||||||||||||||||
| 105 | 0 | @new_path = @$new_path; | |||||||||||||||||||||||||||||||
| 106 | 0 | @old_path = @$path; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | # Otherwise it's a store or delete | ||||||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||||||
| 111 | 0 | $blob = shift; | |||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | # Defined $blob -> Store | ||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if (defined $blob) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | 0 | @new_path = @$path; | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | # Undefined $blob -> delete | ||||||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||||||
| 120 | 0 | @old_path = @$path; | |||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 0 | my ($new_mode, $new_type, $new_name, $old_name, $remove_here); | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | # Parts to add or update | ||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if (@new_path) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 0 | $new_name = shift @new_path; | |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | # Create the file here? | ||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if (@new_path == 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 0 | $new_mode = '100644'; | |||||||||||||||||||||||||||||||
| 133 | 0 | $new_type = 'blob'; | |||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | # Or we're still hunting down the tree | ||||||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||||||
| 138 | 0 | $new_mode = '040000'; | |||||||||||||||||||||||||||||||
| 139 | 0 | $new_type = 'tree'; | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | # Parts to remove | ||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if (@old_path) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 145 | 0 | $old_name = shift @old_path; | |||||||||||||||||||||||||||||||
| 146 | 0 | $remove_here = (@old_path == 0); | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 0 | my $git = $self->git; | |||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 0 | my $overwrite; | |||||||||||||||||||||||||||||||
| 152 | my @new_tree; | ||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if (defined $base) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | 0 | my @old_tree = $git->run('ls-tree', $base); | |||||||||||||||||||||||||||||||
| 155 | 0 | for my $line (@old_tree) { | |||||||||||||||||||||||||||||||
| 156 | 0 | my ($old_mode, $old_type, $old_object_id, $old_file) = split /\s+/, $line, 4; | |||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if (defined $new_name and $old_file eq $new_name) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $new_name and $old_file eq $new_name
MC/DC0%0/2
defined $new_name and $old_file eq $new_name
defined $new_name
$old_file eq $new_name
Truth table0%0/3
A and B
A= defined $new_nameB= $old_file eq $new_name
| |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | # The file already exists, we are doing an update | ||||||||||||||||||||||||||||||||
| 161 | 0 | $overwrite++; | |||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | # Cannot overwrite a file with a dir or a dir with a file | ||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | http_throw("cannot replace $old_type $new_name with $new_type") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 165 | if $old_type ne $new_type; | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | # Add the updated file to the tree | ||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ($new_type eq 'blob') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 170 | 0 | push @new_tree, "$new_mode $new_type $blob\t$new_name"; | |||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | # The child tree contains both sides of the rename | ||||||||||||||||||||||||||||||||
| 174 | elsif ($old_name eq $new_name) { | ||||||||||||||||||||||||||||||||
| 175 | 0 | my $tree_id = $self->make_tree($old_object_id, \@old_path, \@new_path, $blob); | |||||||||||||||||||||||||||||||
| 176 | 0 | push @new_tree, "$new_mode $new_type $tree_id\t$new_name"; | |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | # Add the updated tree contains only the rename/add | ||||||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||||||
| 181 | 0 | my $tree_id = $self->make_tree($old_object_id, \@new_path, $blob); | |||||||||||||||||||||||||||||||
| 182 | 0 | push @new_tree, "$new_mode $new_type $tree_id\t$new_name"; | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | # If $old_name != $new_name and it matches this file | ||||||||||||||||||||||||||||||||
| 187 | ▶ | elsif (defined $old_name and $old_file eq $old_name) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $old_name and $old_file eq $old_name
MC/DC0%0/2
defined $old_name and $old_file eq $old_name
defined $old_name
$old_file eq $old_name
Truth table0%0/3
A and B
A= defined $old_nameB= $old_file eq $old_name
| |||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | # if ($remove_here) { ... do nothing ... }. The file will be | ||||||||||||||||||||||||||||||||
| 190 | # omitted. \o/ | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | # Not yet removed, but we need to hunt it down and remove it | ||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | unless ($remove_here) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 194 | 0 | my $tree_id = $self->make_tree($old_object_id, \@old_path); | |||||||||||||||||||||||||||||||
| 195 | 0 | push @new_tree, "040000 tree $tree_id\t$old_name"; | |||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | # It's something else, leave it be. | ||||||||||||||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||||||||||||||
| 201 | 0 | push @new_tree, $line; | |||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | # If the file or tree we want to create was never encountered, add it | ||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ($new_name and not $overwrite) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$new_name and not $overwrite
MC/DC0%0/2
$new_name and not $overwrite
$new_name
not $overwrite
Truth table0%0/3
A and not(B)
A= $new_nameB= not $overwrite
| |||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | # ...as a file | ||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($new_type eq 'blob') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 211 | 0 | push @new_tree, "$new_mode $new_type $blob\t$new_name"; | |||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | # ...as a tree | ||||||||||||||||||||||||||||||||
| 215 | else { | ||||||||||||||||||||||||||||||||
| 216 | 0 | my $tree_id = $self->make_tree(undef, \@new_path, $blob); | |||||||||||||||||||||||||||||||
| 217 | 0 | push @new_tree, "$new_mode $new_type $tree_id\t$new_name"; | |||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | # Now, build this new tree from the input we've generated | ||||||||||||||||||||||||||||||||
| 222 | 0 | return $git->run('mktree', { input => join "\n", @new_tree }); | |||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | sub make_blob { | ||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my ($self, $name, $content) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
make_blob: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | 0 | return $self->git->run('hash-object', '-t', 'blob', '-w', '--stdin', '--path', $name, | |||||||||||||||||||||||||||||||
| 230 | { input => $content }); | ||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | sub make_blob_from_file { | ||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | my ($self, $name, $filename) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
make_blob_from_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | 0 | return $self->git->run('hash-object', '-t', 'blob', '-w', '--path', $name, $filename); | |||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | sub find_root { | ||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
find_root: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | 0 | my $old_tree_id; | |||||||||||||||||||||||||||||||
| 245 | 0 | my @ref_info = $self->git->run('show-ref', $self->branch); | |||||||||||||||||||||||||||||||
| 246 | 0 | REF: for my $line (@ref_info) { | |||||||||||||||||||||||||||||||
| 247 | 0 | my ($object_id, $name) = split /\s+/, $line, 2; | |||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ($name eq $self->branch) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 250 | 0 | $old_tree_id = $object_id; | |||||||||||||||||||||||||||||||
| 251 | 0 | last REF; | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | 0 | return $old_tree_id; | |||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | sub commit_tree { | ||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | my ($self, $old_tree_id, $new_tree_id, $comment) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
commit_tree: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | 0 | return $self->git->run( | |||||||||||||||||||||||||||||||
| 263 | 'commit-tree', $new_tree_id, '-p', $old_tree_id, { | ||||||||||||||||||||||||||||||||
| 264 | input => $comment, | ||||||||||||||||||||||||||||||||
| 265 | env => { | ||||||||||||||||||||||||||||||||
| 266 | GIT_AUTHOR_NAME => $self->author_name, | ||||||||||||||||||||||||||||||||
| 267 | GIT_AUTHOR_EMAIL => $self->author_email, | ||||||||||||||||||||||||||||||||
| 268 | }, | ||||||||||||||||||||||||||||||||
| 269 | }, | ||||||||||||||||||||||||||||||||
| 270 | ); | ||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | sub update_root { | ||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | my ($self, $old_commit_id, $new_commit_id) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
update_root: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 276 | 0 | $self->git->command('update-ref', $self->branch, $new_commit_id, $old_commit_id); | |||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||
| 280 | sub find_path { | ||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | my ($self, $path) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
find_path: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | 0 | my $object_id; | |||||||||||||||||||||||||||||||
| 284 | my @files; | ||||||||||||||||||||||||||||||||
| 285 | try { | ||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | @files = $self->git->run('ls-tree', $self->branch, $path); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||
| 288 | catch { | ||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||
| 290 | # Looks like an empty repo, try initializing it | ||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if ($_ =~ /Not a valid object name/) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 292 | 0 | $self->initialize_repository; | |||||||||||||||||||||||||||||||
| 293 | 0 | @files = $self->git->run('ls-tree', $self->branch, $path); | |||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | # I don't know what this is, die die die! | ||||||||||||||||||||||||||||||||
| 297 | else { | ||||||||||||||||||||||||||||||||
| 298 | 0 | die $_; | |||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||
| 300 | 0 | }; | |||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | 0 | FILE: for my $line (@files) { | |||||||||||||||||||||||||||||||
| 303 | 0 | my ($mode, $type, $id, $name) = split /\s+/, $line, 4; | |||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ($name eq $path) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 306 | 0 | $object_id = $id; | |||||||||||||||||||||||||||||||
| 307 | 0 | last FILE; | |||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 0 | return $object_id; | |||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||
| 315 | sub show { | ||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | my ($self, $object_id) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
show: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 317 | 0 | return $self->git->run('show', $object_id); | |||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | sub fetch_size { | ||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | my ($self, $path) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
fetch_size: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | 0 | my @files = $self->git->run('ls-tree', '-l', $self->branch, $path); | |||||||||||||||||||||||||||||||
| 325 | 0 | FILE: for my $line (@files) { | |||||||||||||||||||||||||||||||
| 326 | 0 | my ($mode, $type, $id, $size, $name) = split /\s+/, $line, 5; | |||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | return $size if $name eq $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | 0 | return; | |||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||
| 334 | sub list_files { | ||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | my ($self, $path) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
list_files: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 336 | 0 | my @files; | |||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||
| 338 | 0 | my @tree_files = $self->git->run('ls-tree', $self->branch, $path . '/'); | |||||||||||||||||||||||||||||||
| 339 | 0 | FILE: for my $line (@tree_files) { | |||||||||||||||||||||||||||||||
| 340 | 0 | my ($mode, $type, $id, $name) = split /\s+/, $line, 4; | |||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | next unless $type eq 'blob'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||
| 344 | 0 | my $filetype; | |||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if ($name =~ s/\.(?<filetype>[a-z0-9]+)$//) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 346 | 0 | $filetype = $+{filetype}; | |||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||
| 349 | 0 | push @files, $self->file({ path => $name, filetype => $filetype }); | |||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | 0 | return @files; | |||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | sub file { | ||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | my ($self, $params) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||
| 359 | 0 | Yukki::Model::File->new( | |||||||||||||||||||||||||||||||
| 360 | %$params, | ||||||||||||||||||||||||||||||||
| 361 | app => $self->app, | ||||||||||||||||||||||||||||||||
| 362 | repository => $self, | ||||||||||||||||||||||||||||||||
| 363 | ); | ||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||
| 367 | sub default_file { | ||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
default_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||
| 370 | 0 | return Yukki::Model::File->new( | |||||||||||||||||||||||||||||||
| 371 | full_path => $self->repository_settings->default_page, | ||||||||||||||||||||||||||||||||
| 372 | app => $self->app, | ||||||||||||||||||||||||||||||||
| 373 | repository => $self, | ||||||||||||||||||||||||||||||||
| 374 | ); | ||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | sub log { | ||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | my ($self, $full_path) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | 0 | my @lines = $self->git->run( | |||||||||||||||||||||||||||||||
| 382 | 'log', $self->branch, '--pretty=format:%H~%an~%aD~%ar~%s', '--numstat', | ||||||||||||||||||||||||||||||||
| 383 | '--', $full_path | ||||||||||||||||||||||||||||||||
| 384 | ); | ||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | 0 | my @revisions; | |||||||||||||||||||||||||||||||
| 387 | my $current_revision; | ||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | 0 | my $mode = 'log'; | |||||||||||||||||||||||||||||||
| 390 | 0 | for my $line (@lines) { | |||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||
| 392 | # First line is the log line | ||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ($mode eq 'log') { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 394 | 0 | $current_revision = {}; | |||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | 0 | @{ $current_revision }{qw( object_id author_name date time_ago comment )} | |||||||||||||||||||||||||||||||
| 397 | = split /~/, $line, 5; | ||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | $current_revision->{date} = DateTime::Format::Mail->parse_datetime( | ||||||||||||||||||||||||||||||||
| 400 | $current_revision->{date} | ||||||||||||||||||||||||||||||||
| 401 | 0 | ); | |||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||
| 403 | 0 | $mode = 'stat'; | |||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | # Remaining lines are the numstat | ||||||||||||||||||||||||||||||||
| 407 | elsif ($mode eq 'stat') { | ||||||||||||||||||||||||||||||||
| 408 | 0 | my ($added, $removed, $path) = split /\s+/, $line, 3; | |||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ($path eq $full_path) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 410 | 0 | $current_revision->{lines_added} = $added; | |||||||||||||||||||||||||||||||
| 411 | 0 | $current_revision->{lines_removed} = $removed; | |||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | 0 | $mode = 'skip'; | |||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||
| 417 | # Once we know the numstat, search for the blank and start over | ||||||||||||||||||||||||||||||||
| 418 | elsif ($mode eq 'skip') { | ||||||||||||||||||||||||||||||||
| 419 | 0 | push @revisions, $current_revision; | |||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | $mode = 'log' if $line !~ /\S/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | else { | ||||||||||||||||||||||||||||||||
| 424 | 0 | http_throw("invalid parse mode '$mode'"); | |||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | 0 | return @revisions; | |||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | sub diff_blobs { | ||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | my ($self, $path, $object_id_1, $object_id_2) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
diff_blobs: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||
| 435 | 0 | my @lines = $self->git->run( | |||||||||||||||||||||||||||||||
| 436 | 'diff', '--word-diff=porcelain', '--unified=10000000', '--patience', | ||||||||||||||||||||||||||||||||
| 437 | $object_id_1, $object_id_2, '--', $path, | ||||||||||||||||||||||||||||||||
| 438 | ); | ||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||
| 440 | 0 | my @chunks; | |||||||||||||||||||||||||||||||
| 441 | 0 | my $last_chunk_type = ''; | |||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||
| 443 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||
| 444 | 0 | LINE: for my $line (@lines) { | |||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | next if $i++ < 5; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||
| 447 | 0 | my ($type, $detail) = $line =~ /^(.)(.*)$/; | |||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if ($type =~ /^(?:~| |\+|-)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | if ($last_chunk_type eq $type) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 450 | 0 | $chunks[-1][1] .= $detail; | |||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||
| 452 | elsif ($type eq '~') { | ||||||||||||||||||||||||||||||||
| 453 | 0 | $chunks[-1][1] .= "\n"; | |||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||
| 455 | else { | ||||||||||||||||||||||||||||||||
| 456 | 0 | push @chunks, [ $type, $detail ]; | |||||||||||||||||||||||||||||||
| 457 | 0 | $last_chunk_type = $type; | |||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||
| 460 | elsif ($type eq '\\') { } | ||||||||||||||||||||||||||||||||
| 461 | 0 | else { warn "unknown diff line type $type" } | |||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | 0 | return @chunks; | |||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||
| 468 | sub initialize_repository { | ||||||||||||||||||||||||||||||||
| 469 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
initialize_repository: called CC=2 SCAR=7.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | 3 | my $repository_path = ''.$self->repository_path; | |||||||||||||||||||||||||||||||
| 472 | 3 | Git::Repository->run('init', '--bare', $repository_path); | |||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||
| 474 | # TODO This would be nice to have as a config. | ||||||||||||||||||||||||||||||||
| 475 | 3 | ▶ | my $title = $self->repository_settings->name // 'Untitled'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->repository_settings->name // "Untitled"
MC/DC0%0/1
$self->repository_settings->name // "Untitled"
$self->repository_settings->name
Truth table50%1/2
A
A= $self->repository_settings->name
| |||||||||||||||||||||||||||||||||
| 476 | 3 | my $stub_main = <<END_OF_STUB_MAIN; | |||||||||||||||||||||||||||||||
| 477 | # $title | ||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||
| 479 | Welcome to your new wiki repository. The first thing you will probably | ||||||||||||||||||||||||||||||||
| 480 | want to do is edit this page. | ||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||
| 482 | Cheers. | ||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||
| 484 | END_OF_STUB_MAIN | ||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | 3 | my $page = $self->repository_settings->default_page; | |||||||||||||||||||||||||||||||
| 487 | 3 | my $object_id = $self->git->run('hash-object', '-t', 'blob', '-w', '--stdin', "--path=$page", { input => $stub_main }); | |||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||
| 489 | 3 | my $stub_tree = "100655 blob $object_id\t$page\n"; | |||||||||||||||||||||||||||||||
| 490 | 3 | my $tree_id = $self->git->run('mktree', { input => $stub_tree }); | |||||||||||||||||||||||||||||||
| 491 | 3 | my $commit_id = $self->git->run('commit-tree', $tree_id, { | |||||||||||||||||||||||||||||||
| 492 | input => 'Initializing empty Yukki repository.', | ||||||||||||||||||||||||||||||||
| 493 | env => { | ||||||||||||||||||||||||||||||||
| 494 | GIT_AUTHOR_NAME => 'Yukki::Model::Repository', | ||||||||||||||||||||||||||||||||
| 495 | GIT_AUTHOR_EMAIL => 'hanenkamp@cpan.org', | ||||||||||||||||||||||||||||||||
| 496 | }, | ||||||||||||||||||||||||||||||||
| 497 | }); | ||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||
| 499 | 0 | my $branch = $self->branch; | |||||||||||||||||||||||||||||||
| 500 | 0 | $self->git->run('update-ref', $branch, $commit_id, '0' x 40); | |||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||
| 502 | 0 | return; | |||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||
| 506 | sub clone_repository { | ||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | my ($self, $origin) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
clone_repository: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||
| 509 | 0 | my $repository_path = ''.$self->repository_path; | |||||||||||||||||||||||||||||||
| 510 | 0 | Git::Repository->run('clone', '--bare', $origin, $repository_path); | |||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||
| 512 | 0 | return; | |||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||
| 515 | 3 | 1; | |||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||
| 517 | __END__ | ||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||
| 519 | =pod | ||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||
| 521 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||
| 523 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||
| 525 | Yukki::Model::Repository - model for accessing objects in a git repository | ||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||
| 527 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||
| 529 | version 0.991_002 | ||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||
| 531 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||
| 533 | my $repository = $app->model('Repository', { name => 'main' }); | ||||||||||||||||||||||||||||||||
| 534 | my $file = $repository->file({ path => 'foo.yukki' }); | ||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||
| 536 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||
| 538 | This model contains methods for performing all the individual operations | ||||||||||||||||||||||||||||||||
| 539 | required to store files into and fetch files from the git repository. It | ||||||||||||||||||||||||||||||||
| 540 | includes tools for building trees, commiting, creating blobs, fetching file | ||||||||||||||||||||||||||||||||
| 541 | lists, etc. | ||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||
| 543 | =head1 EXTENDS | ||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||
| 545 | L<Yukki::Model> | ||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||
| 547 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||
| 549 | =head2 name | ||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||
| 551 | This is the name of the repository. This is used to lookup the configuration for | ||||||||||||||||||||||||||||||||
| 552 | the repository from the F<yukki.conf>. | ||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||
| 554 | =head2 repository_settings | ||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||
| 556 | These are the settings telling this model where to find the git repository and | ||||||||||||||||||||||||||||||||
| 557 | how to access it. It is loaded automatically using the L</name> to look up | ||||||||||||||||||||||||||||||||
| 558 | information in the F<yukki.conf>. | ||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||
| 560 | =head2 repository_path | ||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||
| 562 | This is the path to the repository. It is located using the C<repository_path> | ||||||||||||||||||||||||||||||||
| 563 | and C<repository> keys in the configuration. | ||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||
| 565 | =head2 git | ||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||
| 567 | This is a L<Git::Repository> object which helps us do the real work. | ||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||
| 569 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||
| 571 | =head2 author_name | ||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||
| 573 | This is the author name to use when making changes to the repository. | ||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||
| 575 | This is taken from the C<author_name> of the C<anonymous> key in the | ||||||||||||||||||||||||||||||||
| 576 | configuration or defaults to "Anonymous". | ||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||
| 578 | =head2 author_email | ||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||
| 580 | This is the author email to use when making changes to the repository. | ||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||
| 582 | This is taken from teh C<author_email> of the C<anonymous> key in the | ||||||||||||||||||||||||||||||||
| 583 | configuration or defaults to "anonymous@localhost". | ||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||
| 585 | =head2 make_tree | ||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||
| 587 | my $tree_id = $repository->make_tree($old_tree_id, \@parts, $object_id); | ||||||||||||||||||||||||||||||||
| 588 | my $tree_id = $repository->make_tree($old_tree_id, \@parts); | ||||||||||||||||||||||||||||||||
| 589 | my $tree_id = $repository->make_tree( | ||||||||||||||||||||||||||||||||
| 590 | $old_tree_id, \@old_parts, \@new_parts, $object_id); | ||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||
| 592 | In any case described here, the method returns the object ID of the top level | ||||||||||||||||||||||||||||||||
| 593 | tree created. | ||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||
| 595 | =head3 Insert/Update | ||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||
| 597 | When C<$object_id> is given, this will construct one or more trees in the git | ||||||||||||||||||||||||||||||||
| 598 | repository to place the C<$object_id> into the deepest tree. This starts by | ||||||||||||||||||||||||||||||||
| 599 | reading the tree found using the object ID in C<$old_tree_id>. The first path | ||||||||||||||||||||||||||||||||
| 600 | part in C<@parts> is shifted off. If an existing path is found there, that | ||||||||||||||||||||||||||||||||
| 601 | path will be replaced. If not, a new path will be added. A tree object will be | ||||||||||||||||||||||||||||||||
| 602 | constructed for all byt he final path part in C<@parts>. | ||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||
| 604 | When the final part is reached, that path will be placed into the final tree | ||||||||||||||||||||||||||||||||
| 605 | as a blob using the given C<$object_id>. | ||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||
| 607 | This method will fail if it runs into a situation where a blob would be | ||||||||||||||||||||||||||||||||
| 608 | replaced by a tree or a tree would be replaced by a blob. | ||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||
| 610 | =head3 Remove | ||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||
| 612 | When C<$object_id> is not passed or C<undef>, this will cause the final tree or blob found to be removed. This works essentially the same as the case for storing a blob, but when it gets to the last tree or blob found, it will elide that name from the final tree constructed. | ||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||
| 614 | This method will fail if you attempt to remove something that does not exist. | ||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||
| 616 | =head3 Rename | ||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||
| 618 | When a second array reference is passed with the C<$object_id>, this method will perform a rename. In this case, the method will remove the path named in the L<@old_parts> and add the path named in <@new_parts> using the given C<$object_id> at that new location. | ||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||
| 620 | This method will fail if a failure condition that would occur during either the insert/update or remove operation that is being performed simultaneously. | ||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||
| 622 | =head2 make_blob | ||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||
| 624 | my $object_id = $repository->make_blob($name, $content); | ||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||
| 626 | This creates a new file blob in the git repository with the given name and the | ||||||||||||||||||||||||||||||||
| 627 | file contents. | ||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||
| 629 | =head2 make_blob_from_file | ||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||
| 631 | my $object_id = $repository->make_blob_from_file($name, $filename); | ||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||
| 633 | This is identical to L</make_blob>, except that the contents are read from the | ||||||||||||||||||||||||||||||||
| 634 | given filename on the local disk. | ||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||
| 636 | =head2 find_root | ||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||
| 638 | my $tree_id = $repository->find_root; | ||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||
| 640 | This returns the object ID for the tree at the root of the L</branch>. | ||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||
| 642 | =head2 commit_tree | ||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||
| 644 | my $commit_id = $self->commit_tree($old_tree_id, $new_tree_id, $comment); | ||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||
| 646 | This takes an existing tree commit (generally found with L</find_root>), a new | ||||||||||||||||||||||||||||||||
| 647 | tree to replace it (generally constructed by L</make_tree>) and creates a | ||||||||||||||||||||||||||||||||
| 648 | commit using the given comment. | ||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||
| 650 | The object ID of the committed ID is returned. | ||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||
| 652 | =head2 update_root | ||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||
| 654 | $self->update_root($old_tree_id, $new_tree_id); | ||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||
| 656 | Given an old commit ID and a new commit ID, this moves the HEAD of the | ||||||||||||||||||||||||||||||||
| 657 | L</branch> so that it points to the new commit. This is called after | ||||||||||||||||||||||||||||||||
| 658 | L</commit_tree> has setup the commit. | ||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||
| 660 | =head2 find_path | ||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||
| 662 | my $object_id = $self->find_path($path); | ||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||
| 664 | Given a path within the repository, this will find the object ID of that tree or | ||||||||||||||||||||||||||||||||
| 665 | blob at that path for the L</branch>. | ||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||
| 667 | =head2 show | ||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||
| 669 | my $content = $repository->show($object_id); | ||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||
| 671 | Returns the contents of the blob for the given object ID. | ||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||
| 673 | =head2 fetch_size | ||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||
| 675 | my $bytes = $repository->fetch_size($path); | ||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||
| 677 | Returns the size, in bites, of the blob at the given path. | ||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||
| 679 | =head2 list_files | ||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||
| 681 | my @files = $repository->list_files($path); | ||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||
| 683 | Returns a list of L<Yukki::Model::File> objects for all the files found at | ||||||||||||||||||||||||||||||||
| 684 | C<$path> in the repository. | ||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||
| 686 | =head2 file | ||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||
| 688 | my $file = $repository->file({ path => 'foo', filetype => 'yukki' }); | ||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||
| 690 | Returns a single L<Yukki::Model::File> object for the given path and filetype. | ||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||
| 692 | =head2 default_file | ||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||
| 694 | my $file = $repository->default_file; | ||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||
| 696 | Return the default L<Yukki::Model::File> configured for this repository. | ||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||
| 698 | =head2 log | ||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||
| 700 | my @log = $repository->log( full_path => 'foo.yukk' ); | ||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||
| 702 | Returns a list of revisions. Each revision is a hash with the following keys: | ||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||
| 704 | =over | ||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||
| 706 | =item object_id | ||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||
| 708 | The object ID of the commit. | ||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||
| 710 | =item author_name | ||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||
| 712 | The name of the commti author. | ||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||
| 714 | =item date | ||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||
| 716 | The date the commit was made. | ||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||
| 718 | =item time_ago | ||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||
| 720 | A string showing how long ago the edit took place. | ||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||
| 722 | =item comment | ||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||
| 724 | The comment the author made about the comment. | ||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||
| 726 | =item lines_added | ||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||
| 728 | Number of lines added. | ||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||
| 730 | =item lines_removed | ||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||
| 732 | Number of lines removed. | ||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||
| 734 | =back | ||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||
| 736 | =head2 diff_blobs | ||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||
| 738 | my @chunks = $self->diff_blobs('file.yukki', 'a939fe...', 'b7763d...'); | ||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||
| 740 | Given a file path and two object IDs, returns a list of chunks showing the difference between to revisions of that path. Each chunk is a two element array. The first element is the type of chunk and the second is any detail for that chunk. | ||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||
| 742 | The types are: | ||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||
| 744 | "+" This chunk was added to the second revision. | ||||||||||||||||||||||||||||||||
| 745 | "-" This chunk was removed in the second revision. | ||||||||||||||||||||||||||||||||
| 746 | " " This chunk is the same in both revisions. | ||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||
| 748 | =head2 initialize_repository | ||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||
| 750 | $self->initialize_repository; | ||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||
| 752 | Run on an empty repository to create an empty one. | ||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||
| 754 | =head2 clone_repository | ||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||
| 756 | $self->clone_repository($origin); | ||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||
| 758 | Given a remote repository URI to clone from in C<$origin>, initialize the local repository from a clone of the remote one. | ||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||
| 760 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||
| 762 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||
| 764 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||
| 766 | This software is copyright (c) 2017 by Qubling Software LLC. | ||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||
| 768 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 769 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||
| 771 | =cut | ||||||||||||||||||||||||||||||||