line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
2
|
|
993
|
use Moo; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
13
|
|
10
|
2
|
|
|
2
|
|
647
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
11
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
53
|
|
12
|
2
|
|
|
2
|
|
21
|
use version; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
11
|
|
13
|
2
|
|
|
2
|
|
148
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
104
|
|
14
|
2
|
|
|
2
|
|
12
|
use Data::Dumper qw/Dumper/; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
95
|
|
15
|
2
|
|
|
2
|
|
12
|
use English qw/ -no_match_vars /; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
16
|
2
|
|
|
2
|
|
732
|
use Path::Tiny; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
91
|
|
17
|
2
|
|
|
2
|
|
12
|
use File::chdir; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
137
|
|
18
|
2
|
|
|
2
|
|
11
|
use Contextual::Return; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
14
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
extends 'VCS::Which::Plugin'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = version->new('0.6.9'); |
23
|
|
|
|
|
|
|
our $name = 'Subversion'; |
24
|
|
|
|
|
|
|
our $exe = 'svn'; |
25
|
|
|
|
|
|
|
our $meta = '.svn'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub installed { |
28
|
6
|
|
|
6
|
1
|
8
|
my ($self) = @_; |
29
|
|
|
|
|
|
|
|
30
|
6
|
100
|
|
|
|
27
|
return $self->_installed if defined $self->_installed; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
9
|
for my $path (split /[:;]/, $ENV{PATH}) { |
33
|
9
|
50
|
|
|
|
153
|
next if !-x "$path/$exe"; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
return $self->_installed( 1 ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
17
|
return $self->_installed( 0 ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub used { |
42
|
21
|
|
|
21
|
1
|
45
|
my ( $self, $dir ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
21
|
50
|
|
|
|
197
|
if (-f $dir) { |
45
|
0
|
|
|
|
|
0
|
$dir = path($dir)->parent; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
21
|
100
|
|
|
|
319
|
croak "$dir is not a directory!" if !-d $dir; |
49
|
|
|
|
|
|
|
|
50
|
20
|
|
|
|
|
291
|
return -d "$dir/$meta"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub uptodate { |
54
|
0
|
|
|
0
|
1
|
|
my ( $self, $dir ) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
0
|
|
|
|
$dir ||= $self->_base; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
croak "'$dir' is not a directory!" if !-e $dir; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
local $CWD = $dir; |
61
|
0
|
|
|
|
|
|
my @lines = `$exe status`; |
62
|
0
|
|
|
|
|
|
pop @lines; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return !@lines; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub pull { |
68
|
0
|
|
|
0
|
1
|
|
my ( $self, $dir ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
0
|
|
|
|
$dir ||= $self->_base; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
croak "'$dir' is not a directory!" if !-e $dir; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
local $CWD = $dir; |
75
|
0
|
|
|
|
|
|
return !system "$exe update > /dev/null 2> /dev/null"; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub cat { |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $file, $revision) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
0
|
|
|
|
if ( $revision && $revision =~ /^-\d+$/xms ) { |
|
|
0
|
|
|
|
|
|
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
|
|
0
|
|
|
|
$revision &&= "-r$revision"; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return `$exe cat $revision $file`; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub log { |
95
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $args = join ' ', map {"'$_'"} @args; |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return |
100
|
0
|
|
|
0
|
|
|
SCALAR { scalar `$exe log $args` } |
101
|
|
|
|
|
|
|
ARRAYREF { |
102
|
0
|
|
|
0
|
|
|
my @raw_log = `$exe log $args`; |
103
|
0
|
|
|
|
|
|
my @log; |
104
|
0
|
|
|
|
|
|
my $line = ''; |
105
|
0
|
|
|
|
|
|
for my $raw (@raw_log) { |
106
|
0
|
0
|
0
|
|
|
|
if ( $raw eq ( '-' x 72 ) . "\n" && $line ) { |
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
HASHREF { |
118
|
0
|
|
|
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
|
|
|
|
|
|
|
sub versions { |
141
|
0
|
|
|
0
|
1
|
|
my ($self, $file, $oldest, $newest, $max) = @_; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
$file = path($file); |
144
|
0
|
0
|
|
|
|
|
local $CWD = -d $file ? $file : $file->parent; |
145
|
0
|
0
|
|
|
|
|
my %logs = %{ $self->log(-d $file ? '.' : $file->basename, $max ? "--limit $max" : '') }; |
|
0
|
0
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my @versions; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
for my $log (sort {$a <=> $b} keys %logs) { |
|
0
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
push @versions, $logs{$log}{rev};# if $oldest && $logs{$log}{rev} <= $oldest; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return @versions; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__END__ |