blib/lib/SVN/Web/Log.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/List.pm ↑ Summary blib/lib/SVN/Web/RSS.pm »
1 package SVN::Web::Log;
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  
12 our $VERSION = 0.62;
13  
14 =head1 NAME
15  
16 SVN::Web::Log - SVN::Web action to show log messages for a repository path
17  
18 =head1 SYNOPSIS
19  
20 In F<config.yaml>
21  
22 actions:
23 ...
24 log:
25 class: SVN::Web::Log
26 action_menu:
27 show:
28 - file
29 - directory
30 link_text: (view revision log)
31 ...
32  
33 =head1 DESCRIPTION
34  
35 Shows log messages (in reverse order) for interesting revisions of a given
36 file or directory in the repository.
37  
38 =head1 OPTIONS
39  
40 =over 8
41  
42 =item limit
43  
44 The number of log entries to retrieve. The default is 20.
45  
46 =item rev
47  
48 The repository revision to start with. The default is the repository's
49 youngest revision.
50  
51 =back
52  
53 =head1 TEMPLATE VARIABLES
54  
55 =over 8
56  
57 =item context
58  
59 Either C<directory> or C<file>.
60  
61 =item at_head
62  
63 A boolean value, true if the log starts with the most recent revision.
64  
65 =item at_oldest
66  
67 A boolean value, true if the list of revisions (C<revs>) includes the oldest
68 revision for this path.
69  
70 =item isdir
71  
72 A boolean value, true if the given path is a directory.
73  
74 =item rev
75  
76 The repository revision that the log starts with.
77  
78 =item revs
79  
80 A list of hashes. Each entry corresponds to a particular repository revision,
81 and has the following keys.
82  
83 =over 8
84  
85 =item rev
86  
87 The repository revision this entry is for.
88  
89 =item youngest_rev
90  
91 The repository's youngest revision.
92  
93 =item author
94  
95 The author of this change.
96  
97 =item date
98  
99 The date of this change, formatted according to
100 L<SVN::Web/"Time and date formatting">.
101  
102 =item msg
103  
104 The log message for this change.
105  
106 =item paths
107  
108 A list of hashes containing information about the paths that were
109 changed with this commit. Each hash key is the path name that was
110 modified with this commit. Each key is a hash ref of extra
111 information about the change to this path. These hash refs have the
112 following keys.
113  
114 =over 8
115  
116 =item action
117  
118 A single letter indicating the action that was carried out on the
119 path. A file was either added C<A>, modified C<M>, replaced C<R>,
120 or deleted C<D>.
121  
122 =item copyfrom
123  
124 If the file was copied from another file then this is the path of the
125 source of the copy.
126  
127 =item copyfromrev
128  
129 If the file was copied from another file then this is the revision of
130 the file that it was copied from.
131  
132 =back
133  
134 =back
135  
136 =item limit
137  
138 The value of the C<limit> parameter.
139  
140 =back
141  
142 =head1 EXCEPTIONS
143  
144 None.
145  
146 =cut
147  
148 sub _log {
149 my ( $self, $paths, $rev, $author, $date, $msg, $pool ) = @_;
150  
151 return unless $rev > 0;
152  
153 my $data = {
154 rev => $rev,
155 author => $author,
156 date => $self->format_svn_timestamp($date),
157 msg => Encode::decode('utf8',$msg),
158 };
159  
160 $data->{paths} = {
161 map {
162 $_ => {
163 action => $paths->{$_}->action(),
164 copyfrom => $paths->{$_}->copyfrom_path(),
165 copyfromrev => $paths->{$_}->copyfrom_rev(),
166 }
167 } keys %$paths
168 };
169  
170 push @{ $self->{REVS} }, $data;
171 }
172  
173 sub cache_key {
174 my $self = shift;
175 my $path = $self->{path};
176  
177 my ( undef, undef, $act_rev, $head ) = $self->get_revs();
178  
179 my $limit = $self->_get_limit();
180  
181 return "$act_rev:$limit:$head:$path";
182 }
183  
184 # Obtain the correct 'limit' value. Use the CGI parameter if it's defined,
185 # supporting the special value 'all' to mean all revisions. Default to 20
186 # if it's not defined.
187 sub _get_limit {
188 my $self = shift;
189  
190 my $limit = $self->{cgi}->param('limit');
191 if ( defined $limit ) {
192 return $limit eq '(all)' ? 0 : $limit;
193 }
194  
195 return 20;
196 }
197  
198 sub run {
199 my $self = shift;
200 my $ra = $self->{repos}{ra};
201 my $limit = $self->_get_limit();
202 my $rev = $self->{cgi}->param('rev') || $ra->get_latest_revnum();
203 my $uri = $self->{repos}{uri};
204 $uri .= '/'.$self->rpath if $self->rpath;
205  
206 my ( undef, $yng_rev, undef, $head ) = $self->get_revs();
207  
208 # Handle log paging
209 my $at_oldest;
210 if ($limit) { # $limit not 'all'
211 # Get one more log entry than asked for. If we get back this
212 # many log entries then we know there's at least one more page
213 # of results to show. If we get back $limit or less log
214 # entries then we're on the last page.
215 #
216 # If we're not on the last page then pop off the extra log entry
217 $ra->get_log( [ $self->rpath ], $rev, 1, $limit + 1, 1, 1, sub { $self->_log(@_) } );
218  
219 $at_oldest = @{ $self->{REVS} } <= $limit;
220  
221 pop @{ $self->{REVS} } unless $at_oldest;
222 }
223 else {
224  
225 # We must be displaying to the oldest rev, so no paging required
226 $ra->get_log( [ $self->rpath ], $rev, 1, $limit, 1, 1, sub { $self->_log(@_) } );
227  
228 $at_oldest = 1;
229 }
230  
231 # $self->_resolve_changed_paths();
232 my $node_kind = $self->svn_get_node_kind($uri, $rev, $rev);
233 my $is_dir = $node_kind == $SVN::Node::dir;
234  
235 return {
236 template => 'log',
237 data => {
238 context => $is_dir ? 'directory' : 'file',
239 isdir => $is_dir,
240 revs => $self->{REVS},
241 limit => $limit,
242 rev => $rev,
243 youngest_rev => $yng_rev,
244 at_oldest => $at_oldest,
245 at_head => $head,
246 }
247 };
248 }
249  
250 # Add 'isdir' keys to the paths if appropriate. Also, add trailing slashes
251 # if necessary.
252 #
253 # This code used to be in get_log() when it used the repos layer. When
254 # the code was changed to use the ra layer it had to be moved out, as you
255 # can't call ra functions from a get_log() callback.
256 #
257 # XXX Very similar code in Revision.pm, needs refactoring
258 sub _resolve_changed_paths {
259 my $self = shift;
260 my $uri = $self->{repos}{uri};
261  
262 my $subpool = SVN::Pool->new();
263  
264 foreach my $data ( @{ $self->{REVS} } ) {
265 foreach my $path ( keys %{ $data->{paths} } ) {
266 my $node_kind = $self->svn_get_node_kind("$uri$path", $data->{rev}, $data->{rev}, $subpool);
267  
268 $data->{paths}{$path}{isdir} = $node_kind == $SVN::Node::dir;
269  
270 $subpool->clear();
271 }
272 }
273 }
274  
275 1;
276  
277 =head1 COPYRIGHT
278  
279 Copyright 2003-2004 by Chia-liang Kao C<< <clkao@clkao.org> >>.
280  
281 Copyright 2005-2007 by Nik Clayton C<< <nik@FreeBSD.org> >>.
282  
283 This program is free software; you can redistribute it and/or modify it
284 under the same terms as Perl itself.
285  
286 See L<http://www.perl.com/perl/misc/Artistic.html>
287  
288 =cut
« blib/lib/SVN/Web/List.pm ↑ Summary blib/lib/SVN/Web/RSS.pm »