~allison/ubuntu/raring/libsvn-web-perl/fix-for-1106378

« back to all changes in this revision

Viewing changes to lib/SVN/Web/action.pm

  • Committer: Package Import Robot
  • Author(s): Hilko Bengen
  • Date: 2012-10-22 21:08:14 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20121022210814-5wru25mlw6dakkr8
Tags: 0.63-1
* New Upstream version
* Updated dependencies
* Switched to Debhelper 8
* Set locale for running tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package SVN::Web::action;
2
2
 
3
 
our $VERSION = 0.53;
4
 
 
5
 
use POSIX qw();
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
our $VERSION = 0.63;
 
7
 
 
8
use Encode;
 
9
use File::Temp ();
 
10
use POSIX ();
6
11
use Time::Local qw(timegm_nocheck);
7
 
use Time::Zone qw();
 
12
use Time::Zone ();
8
13
 
9
14
use SVN::Core;
10
15
 
93
98
 
94
99
=item $self->{cgi}
95
100
 
96
 
An instance of a CGI object corresponding to the current request.  This is
97
 
normally an object from either the L<CGI> or L<CGI::Fast> modules, although
98
 
it is possible to specify another class with the C<cgi_class> directive in
99
 
F<config.yaml>.
 
101
An instance of a CGI compatible object corresponding to the current request.  This is normally an object from either the L<CGI> or L<CGI::Fast> modules, although it is possible to specify another class with the C<cgi_class> directive in
 
102
F<config.yaml>. Since we now use Plack, this is a L<Plack::Request> object.
100
103
 
101
104
You can use this object to retrieve the values of any parameters passed to
102
105
your action.
234
237
=cut
235
238
 
236
239
sub recent_interesting_rev {
237
 
    my $self = shift;
238
 
    my $path = shift;
239
 
    my $rev  = shift;
240
 
 
241
 
    my $ra  = $self->{repos}{ra};
242
 
 
243
 
                $path =~ s{^/}{};
 
240
    my ($self, $path, $rev) = @_;
 
241
 
 
242
    my $ra = $self->{repos}{ra};
244
243
 
245
244
    my @log_result;
246
 
    $ra->get_log([$path], $rev, 1, 1, 0, 1,
247
 
                 sub { @log_result = @_; });
 
245
 
 
246
    $ra->get_log( [ Encode::encode('utf8',$self->rpath($path)) ], $rev, 1, 1, 0, 1, sub { @log_result = @_; } );
248
247
 
249
248
    return @log_result if wantarray();
250
 
    return $log_result[1];      # Revision number
 
249
    return $log_result[1];    # Revision number
251
250
}
252
251
 
253
252
=head2 get_revs()
286
285
 
287
286
    my $exp_rev = $self->{cgi}->param('rev');
288
287
    my $yng_rev = $self->{repos}{ra}->get_latest_revnum();
289
 
    my $act_rev = defined $exp_rev ? $self->recent_interesting_rev($path, $exp_rev) :
290
 
                                     $self->recent_interesting_rev($path, $yng_rev);
 
288
    my $act_rev =
 
289
      defined $exp_rev
 
290
      ? $self->recent_interesting_rev( $path, $exp_rev )
 
291
      : $self->recent_interesting_rev( $path, $yng_rev );
291
292
 
292
293
    my $at_head = 0;
293
 
    if(! defined $exp_rev) {
294
 
        $at_head = 1;
295
 
    } else {
296
 
        if($exp_rev == $yng_rev) {
297
 
            $at_head = 1;
298
 
        }
299
 
    }
300
 
    return($exp_rev, $yng_rev, $act_rev, $at_head);
 
294
    if ( !defined $exp_rev or $exp_rev eq '' ) {
 
295
        $at_head = 1;
 
296
    }
 
297
    else {
 
298
        if ( $exp_rev == $yng_rev ) {
 
299
            $at_head = 1;
 
300
        }
 
301
    }
 
302
    return ( $exp_rev, $yng_rev, $act_rev, $at_head );
301
303
}
302
304
 
303
305
=head2 format_svn_timestamp()
308
310
 
309
311
=cut
310
312
 
311
 
my $tz_offset = undef;          # Cache the timezone offset
 
313
my $tz_offset = undef;    # Cache the timezone offset
312
314
 
313
315
sub format_svn_timestamp {
314
316
    my $self    = shift;
316
318
 
317
319
    # Note: Buggy on Solaris
318
320
    # my $time = SVN::Core::time_from_cstring($cstring) / 1_000_000;
319
 
    my(@time) = $cstring =~ /^(....)-(..)-(..)T(..):(..):(..)/;
320
 
 
321
 
    my $time = timegm_nocheck($time[5], $time[4],     $time[3],
322
 
                              $time[2], $time[1] - 1, $time[0]);
323
 
 
324
 
    if($self->{config}->{timezone} eq 'local') {
325
 
        return POSIX::strftime($self->{config}->{timedate_format},
326
 
                               localtime($time));
327
 
    }
328
 
 
329
 
    if((not defined $tz_offset) and ($self->{config}->{timezone} ne '')) {
330
 
        $tz_offset = Time::Zone::tz_offset($self->{config}->{timezone});
331
 
        $time += $tz_offset;
332
 
    }
333
 
 
334
 
    return POSIX::strftime($self->{config}->{timedate_format}, gmtime($time));
 
321
    my (@time) = $cstring =~ /^(....)-(..)-(..)T(..):(..):(..)/;
 
322
 
 
323
    my $time =
 
324
      timegm_nocheck( $time[5], $time[4], $time[3], $time[2], $time[1] - 1,
 
325
        $time[0] );
 
326
 
 
327
    if ( $self->{config}->{timezone} eq 'local' ) {
 
328
        return POSIX::strftime( $self->{config}->{timedate_format},
 
329
            localtime($time) );
 
330
    }
 
331
 
 
332
    if ( ( not defined $tz_offset ) and ( $self->{config}->{timezone} ne '' ) )
 
333
    {
 
334
        $tz_offset = Time::Zone::tz_offset( $self->{config}->{timezone} );
 
335
        $time += $tz_offset;
 
336
    }
 
337
 
 
338
    return POSIX::strftime( $self->{config}->{timedate_format}, gmtime($time) );
335
339
}
336
340
 
337
341
=head1 CACHING
367
371
 
368
372
Copyright 2005-2007 by Nik Clayton C<< <nik@FreeBSD.org> >>.
369
373
 
 
374
Copyright 2012 by Dean Hamstead C<< <dean@fragfest.com.au> >>.
 
375
 
370
376
This program is free software; you can redistribute it and/or modify it
371
377
under the same terms as Perl itself.
372
378
 
374
380
 
375
381
=cut
376
382
 
 
383
sub rpath {
 
384
    my ( $self, $p ) = @_;
 
385
    my $path = $p || $self->{path};
 
386
    $path =~ s{^/}{} if $path;
 
387
    return $path
 
388
}
 
389
 
 
390
sub svn_get_node_kind {
 
391
    my ($self, $uri, $peg_revision, $revision, $pool) = @_;
 
392
 
 
393
    my $node_kind;
 
394
 
 
395
    my @args = ($self->encode_svn_uri($uri), $peg_revision, $revision, sub { $node_kind = $_[1]->kind() }, 0);
 
396
    push @args, $pool if $pool;
 
397
    $self->{repos}{client}->info(@args);
 
398
 
 
399
    return $node_kind;
 
400
}
 
401
 
 
402
sub svn_get_diff {
 
403
    my ($self, $target1, $rev1, $target2, $rev2, $recursive, $pool) = @_;
 
404
 
 
405
    my ( $out_h, $out_fn ) = File::Temp::tempfile();
 
406
    my ( $err_h, $err_fn ) = File::Temp::tempfile();
 
407
 
 
408
    my @args = ([], $self->encode_svn_uri($target1), $rev1, $self->encode_svn_uri($target2), $rev2, $recursive, 1, 0, $out_h, $err_h);
 
409
    push @args, $pool if $pool;
 
410
    $self->{repos}{client}->diff(@args);
 
411
 
 
412
    my $out;
 
413
    local $/ = undef;
 
414
    seek($out_h, 0, 0);
 
415
    $out = <$out_h>;
 
416
    unlink( $out_fn ); unlink( $err_fn );
 
417
    close( $out_h ); close( $err_h );
 
418
 
 
419
    return $out;
 
420
}
 
421
 
 
422
sub ctx_ls {
 
423
    my ($self, $uri) = splice(@_, 0, 2);
 
424
    return $self->{repos}{client}->ls( $self->encode_svn_uri($uri), @_ );
 
425
}
 
426
 
 
427
sub ctx_revprop_get {
 
428
    my ($self, $prop_name, $uri, $rev) = splice(@_, 0, 4);
 
429
    return $self->{repos}{client}->revprop_get( $prop_name, $self->encode_svn_uri($uri), $rev, @_ );
 
430
}
 
431
 
 
432
sub ctx_propget {
 
433
    my ($self, $prop_name, $uri, $rev, $recursive) = splice(@_, 0, 5);
 
434
    return $self->{repos}{client}->propget( $prop_name, $self->encode_svn_uri($uri), $rev, $recursive, @_ );
 
435
}
 
436
 
 
437
sub ctx_cat {
 
438
    my ($self, $fh, $uri, $rev) = splice(@_, 0, 4);
 
439
    return $self->{repos}{client}->cat( $fh, $self->encode_svn_uri($uri), $rev, @_ );
 
440
}
 
441
 
 
442
sub ctx_blame {
 
443
    my ($self, $uri, $start_rev, $end_rev, $cb) = splice(@_, 0, 5);
 
444
    return $self->{repos}{client}->blame( $self->encode_svn_uri($uri), $start_rev, $end_rev, $cb, @_ );
 
445
}
 
446
 
 
447
sub encode_svn_uri {
 
448
    my $uri = Encode::encode('utf8', $_[1]);
 
449
    # same as in svn_path_uri_encode (see subversion/libsvn_subr/path.c)
 
450
    $uri =~ s#([^\-\!\$\&\'\(\)\*\+\,\.\/\:\=\@\~\_0-9A-Za-z])#sprintf("%%%02X",ord($1))#eg;
 
451
    return $uri;
 
452
}
 
453
 
 
454
sub decode_svn_uri {
 
455
    my ($self, $uri) = @_;
 
456
    $uri =~ s#%([0-9A-Fa-f]{2})#chr(hex($1))#eg;
 
457
    return Encode::decode('utf8', $uri);
 
458
}
 
459
 
377
460
1;