This file is indexed.

/usr/share/perl5/SVN/Web/Diff.pm is in libsvn-web-perl 0.63-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# -*- Mode: cperl; cperl-indent-level: 4 -*-

package SVN::Web::Diff;

use strict;
use warnings;

use base 'SVN::Web::action';

use Encode ();
use SVN::Core;
use SVN::Ra;
use SVN::Client;
use SVN::Web::DiffParser;
use SVN::Web::X;
use List::Util qw(max min);

our $VERSION = 0.62;

=head1 NAME

SVN::Web::Diff - SVN::Web action to show differences between file revisions

=head1 SYNOPSIS

In F<config.yaml>

  actions:
    ...
    diff:
      class: SVN::Web::Diff
    ...

=head1 DESCRIPTION

Returns the difference between two revisions of the same file.

=head1 CONFIGURATION

The following configuration options may be specified in F<config.yaml>.

=over

=item max_diff_size

If showing the diff (see C<show_diff>), this determines the maximum size
of the diff that will be shown.  If the size of the generated diff (in
bytes) is larger than this figure then it is not shown.

Defaults to 200,000 bytes.

=back

=head1 OPTIONS

=over 8

=item rev1

The first revision of the file to compare.

=item rev2

The second revision of the file to compare.

=item revs

A list of two or more revisions.  If present, the smallest number in
the list is assigned to C<rev1> (overriding any given C<rev1> value) and the
largest number in the list is assigned to C<rev2> (overriding any given
C<rev2> value).

In other words:

    ...?rev1=5;rev2=10

is equal to:

    ...?revs=10;revs=5

This supports the "diff between arbitrary revisions" functionality.

=item mime

The desired output format.  The default is C<html> for a diff marked
up in HTML.  The other allowed value is C<text>, for a plain text
unified diff.

=back

=head1 TEMPLATE VARIABLES

=over 8

=item at_head

Boolean, indicating whether or not we're currently diffing against the
youngest revision of this file.

=item context

Always C<file>.

=item rev1

The first revision of the file to compare.  Corresponds with the C<rev1>
parameter, either set explicitly, or extracted from C<revs>.

=item rev2

The second revision of the file to compare.  Corresponds with the C<rev2>
parameter, either set explicitly, or extracted from C<revs>.

=item diff

An L<SVN::Web::DiffParser> object that contains the text of the diff.
Call the object's methods to format the diff.

=item diff_size

The size of the generated diff (before parsing).

=item max_diff_size

The configured maximum diff size.

=back

=head1 EXCEPTIONS

=over 4

=item (cannot diff nodes of different types: %1 %2 %3)

The given path has different node types at the different revisions.
This probably means a file was added, deleted, and then re-added as a
directory at a later date (or vice-versa).

=item (path %1 is a directory at rev %2)

The user has tried to diff two directories.  This is not currently
supported.

=item (path %1 does not exist in revision %2)

The given path is not present in the repository at the given revision.

=item (two revisions must be provided)

No revisions were given to diff against.

=item (rev1 and rev2 must be different)

Either only one revision number was given, or several were given, but
they're the same number.

=back

=cut

my %default_opts = ( max_diff_size => 200_000, );

sub cache_key {
    my $self = shift;

    my ( $rev1, $rev2 ) = $self->_check_params();
    my $path = $self->{path};
    my $mime = $self->{cgi}->param('mime') || 'text/html';

    return "$rev1:$rev2:$mime:$path";
}

sub run {
    my $self = shift;

    $self->{opts} = { %default_opts, %{ $self->{opts} } };

    my ( $rev1, $rev2 ) = $self->_check_params();

    my $ctx  = $self->{repos}{client};
    my $ra   = $self->{repos}{ra};
    my $uri  = $self->{repos}{uri};
    $uri .= '/'.$self->rpath if $self->rpath;

    my ( undef, undef, undef, $at_head ) = $self->get_revs();

    my $mime = $self->{cgi}->param('mime') || 'text/html';

    my %types = (
        $rev1 => $ra->check_path( $self->rpath, $rev1 ),
        $rev2 => $ra->check_path( $self->rpath, $rev2 )
    );

    SVN::Web::X->throw(
        error => '(cannot diff nodes of different types: %1 %2 %3)',
        vars  => [ $self->rpath, $rev1, $rev2 ]
    ) if $types{$rev1} != $types{$rev2};

    foreach my $rev ( $rev1, $rev2 ) {
        SVN::Web::X->throw(
            error => '(path %1 does not exist in revision %2)',
            vars  => [ $self->rpath, $rev ]
        ) if $types{$rev} == $SVN::Node::none;

        SVN::Web::X->throw(
            error => '(path %1 is a directory at rev %2)',
            vars  => [ $self->rpath, $rev ]
        ) if $types{$rev} == $SVN::Node::dir;
    }

    my $style;
    $mime eq 'text/html'  and $style = 'Text::Diff::HTML';
    $mime eq 'text/plain' and $style = 'Unified';

    if ( $mime eq 'text/html' ) {
        my $out = Encode::decode('utf8',$self->svn_get_diff($uri, $rev1, $uri, $rev2, 0));
        my $diff;
        my $diff_size = length($out);
        my $max_diff_size = $self->{opts}{max_diff_size} || 0;
        if ( $diff_size <= $max_diff_size ) {
            $diff = SVN::Web::DiffParser->new($out);
        }

        return {
            template => 'diff',
            data     => {
                context       => 'file',
                rev1          => $rev1,
                rev2          => $rev2,
                diff          => $diff,
                diff_size     => $diff_size,
                max_diff_size => $max_diff_size,
                at_head       => $at_head,
            }
        };
    }
    else {
        return {
            mimetype => $mime,
            body     => $self->svn_get_diff($uri, $rev1, $uri, $rev2, 0),
        };
    }
}

sub _check_params {
    my $self = shift;

    my $rev1 = $self->{cgi}->param('rev1');
    my $rev2 = $self->{cgi}->param('rev2');
    my @revs = $self->{cgi}->param('revs');

    if (@revs) {
        $rev1 = min(@revs);
        $rev2 = max(@revs);
    }

    SVN::Web::X->throw(
        error => '(two revisions must be provided)',
        vars  => []
      )
      unless defined $rev1
          and defined $rev2;

    SVN::Web::X->throw(
        error => '(rev1 and rev2 must be different)',
        vars  => []
    ) if @revs and @revs < 2;

    SVN::Web::X->throw(
        error => '(rev1 and rev2 must be different)',
        vars  => []
    ) if $rev1 == $rev2;

    return ( $rev1, $rev2 );
}

# Make sure that a path exists in a revision
sub _check_path {
    my $self = shift;
    my $path = shift;
    my $rev  = shift;

    my $ra = $self->{repos}{ra};

    if ( $ra->check_path( $self->rpath($path), $rev ) == $SVN::Node::none ) {
        SVN::Web::X->throw(
            error => '(path %1 does not exist in revision %2)',
            vars  => [ $path, $rev ],
        );
    }
}

1;

=head1 COPYRIGHT

Copyright 2003-2004 by Chia-liang Kao C<< <clkao@clkao.org> >>.

Copyright 2005-2007 by Nik Clayton C<< <nik@FreeBSD.org> >>.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

See L<http://www.perl.com/perl/misc/Artistic.html>

=cut