| 1 | package GitStore; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | $GitStore::AUTHORITY = 'cpan:YANICK'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 15 | $GitStore::VERSION = '0.15'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #ABSTRACT: Git as versioned data store in Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 15 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use Git::PurePerl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | ▶ | use Path::Class qw/ dir file /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 15 | ▶ | use List::Util qw/ first /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 15 | ▶ | use GitStore::Revision; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | ▶ | no warnings qw/ uninitialized /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 | subtype 'PurePerlActor' => | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | as 'Git::PurePerl::Actor'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | coerce PurePerlActor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | => from 'Str' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | => via { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | s/<(.*?)>//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | Git::PurePerl::Actor->new( name => $_, email => $1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 15 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 15 | has 'repo' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 15 | has 'branch' => ( is => 'rw', isa => 'Str', default => 'master' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | has author => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => 'PurePerlActor', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 14 | ▶ | Git::PurePerl::Actor->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | name => 'anonymous', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | email => 'anon@127.0.0.1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 15 | } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | has serializer => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 12 | ▶ | require Storable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | return sub { return Storable::nfreeze($_[2]); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 12 | }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | has deserializer => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | ▶ | require Storable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 16 | ▶ | my $data = $_[2]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 16 | my $magic = eval { Storable::read_magic($data); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 16 | ▶ | return $data unless $magic && $magic->{major} && $magic->{major} >= 2 && $magic->{major} <= 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$magic and $magic->{"major"} and $magic->{"major"} >= 2 and $magic->{"major"} <= 5
$magic and $magic->{"major"} and $magic->{"major"} >= 2
$magic and $magic->{"major"}
MC/DC25%1/4
$magic and $magic->{"major"} and $magic->{"major"} >= 2 and $magic->{"major"} <= 5
$magic
$magic->{"major"}
$magic->{"major"} >= 2
$magic->{"major"} <= 5
Truth table40%2/5
A and B and C and D
A= $magicB= $magic->{"major"}C= $magic->{"major"} >= 2D= $magic->{"major"} <= 5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | my $thawed = eval { Storable::thaw($data) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # false alarm... looked like a Storable, but wasn't. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | return $@ ? $data : $thawed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 12 | }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 15 | has autocommit => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | sub _clean_directories { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 37 | ▶ | my ( $self, $dir ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clean_directories: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 37 | ▶ | $dir ||= $self->root; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$dir ||= $self->root
MC/DC0%0/2
$dir ||= $self->root
$dir
$self->root
Truth table66%2/3
A ||= B
A= $dirB= $self->root
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 37 | my $nbr_files = keys %{ $dir->{FILES} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 37 | for my $d ( keys %{ $dir->{DIRS} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 14 | ▶ | if( my $f = $self->_clean_directories( $dir->{DIRS}{$d} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 13 | $nbr_files += $f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | delete $dir->{DIRS}{$d}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 37 | return $nbr_files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | sub _expand_directories { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 48 | ▶ | my( $self, $object ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expand_directories: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 48 | my %dir = ( DIRS => {}, FILES => {} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 48 | for my $entry ( map { $_->directory_entries } $object ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 59 | ▶ | if ( $entry->object->isa( 'Git::PurePerl::Object::Tree' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 17 | $dir{DIRS}{$entry->filename} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | = $self->_expand_directories( $entry->object ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 42 | $dir{FILES}{$entry->filename} = $entry->sha1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 48 | return \%dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 14 | ▶ | has 'root' => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | has 'git' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | isa => 'Git::PurePerl', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 14 | ▶ | my $repo = $_[0]->repo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 14 | ▶ | return Git::PurePerl->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ( $repo =~ m/\.git$/ ? 'gitdir' : 'directory') => $repo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 15 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 14 | $self->load(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 14 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 14 | ▶ | if ( @_ == 1 && ! ref $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and not ref $_[0]
MC/DC50%1/2
@_ == 1 and not ref $_[0]
@_ == 1
not ref $_[0]
Truth table66%2/3
A and not(B)
A= @_ == 1B= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 7 | return { repo => $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 7 | return $class->SUPER::BUILDARGS(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | sub branch_head { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 44 | ▶ | my ( $self, $branch ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
branch_head: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 44 | ▶ | $branch ||= $self->branch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$branch ||= $self->branch
MC/DC0%0/2
$branch ||= $self->branch
$branch
$self->branch
Truth table33%1/3
A ||= B
A= $branchB= $self->branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 44 | return $self->git->ref_sha1('refs/heads/' . $branch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # Load the current head version from repository. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 38 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 38 | ▶ | my $head = $self->branch_head or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 9 | $self->root({ DIRS => {}, FILES => {} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 29 | my $commit = $self->git->get_object($head); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 29 | my $tree = $commit->tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 29 | my $root = $self->_expand_directories( $tree ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 29 | $self->root($root); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | sub _normalize_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 54 | ▶ | my ( $self, $path ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_path: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 54 | ▶ | $path = join '/', @$path if ref $path eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # Git doesn't like paths prefixed with a '/' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 54 | $path =~ s#^/+##; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 54 | return $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | sub get_revision { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ▶ | my ( $self, $path ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_revision: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | $path = file( $self->_normalize_path($path) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | ▶ | my $head = $self->branch_head | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | my $commit = $self->git->get_object($head); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | my @q = ( $commit ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | ▶ | my $file = $self->_find_file( $commit->tree, $path ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | my $latest_file_sha1 = $file->object->sha1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my $last_commit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | ▶ | while ( @q ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | push @q, $q[0]->parents; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | $last_commit = $commit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $commit = shift @q; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | ▶ | my $f = $self->_find_file( $commit->tree, file($path) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | ▶ | last if $f->object->sha1 ne $latest_file_sha1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | return GitStore::Revision->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | gitstore => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | sha1 => $last_commit->sha1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 19 | ▶ | my ( $self, $path ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 19 | $path = file( $self->_normalize_path($path) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 19 | ▶ | my $dir = $self->_cd_dir($path) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 19 | ▶ | my $sha1 = $dir->{FILES}{$path->basename} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 12 | ▶ | my $object = $self->git->get_object($sha1) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 12 | return $self->deserializer->($self,$path,$object->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 27 | ▶ | my ( $self, $path, $content ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 27 | $path = file( $self->_normalize_path($path) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 27 | ▶ | my $dir = $self->_cd_dir($path,1) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 27 | ▶ | $content = $self->serializer->( $self, $path, $content ) if ref $content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 27 | my $blob = Git::PurePerl::NewObject::Blob->new( content => $content ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 27 | $self->git->put_object($blob); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 27 | return $dir->{FILES}{$path->basename} = $blob->sha1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | after [ 'set', 'delete' ] => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 34 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 34 | ▶ | $self->commit if $self->autocommit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 15 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 15 | *remove = \&delete; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | sub delete { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 7 | ▶ | my ( $self, $path ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 7 | $path = file( $self->_normalize_path($path) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 7 | ▶ | my $dir = $self->_cd_dir($path) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 7 | return delete $dir->{FILES}{$path->basename}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | sub _cd_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 53 | ▶ | my( $self, $path, $create ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cd_dir: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 53 | my $dir = $self->root; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 53 | for ( grep { !/^\.$/ } $path->dir->dir_list ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 17 | ▶ | if ( $dir->{DIRS}{$_} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 11 | $dir = $dir->{DIRS}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 6 | ▶ | return unless $create; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 6 | $dir = $dir->{DIRS}{$_} = { DIRS => {}, FILES => {} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 53 | return $dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | sub _build_new_directory_entry { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 38 | ▶ | my( $self, $dir ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_new_directory_entry: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 38 | my @children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 38 | ▶ | while ( my( $filename, $sha1 ) = each %{ $dir->{FILES} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 30 | push @children, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | Git::PurePerl::NewDirectoryEntry->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | mode => '100644', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | filename => $filename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | sha1 => $sha1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 38 | ▶ | while ( my( $dirname, $dir ) = each %{ $dir->{DIRS} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 15 | my $tree = $self->_build_new_directory_entry($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 15 | push @children, Git::PurePerl::NewDirectoryEntry->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | mode => '040000', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | filename => $dirname, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | sha1 => $tree->sha1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 38 | my $tree = Git::PurePerl::NewObject::Tree->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | directory_entries => \@children, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 38 | $self->git->put_object($tree); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 38 | return $tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | sub commit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 23 | ▶ | my ( $self, $message ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 23 | ▶ | unless ( $self->_clean_directories ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # TODO surely there's a better way? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | $self->set( '.gitignore/dummy', 'dummy file to keep git happy' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # TODO only commit if there were changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 23 | my $tree = $self->_build_new_directory_entry( $self->root ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # there might not be a parent, if it's a new branch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 23 | my $parent = eval { $self->git->ref( 'refs/heads/'.$self->branch )->sha1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 23 | my $timestamp = DateTime->now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 23 | ▶ | my $commit = Git::PurePerl::NewObject::Commit->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$message || ''
MC/DC100%1/1
$message || ''
$message
Truth table100%2/2
A
A= $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ( parent => $parent ) x !!$parent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | tree => $tree->sha1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | author => $self->author, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | committer => $self->author, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | comment => $message||'', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | authored_time => $timestamp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | committed_time => $timestamp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 23 | $self->git->put_object($commit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # reload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 23 | $self->load; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | sub discard { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
discard: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | $self->load; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | sub _find_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 42 | ▶ | my( $self, $tree, $path ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_file: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 42 | my @path = grep { !/^\.$/ } $path->dir->dir_list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 42 | ▶ | if ( my $part = shift @path ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 18 | ▶ | my $entry = first { $_->filename eq $part } $tree->directory_entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 18 | my $object = $self->git->get_object( $entry->sha1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 18 | ▶ | return unless ref $object eq 'Git::PurePerl::Object::Tree'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 18 | return $self->_find_file( $object, file(@path,$path->basename) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 24 | ▶ | return first { $_->filename eq $path->basename } $tree->directory_entries; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | sub history { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 3 | ▶ | my ( $self, $path ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
history: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | ▶ | my $head = $self->branch_head | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 3 | my @q = ( $self->git->get_object($head) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 3 | my @commits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 3 | ▶ | while ( @q ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 16 | push @q, $q[0]->parents; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 16 | unshift @commits, shift @q; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 3 | my @history_commits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | my %sha1_seen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 3 | for my $c ( @commits ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 16 | ▶ | my $file = $self->_find_file( $c->tree, file($path) ) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 14 | ▶ | push @history_commits, $c unless $sha1_seen{ $file->object->sha1 }++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | return map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | GitStore::Revision->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | gitstore => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | sha1 => $_->sha1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } @history_commits; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | sub list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 2 | ▶ | my( $self, $regex ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 2 | ▶ | croak "'$regex' is not a a regex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$regex and ref $regex ne "Regexp"
MC/DC0%0/2
$regex and ref $regex ne "Regexp"
$regex
ref $regex ne "Regexp"
Truth table66%2/3
A and B
A= $regexB= ref $regex ne "Regexp"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | if $regex and ref $regex ne 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | ▶ | my $head = $self->branch_head or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | my $commit = $self->git->get_object($head); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2 | my $tree = $commit->tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 2 | my $root = $self->_expand_directories( $tree ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 2 | my @dirs = ( [ '', $root ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | my @entries; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | ▶ | while( my $dir = shift @dirs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 2 | my $path = $dir->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 2 | $dir = $dir->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | push @dirs, [ "$path/$_" => $dir->{DIRS}{$_} ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 2 | for sort keys %{$dir->{DIRS}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | for ( sort keys %{$dir->{FILES}} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 4 | my $f = "$path/$_"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 4 | $f =~ s#^/##; # TODO improve this | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | ▶ | next if $regex and $f !~ $regex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$regex and not $f =~ /$regex/
MC/DC100%2/2
$regex and not $f =~ /$regex/
$regex
not $f =~ /$regex/
Truth table100%3/3
A and not(B)
A= $regexB= not $f =~ /$regex/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 3 | push @entries, $f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | return @entries; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 15 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 15 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | GitStore - Git as versioned data store in Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | version 0.15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | use GitStore; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | my $gs = GitStore->new('/path/to/repo'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | $gs->set( 'users/obj.txt', $obj ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | $gs->set( ['config', 'wiki.txt'], { hash_ref => 1 } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | $gs->commit(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | $gs->set( 'yyy/xxx.log', 'Log me' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | $gs->discard(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # later or in another pl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | my $val = $gs->get( 'user/obj.txt' ); # $val is the same as $obj | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | my $val = $gs->get( 'config/wiki.txt' ); # $val is { hashref => 1 } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | my $val = $gs->get( ['yyy', 'xxx.log' ] ); # $val is undef since discard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | It is inspired by the Python and Ruby binding. check SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | GitStore->new('/path/to/repo'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | GitStore->new( repo => '/path/to/repo', branch => 'mybranch' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | GitStore->new( repo => '/path/to/repo', author => 'Someone Unknown <unknown\@what.com>' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | =item repo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | your git directory or work directory (I<GitStore> will assume it's a work | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | directory if it doesn't end with C<.git>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | =item branch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | your branch name, default is 'master' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | =item author | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | It is used in the commit info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | =item serializer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | Can be used to define a serializing function that will be used if the value to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | save is a reference. When invoked, the function will be passed a reference to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | the store object, the path under which the value will be saved, and the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | itself. For example, one could do different serialization via: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | my $store = GitStore->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | repo => '/path/to/repo', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | serializer => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | my( $store, $path, $value ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | if ( $path =~ m#^json# ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | return encode_json($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # defaults to YAML | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | return YAML::Dump($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | The default serializer uses L<Storable/nfreeze>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | =item deserializer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | Called when a value is picked from the store to be (potentially) deserialized. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | Just like the serializer function, it is passed three arguments: the store | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | object, the path of the value to deserialize and the value itself. To revisit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | the example for C<serializer>, the full serializer/deserializer dance would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | be: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | my $store = GitStore->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | repo => '/path/to/repo', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | serializer => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | my( $store, $path, $value ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | return $path =~ m#^json# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | ? encode_json($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | : YAML::Dump($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | deserializer => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | my( $store, $path, $value ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | return $path =~ #^json# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | ?decode_json($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | : YAML::Load($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | The default deserializer will try to deserialize the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | retrieved from the store via L<Storable/thaw> and, if this fails, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | return the value verbatim. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | =item autocommit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | If set to C<true>, any call to C<set()> or C<delete()> will automatically call an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | implicit C<commit()>. Defaults to C<false>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | =head2 set($path, $val) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | $gs->set( 'yyy/xxx.log', 'Log me' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | $gs->set( ['config', 'wiki.txt'], { hash_ref => 1 } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | $gs->set( 'users/obj.txt', $obj ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | Store $val as a $path file in Git | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | $path can be String or ArrayRef. Any leading slashes ('/') in the path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | will be stripped, as to make it a valid Git path. The same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | grooming is done for the C<get()> and C<delete()> methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | $val can be String or Ref[HashRef|ArrayRef|Ref[Ref]] or blessed Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | =head2 get($path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | $gs->get( 'user/obj.txt' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | $gs->get( ['yyy', 'xxx.log' ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | Get $val from the $path file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | $path can be String or ArrayRef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | =head2 get_revision( $path ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | Like C<get()>, but returns the L<GitStore::Revision> object corresponding to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | the latest Git revision on the monitored branch for which C<$path> changed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | =head2 delete($path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | =head2 remove($path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | remove $path from Git store | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | =head2 commit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | $gs->commit(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | $gs->commit('Your Comments Here'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | commit the B<set> changes into Git | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | =head2 discard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | $gs->discard(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | discard the B<set> changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | =head2 history($path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | Returns a list of L<GitStore::Revision> objects representing the changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | brought to the I<$path>. The changes are returned in ascending commit order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | =head2 list($regex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | @entries = $gs->list( qr/\.txt$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | Returns a list of all entries in the repository, possibly filtered by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | optional I<$regex>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | =head1 FAQ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | =head2 why the files are B<not> there? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | git checkout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | =head2 any example? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | # if you just need a local repo, that's all you need. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | mkdir sandbox | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | cd sandbox | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | git init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # use GitStore->new('/path/to/this/sandbox') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # set something | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | git checkout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # follows are for remote git url | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | git remote add origin git@github.com:fayland/sandbox2.git | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | git push origin master | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # do more GitStore->new('/path/to/this/sandbox') later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | git checkout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | git pull origin master | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | git push | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | =head1 KNOWN BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | If all files are deleted from the repository, a 'dummy' file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | will be created to keep Git happy. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | =item Article | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | L<http://www.newartisans.com/2008/05/using-git-as-a-versioned-data-store-in-python.html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | =item Python binding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | L<http://github.com/jwiegley/git-issues/tree/master> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | =item Ruby binding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | L<http://github.com/georgi/git_store/tree/master> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | =head1 Git URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | L<http://github.com/fayland/perl-git-store/tree/master> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | Fayland Lam <fayland@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | Yanick Champoux <yanick@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | This software is copyright (c) 2013 by Fayland Lam <fayland@gmail.com>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||