| 1 | package VCS::Which::Plugin::Subversion; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | # Created on: 2009-05-16 16:58:03 | ||||||||||||||||||||||||||||||||
| 4 | # Create by: ivan | ||||||||||||||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use version; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Data::Dumper qw/Dumper/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use File::chdir; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Contextual::Return; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | extends 'VCS::Which::Plugin'; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 2 | our $VERSION = version->new('0.6.9'); | |||||||||||||||||||||||||||||||
| 23 | 2 | our $name = 'Subversion'; | |||||||||||||||||||||||||||||||
| 24 | 2 | our $exe = 'svn'; | |||||||||||||||||||||||||||||||
| 25 | 2 | our $meta = '.svn'; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | sub installed { | ||||||||||||||||||||||||||||||
|
Subroutine
installed: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 28 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | return $self->_installed if defined $self->_installed; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 1 | for my $path (split /[:;]/, $ENV{PATH}) { | |||||||||||||||||||||||||||||||
| 33 | 10 | ▶ | next if !-x "$path/$exe"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 0 | return $self->_installed( 1 ); | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 1 | return $self->_installed( 0 ); | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 21 | ▶ | sub used { | ||||||||||||||||||||||||||||||
|
Subroutine
used: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | 21 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 21 | ▶ | if (-f $dir) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | $dir = path($dir)->parent; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 21 | ▶ | croak "$dir is not a directory!" if !-d $dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 20 | return -d "$dir/$meta"; | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub uptodate { | ||||||||||||||||||||||||||||||
|
Subroutine
uptodate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 54 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $dir ||= $self->_base; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$dir ||= $self->_base
MC/DC0%0/2
$dir ||= $self->_base
$dir
$self->_base
Truth table0%0/3
A ||= B
A= $dirB= $self->_base
| |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | croak "'$dir' is not a directory!" if !-e $dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | local $CWD = $dir; | |||||||||||||||||||||||||||||||
| 61 | 0 | my @lines = `$exe status`; | |||||||||||||||||||||||||||||||
| 62 | 0 | pop @lines; | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | return !@lines; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub pull { | ||||||||||||||||||||||||||||||
|
Subroutine
pull: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 68 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $dir ||= $self->_base; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$dir ||= $self->_base
MC/DC0%0/2
$dir ||= $self->_base
$dir
$self->_base
Truth table0%0/3
A ||= B
A= $dirB= $self->_base
| |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | croak "'$dir' is not a directory!" if !-e $dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 0 | local $CWD = $dir; | |||||||||||||||||||||||||||||||
| 75 | 0 | return !system "$exe update > /dev/null 2> /dev/null"; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub cat { | ||||||||||||||||||||||||||||||
|
Subroutine
cat: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 79 | 0 | my ($self, $file, $revision) = @_; | |||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( $revision && $revision =~ /^-\d+$/xms ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$revision and $revision =~ /^-\d+$/msx
MC/DC0%0/2
$revision and $revision =~ /^-\d+$/msx
$revision
$revision =~ /^-\d+$/msx
Truth table0%0/3
A and B
A= $revisionB= $revision =~ /^-\d+$/msx
| |||||||||||||||||||||||||||||||||
| 82 | 0 | my @versions = reverse `$exe log -q $file` =~ /^ r(\d+) \s/gxms; | |||||||||||||||||||||||||||||||
| 83 | 0 | $revision = $versions[$revision]; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | elsif ( !defined $revision ) { | ||||||||||||||||||||||||||||||||
| 86 | 0 | $revision = ''; | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $revision &&= "-r$revision"; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$revision &&= "-r$revision"
MC/DC0%0/1
$revision &&= "-r$revision"
$revision
Truth table0%0/2
A
A= $revision
| |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | return `$exe cat $revision $file`; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 95 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 0 | my $args = join ' ', map {"'$_'"} @args; | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | return | ||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | SCALAR { scalar `$exe log $args` } | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | ARRAYREF { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||
| 102 | 0 | my @raw_log = `$exe log $args`; | |||||||||||||||||||||||||||||||
| 103 | 0 | my @log; | |||||||||||||||||||||||||||||||
| 104 | 0 | my $line = ''; | |||||||||||||||||||||||||||||||
| 105 | 0 | for my $raw (@raw_log) { | |||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( $raw eq ( '-' x 72 ) . "\n" && $line ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$raw eq "------------------------------------------------------------------------\n" and $line
MC/DC0%0/2
$raw eq "------------------------------------------------------------------------\n" and $line
$raw eq "------------------------------------------------------------------------\n"
$line
Truth table0%0/3
A and B
A= $raw eq "------------------------------------------------------------------------\n"B= $line
| |||||||||||||||||||||||||||||||||
| 107 | 0 | CORE::push @log, $line; | |||||||||||||||||||||||||||||||
| 108 | 0 | $line = ''; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | elsif ( $raw ne ( '-' x 72 ) . "\n" ) { | ||||||||||||||||||||||||||||||||
| 111 | 0 | $line .= $raw; | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | 0 | return \@log; | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | HASHREF { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 118 | 0 | my $logs = `$exe log $args`; | |||||||||||||||||||||||||||||||
| 119 | 0 | my @logs = split /^-+\n/xms, $logs; | |||||||||||||||||||||||||||||||
| 120 | 0 | shift @logs; | |||||||||||||||||||||||||||||||
| 121 | 0 | my $num = @logs; | |||||||||||||||||||||||||||||||
| 122 | 0 | my %log; | |||||||||||||||||||||||||||||||
| 123 | 0 | for my $log (@logs) { | |||||||||||||||||||||||||||||||
| 124 | 0 | my ($details, $description) = split /\n\n?/, $log, 2; | |||||||||||||||||||||||||||||||
| 125 | 0 | $description =~ s/\s+\Z//xms; | |||||||||||||||||||||||||||||||
| 126 | 0 | $details =~ s/^\s*(.*?)\s*/$1/; | |||||||||||||||||||||||||||||||
| 127 | 0 | my @details = split /\s+\|\s+/, $details; | |||||||||||||||||||||||||||||||
| 128 | 0 | $details[0] =~ s/^r//; | |||||||||||||||||||||||||||||||
| 129 | 0 | $log{$num--} = { | |||||||||||||||||||||||||||||||
| 130 | rev => $details[0], | ||||||||||||||||||||||||||||||||
| 131 | Author => $details[1], | ||||||||||||||||||||||||||||||||
| 132 | Date => $details[2], | ||||||||||||||||||||||||||||||||
| 133 | description => $description, | ||||||||||||||||||||||||||||||||
| 134 | }, | ||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | 0 | return \%log; | |||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | 0 | } | |||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub versions { | ||||||||||||||||||||||||||||||
|
Subroutine
versions: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 141 | 0 | my ($self, $file, $oldest, $newest, $max) = @_; | |||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 0 | $file = path($file); | |||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | local $CWD = -d $file ? $file : $file->parent; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | my %logs = %{ $self->log(-d $file ? '.' : $file->basename, $max ? "--limit $max" : '') }; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 146 | 0 | my @versions; | |||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 0 | for my $log (sort {$a <=> $b} keys %logs) { | |||||||||||||||||||||||||||||||
| 149 | 0 | push @versions, $logs{$log}{rev};# if $oldest && $logs{$log}{rev} <= $oldest; | |||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 0 | return @versions; | |||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 2 | 1; | |||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||