blib/lib/SVN/Web/Revision.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/SVN/Web/RSS.pm ↑ Summary blib/lib/SVN/Web/View.pm »
1 package SVN::Web::Revision;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use base 'SVN::Web::action';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use Encode ();
9 use SVN::Core;
10 use SVN::Ra;
11 use SVN::Web::X;
12 use SVN::Web::DiffParser;
13  
14 our $VERSION = 0.63;
15  
16 =head1 NAME
17  
18 SVN::Web::Revision - SVN::Web action to view a repository revision
19  
20 =head1 SYNOPSIS
21  
22 In F<config.yaml>
23  
24 actions:
25 ...
26 revision:
27 class: SVN::Web::Revision
28 opts:
29 max_diff_size: 200_000
30 show_diff: 1 # or 0
31 ...
32  
33 =head1 DESCRIPTION
34  
35 Shows information about a specific revision in a Subversion repository.
36  
37 =head1 CONFIGURATION
38  
39 The following configuration options may be specified in F<config.yaml>.
40  
41 =over
42  
43 =item max_diff_size
44  
45 If showing the diff (see C<show_diff>), this determines the maximum size
46 of the diff that will be shown. If the size of the generated diff (in
47 bytes) is larger than this figure then it is not shown.
48  
49 Defaults to 200,000 bytes.
50  
51 =item show_diff
52  
53 Boolean indicating whether or not a diff of every file that was changed
54 in the revision should be shown.
55  
56 Defaults to 1.
57  
58 =back
59  
60 =head1 OPTIONS
61  
62 =over 8
63  
64 =item rev
65  
66 The revision to show. If not provided then use the repository's
67 youngest revision.
68  
69 =back
70  
71 =head1 TEMPLATE VARIABLES
72  
73 =over 8
74  
75 =item context
76  
77 Always C<revision>.
78  
79 =item rev
80  
81 The revision that is being shown.
82  
83 =item youngest_rev
84  
85 The repository's youngest revision. This is useful when constructing
86 C<next revision> and C<previous revision> links.
87  
88 =item date
89  
90 The date on which the revision was committed, formatted according to
91 L<SVN::Web/"Time and date formatting">.
92  
93 =item author
94  
95 The revision's author.
96  
97 =item msg
98  
99 The log message associated with this revision.
100  
101 =item paths
102  
103 A hash of hash refs. Each key is a path name. The value is a further hash ref
104 with the following keys.
105  
106 =over 8
107  
108 =item isdir
109  
110 A boolean value, true if the given path is a directory.
111  
112 =item diff
113  
114 A L<SVN::Web::DiffParser> object representing the diff. This may be undef,
115 if the generated diff was larger than C<max_diff_size> or if C<show_diff>
116 is false.
117  
118 =item diff_size
119  
120 The size of the generated diff (before parsing).
121  
122 =item max_diff_size
123  
124 The configured maximum diff size.
125  
126 =item action
127  
128 A single letter indicating the action that carried out on the path. A
129 file was either added C<A>, modified C<M>, replaced C<R>, or deleted
130 C<D>.
131  
132 =item copyfrom
133  
134 If the file was copied from another file then this is the path of the
135 source of the copy.
136  
137 =item copyfromrev
138  
139 If the file was copied from another file then this is the revision of
140 the file that it was copied form.
141  
142 =back
143  
144 =back
145  
146 =head1 EXCEPTIONS
147  
148 =over 4
149  
150 =item (revision %1 does not exist)
151  
152 The given revision does not exist in the repository.
153  
154 =back
155  
156 =cut
157  
158 my %default_opts = (
159 max_diff_size => 200_000,
160 show_diff => 1,
161 );
162  
163 sub _log {
164 my ( $self, $paths, $rev, $author, $date, $msg, $pool ) = @_;
165  
166 my $data = {
167 rev => $rev,
168 author => $author,
169 date => $self->format_svn_timestamp($date),
170 msg => Encode::decode('utf8',$msg),
171 };
172  
173 $data->{paths} = {
174 map {
175 $self->decode_svn_uri($_) => {
176 action => $paths->{$_}->action(),
177 copyfrom => $paths->{$_}->copyfrom_path(),
178 copyfromrev => $paths->{$_}->copyfrom_rev(),
179 }
180 } keys %$paths
181 };
182  
183 return $data;
184 }
185  
186 sub cache_key {
187 my $self = shift;
188  
189 return $self->{cgi}->param('rev') if defined $self->{cgi}->param('rev');
190  
191 return $self->{repos}{ra}->get_latest_revnum();
192 }
193  
194 sub run {
195 my $self = shift;
196  
197 $self->{opts} = { %default_opts, %{ $self->{opts} } };
198  
199 my $ra = $self->{repos}{ra};
200 my $yrev = $ra->get_latest_revnum();
201  
202 my $uri = $self->{repos}{uri};
203  
204 my $rev = $self->{cgi}->param('rev');
205 my $max_diff_size = $self->{opts}{max_diff_size};
206  
207 $rev = $yrev unless defined $rev;
208  
209 SVN::Web::X->throw(
210 error => '(revision %1 does not exist)',
211 vars => [$rev]
212 ) if $rev > $yrev;
213  
214 $ra->get_log( [''], $rev, $rev, 1, 1, 1,
215 sub { $self->{REV} = $self->_log(@_) } );
216  
217 $self->_resolve_changed_paths();
218  
219 my $diff;
220 my $diff_size = 0;
221 if ( $self->{opts}{show_diff} ) {
222 my $out = Encode::decode('utf8', $self->svn_get_diff($uri, $rev - 1, $uri, $rev, 1));
223 $diff_size = length($out);
224 if ( $diff_size <= $max_diff_size ) {
225 $diff = SVN::Web::DiffParser->new($out);
226 }
227 }
228  
229 return {
230 template => 'revision',
231 data => {
232 context => 'revision',
233 rev => $rev,
234 youngest_rev => $yrev,
235 diff => $diff,
236 diff_size => $diff_size,
237 max_diff_size => $max_diff_size,
238 %{ $self->{REV} },
239 }
240 };
241 }
242  
243 # Add 'isdir' keys to the paths if appropriate.
244 #
245 # This code used to be in get_log() when it used the repos layer. When
246 # the code was changed to use the ra layer it had to be moved out, as you
247 # can't call ra functions from a get_log() callback.
248 #
249 # XXX Very similar code in Log.pm, needs refactoring
250 sub _resolve_changed_paths {
251 my $self = shift;
252 my $uri = $self->{repos}{uri};
253 my $data = $self->{REV};
254  
255 my $subpool = SVN::Pool->new();
256 # Set the 'isdir' key
257 foreach my $path ( keys %{ $data->{paths} } ) {
258 # Ignore deleted nodes
259 if ( $data->{paths}{$path}{action} ne 'D' ) {
260 my $node_kind = $self->svn_get_node_kind("$uri$path", $data->{rev}, $data->{rev}, $subpool);
261  
262 $data->{paths}{$path}{isdir} = $node_kind == $SVN::Node::dir;
263 }
264  
265 $subpool->clear();
266 }
267 }
268  
269 1;
270  
271 =head1 COPYRIGHT
272  
273 Copyright 2003-2004 by Chia-liang Kao C<< <clkao@clkao.org> >>.
274  
275 Copyright 2005-2007 by Nik Clayton C<< <nik@FreeBSD.org> >>.
276  
277 This program is free software; you can redistribute it and/or modify it
278 under the same terms as Perl itself.
279  
280 See L<http://www.perl.com/perl/misc/Artistic.html>
281  
282 =cut
« blib/lib/SVN/Web/RSS.pm ↑ Summary blib/lib/SVN/Web/View.pm »