| 1 | package VCS::Lite::Element; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | our $VERSION = '0.11'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use File::Spec::Functions qw(splitpath catfile catdir catpath rel2abs); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use VCS::Lite; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use base qw(VCS::Lite::Common); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 120 | ▶ | my $pkg = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 120 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 120 | my %args = validate ( @_, | |||||||||||||||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | store => { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | type => SCALAR | OBJECT, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | default => $pkg->default_store, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | verbose => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | recordsize => 0, #ignored unless VCS::Lite::Element::Binary | ||||||||||||||||||||||||||||||||||||||||||
| 32 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 120 | my $lite = $file; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 120 | my $verbose = $args{verbose}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 120 | $file = rel2abs($file); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 120 | my $store_pkg; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 120 | ▶ | if (ref $args{store}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $store_pkg = $args{store}; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 120 | ▶ | $store_pkg = ($args{store} =~ /\:\:/) ? $args{store} : "VCS::Lite::Store::$args{store}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 120 | eval "require $store_pkg"; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 120 | ▶ | warn "Failed to require $store_pkg\n$@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 120 | my $ele = $store_pkg->retrieve($file); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 120 | ▶ | if ($ele) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 94 | $ele->path($file); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 94 | return $ele; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 26 | my $proto = bless { | |||||||||||||||||||||||||||||||||||||||||
| 53 | %args, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | path => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | }, $pkg; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 26 | $ele = $store_pkg->retrieve_or_create($proto); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 26 | $ele->{path} = $file; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 26 | ▶ | if (!ref $lite) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 26 | ▶ | unless (-f $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | ▶ | open FIL, '>', $file or croak("Failed to create $file, $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | close FIL; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 26 | $lite = $ele->_slurp_lite($file); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $file = $lite->id; # Not handled at present | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 26 | $ele->_assimilate($lite); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 26 | $ele->save; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 26 | $ele->{verbose} = $verbose; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 26 | $ele; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | sub check_in { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 27 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_in: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 27 | my %args = validate ( @_, | |||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | check_in_anyway => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | description => { type => SCALAR }, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 27 | my $file = $self->{path}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 27 | my $lite = $self->_slurp_lite($file); | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 27 | my $newgen = $self->_assimilate($lite); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 27 | ▶ | return if !$newgen && !$args{check_in_anyway}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$newgen or $args{"check_in_anyway"}
MC/DC50%1/2
$newgen or $args{"check_in_anyway"}
$newgen
$args{"check_in_anyway"}
Truth table66%2/3
A or B
A= $newgenB= $args{"check_in_anyway"}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 14 | $self->_mumble("Check in $file"); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 14 | ▶ | $self->{generation} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"generation"} ||= {}
MC/DC100%1/1
$self->{"generation"} ||= {}
$self->{"generation"}
Truth table100%2/2
A
A= $self->{"generation"}
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 14 | my %gen = %{$self->{generation}}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | $gen{$newgen} = { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | author => $self->user, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | description => $args{description}, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 14 | updated => localtime->datetime, | |||||||||||||||||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 14 | ▶ | $self->{latest} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"latest"} ||= {}
MC/DC100%1/1
$self->{"latest"} ||= {}
$self->{"latest"}
Truth table100%2/2
A
A= $self->{"latest"}
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 14 | my %lat = %{$self->{latest}}; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 14 | $newgen =~ /(\d+\.)*\d+$/; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 14 | ▶ | my $base = $1 || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$1 || ''
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 14 | $lat{$base}=$newgen; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 14 | $self->_update_ctrl( generation => \%gen, latest => \%lat); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 14 | $newgen; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | sub repository { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repository: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my ($vol,$dir,$fil) = splitpath($self->{path}); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | my $repos_path = $vol ? catdir($vol,$dir) : $dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | VCS::Lite::Repository->new($repos_path, verbose => $self->{verbose}); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | sub traverse { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 16 | ▶ | undef; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
traverse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | sub fetch { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 58 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=19 SCAR=37.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 58 | my %args = validate ( @_, | |||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | time => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | generation => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 58 | ▶ | my $gen = $args{generation} || $self->latest; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$args{'generation'} || $self->latest
MC/DC100%2/2
$args{'generation'} || $self->latest
$args{'generation'}
$self->latest
Truth table100%3/3
A || B
A= $args{'generation'}B= $self->latest
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 58 | ▶ | if ($args{time}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $latest_time = ''; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $branch = $args{generation} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{'generation'} || ''
MC/DC0%0/1
$args{'generation'} || ''
$args{'generation'}
Truth table0%0/2
A
A= $args{'generation'}
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | $branch .= '.' if $branch; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | for (keys %{$self->{generation}}) { | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | next unless /^$branch\d+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | next if $self->{generation}{$_}{updated} > $args{time}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | ($latest_time,$gen) = ($self->{generation}{$_}{updated}, $_) | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if $self->{generation}{$_}{updated} > $latest_time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | return unless $latest_time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 58 | ▶ | return if $self->{generation} && !$self->{generation}{$gen}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"generation"} and not $self->{"generation"}{$gen}
MC/DC0%0/2
$self->{"generation"} and not $self->{"generation"}{$gen}
$self->{"generation"}
not $self->{"generation"}{$gen}
Truth table66%2/3
A and not(B)
A= $self->{"generation"}B= not $self->{"generation"}{$gen}
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 58 | my $skip_to; | |||||||||||||||||||||||||||||||||||||||||
| 149 | my @out; | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 58 | for (@{$self->_contents}) { | |||||||||||||||||||||||||||||||||||||||||
| 151 | 2853 | ▶ | if ($skip_to) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 121 | ▶ | if (/^=$skip_to$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 25 | undef $skip_to; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 121 | next; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 2732 | ▶ | if (my ($type,$gensel) = /^([+-])(.+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 60 | ▶ | if (_is_parent_of($gensel,$gen) ^ ($type eq '+')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 25 | $skip_to = $gensel; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 60 | next; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 2672 | ▶ | next if /^=/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 2637 | ▶ | if (/^ /) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 2637 | push @out,substr($_,1); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 58 | my $file = $self->{path}; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 58 | VCS::Lite->new("$file\@\@$gen",undef,\@out); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | sub commit { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | ▶ | my ($self,$parent) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | my ($vol,$dir,$file) = splitpath($self->path); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | my $updfile = catfile($parent,$file); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 4 | my $chg = $self->fetch; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 4 | my $before = VCS::Lite->new($updfile); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | ▶ | return unless $before->delta($chg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | $self->_mumble("Committing $file to $parent"); | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | my $out; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | ▶ | open $out,'>',$updfile or croak "Failed to open $file for committing, $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | print $out $chg->text; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | sub update { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 9 | ▶ | my ($self,$parent) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 9 | my $file = $self->path; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 9 | $self->_mumble("Updating $file from $parent"); | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 9 | my ($vol,$dir,$fil) = splitpath($file); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 9 | my $fromfile = catfile($parent,$fil); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 9 | ▶ | my $baseline = $self->{baseline} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'baseline'} || 0
MC/DC0%0/1
$self->{'baseline'} || 0
$self->{'baseline'}
Truth table50%1/2
A
A= $self->{'baseline'}
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 9 | my $parbas = $self->{parent_baseline}; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 9 | my $orig = $self->fetch( generation => $baseline); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 9 | my $parele = VCS::Lite::Element->new($fromfile, verbose => $self->{verbose}); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 9 | my $parfrom = $parele->fetch( generation => $parbas); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 9 | my $parlat = $parele->latest($parbas); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 9 | my $parto = $parele->fetch( generation => $parlat); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 9 | my $origplus = $parfrom->merge($parto,$orig); | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 9 | my $chg = VCS::Lite->new($file); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | my $merged = $orig->merge($origplus,$chg); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | my $out; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 9 | ▶ | open $out,'>',$file or croak "Failed to write back merge of $fil, $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | print $out $merged->text; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 9 | $self->_update_ctrl(baseline => $self->latest, parent_baseline => $parlat); | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | sub _check_out_member { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_out_member: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 17 | my $newpath = shift; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 17 | my %args = validate(@_, | |||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | store => { type => SCALAR|OBJECT, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 222 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | my $repos = VCS::Lite::Repository->new( | ||||||||||||||||||||||||||||||||||||||||||
| 225 | $newpath, | ||||||||||||||||||||||||||||||||||||||||||
| 226 | verbose => $self->{verbose}, | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 17 | %args); | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 17 | my ($vol,$dir,$fil) = splitpath($self->path); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 17 | my $newfil = catfile($newpath,$fil); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 17 | my $out; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 17 | ▶ | open $out,'>',$newfil or croak "Failed to check_out $fil, $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 17 | print $out $self->fetch->text; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 17 | close $out; | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 17 | my $pkg = ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 17 | $pkg->new($newfil,%args); | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | sub _assimilate { | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 53 | ▶ | my ($self,$lite,%args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assimilate: called CC=29 SCAR=33.7
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 53 | my @newgen = map { [' '.$_] } $lite->text; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 53 | my (@oldgen,@openers,@closers,$skip_to); | |||||||||||||||||||||||||||||||||||||||||
| 245 | 53 | ▶ | my $genbase = $args{generation} || $self->latest; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{'generation'} || $self->latest
MC/DC50%1/2
$args{'generation'} || $self->latest
$args{'generation'}
$self->latest
Truth table66%2/3
A || B
A= $args{'generation'}B= $self->latest
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 53 | ▶ | if (my $cont = $self->_contents) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 28 | for (@$cont) { | |||||||||||||||||||||||||||||||||||||||||
| 249 | 1118 | ▶ | if ($skip_to) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | push @openers, $_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | ▶ | if (/^=$skip_to$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | undef $skip_to; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 1114 | ▶ | if (my ($type,$gen) = /^([+-])(.+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 7 | ▶ | $oldgen[-1][2] = [@closers] if @closers; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 7 | @closers = (); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 7 | push @openers, $_; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 7 | ▶ | if (_is_parent_of($gen,$genbase) ^ ($type eq '+')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | $skip_to = $gen; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 1107 | ▶ | if (my ($gen) = /^=(.+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 5 | push @closers, $_; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 1102 | ▶ | if (/^ /) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 1102 | ▶ | $oldgen[-1][2] = [@closers] if @closers; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1102 | push @oldgen,[$_, [@openers]]; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 1102 | @openers = @closers = (); | |||||||||||||||||||||||||||||||||||||||||
| 273 | 1102 | next; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | croak "Invalid format in element contents"; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 28 | ▶ | $oldgen[-1][2] = [@closers] if @closers; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 25 | $self->_contents([map $_->[0], @newgen]); | |||||||||||||||||||||||||||||||||||||||||
| 280 | 25 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 28 | $genbase =~ s/(\d+)$/$1+1/e; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 28 | ▶ | my @sd = Algorithm::Diff::sdiff( \@oldgen, \@newgen, sub { $_[0][0] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 28 | my (@newcont,@pending); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 28 | my $prev = 'u'; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 28 | my $changed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 28 | for (@sd) { | |||||||||||||||||||||||||||||||||||||||||
| 290 | 1362 | my ($ind,$c1,$c2) = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 1362 | my @res1; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 1362 | ▶ | if ($c1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 1102 | @res1 = (@{$c1->[1]},$c1->[0]); | |||||||||||||||||||||||||||||||||||||||||
| 294 | 1102 | ▶ | push @res1,@{$c1->[2]} if defined $c1->[2]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 1362 | ▶ | my $res2 = $c2->[0] if $c2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 1362 | ▶ | push @newcont,"=$genbase\n" if ($prev ne 'u') && ($ind ne $prev); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev ne "u" and $ind ne $prev
MC/DC100%2/2
$prev ne "u" and $ind ne $prev
$prev ne "u"
$ind ne $prev
Truth table100%3/3
A and B
A= $prev ne "u"B= $ind ne $prev
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 1362 | ▶ | if (@pending && ($ind ne 'c')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@pending and $ind ne "c"
MC/DC100%2/2
@pending and $ind ne "c"
@pending
$ind ne "c"
Truth table100%3/3
A and B
A= @pendingB= $ind ne "c"
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 9 | push @newcont, @pending, "=$genbase\n"; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 9 | @pending=(); | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 1362 | ▶ | if (($prev =~ /[u+]/) && ($ind =~ /[c-]/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev =~ /[u+]/ and $ind =~ /[c-]/
MC/DC100%2/2
$prev =~ /[u+]/ and $ind =~ /[c-]/
$prev =~ /[u+]/
$ind =~ /[c-]/
Truth table100%3/3
A and B
A= $prev =~ /[u+]/B= $ind =~ /[c-]/
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 9 | push @newcont,"-$genbase\n"; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | $changed++; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 1362 | ▶ | if ($ind eq '+') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 260 | ▶ | push @newcont,"+$genbase\n" if ($prev ne $ind); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 260 | push @newcont, $res2; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 260 | $changed++; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 1102 | push @newcont, @res1; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 1362 | ▶ | if ($ind eq 'c') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 38 | ▶ | push @pending,"+$genbase\n" if ($prev ne $ind); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 38 | push @pending, $res2; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 1362 | $prev = $ind; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 28 | ▶ | push @newcont,"=$genbase\n" if ($prev ne 'u'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 28 | ▶ | return unless $changed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 14 | $self->_contents(\@newcont); | |||||||||||||||||||||||||||||||||||||||||
| 324 | 14 | $genbase; | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | sub _is_parent_of { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 67 | ▶ | my ($gen1,$gen2) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_parent_of: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 67 | my @g1v = split /\./,$gen1; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 67 | my @g2v = split /\./,$gen2; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 67 | ▶ | (shift @g1v,shift @g2v) while @g1v && @g2v && ($g1v[0] eq $g2v[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@g1v and @g2v and $g1v[0] eq $g2v[0]
@g1v and @g2v
MC/DC66%2/3
@g1v and @g2v and $g1v[0] eq $g2v[0]
@g1v
@g2v
$g1v[0] eq $g2v[0]
Truth table75%3/4
A and B and C
A= @g1vB= @g2vC= $g1v[0] eq $g2v[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 67 | ▶ | return 1 unless @g2v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 18 | ▶ | return 0 unless @g1v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 18 | ▶ | return 0 if @g1v > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 18 | $g1v[0] < $g2v[0]; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | sub _update_ctrl { | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 23 | ▶ | my ($self,%args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_ctrl: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 23 | ▶ | my $path = $args{path} || $self->{path}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{'path'} || $self->{'path'}
MC/DC0%0/2
$args{'path'} || $self->{'path'}
$args{'path'}
$self->{'path'}
Truth table33%1/3
A || B
A= $args{'path'}B= $self->{'path'}
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 23 | my ($vol,$dir,$fil) = splitpath($path); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 23 | $self->{$_} = $args{$_} for keys %args; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 23 | $self->{updated} = localtime->datetime; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 23 | $self->save; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | sub _contents { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 143 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_contents: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 143 | ▶ | $self->{contents} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 143 | ▶ | return unless exists $self->{contents}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 118 | $self->{contents}; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | sub _slurp_lite { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 50 | ▶ | my ($self,$name) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_slurp_lite: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 50 | VCS::Lite->new($name); | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | __END__ | ||||||||||||||||||||||||||||||||||||||||||