SVN::Web::Checkout - SVN::Web action to checkout a given file


SVN-Web documentation Contained in the SVN-Web distribution.

Index


Code Index:

NAME

Top

SVN::Web::Checkout - SVN::Web action to checkout a given file

SYNOPSIS

Top

In config.yaml

  actions:
    ...
    checkout:
      class: SVN::Web::Checkout
      action_menu:
        show:
          - file
        link_text: (checkout)
    ...

DESCRIPTION

Top

Returns the contents of the given filename. Uses the svn:mime-type property.

OPTIONS

Top

rev

The repository revision to checkout. Defaults to the repository's youngest revision.

TEMPLATE VARIABLES

Top

N/A

EXCEPTIONS

Top

(path %1 is not a file in revision %2)

The given path is not a file in the given revision.

COPYRIGHT

Top


SVN-Web documentation Contained in the SVN-Web distribution.
package SVN::Web::Checkout;

use strict;
use warnings;

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

use SVN::Web::X;

our $VERSION = 0.53;

sub run {
    my $self = shift;
    my $ctx  = $self->{repos}{client};
    my $ra   = $self->{repos}{ra};
    my $uri  = $self->{repos}{uri};
    my $rev  = $self->{cgi}->param('rev') || $ra->get_latest_revnum();
    my $path = $self->{path};

    my $node_kind;
    $ctx->info("$uri$path", $rev, $rev,
	       sub { $node_kind = $_[1]->kind(); }, 0);

    if($node_kind != $SVN::Node::file) {
        SVN::Web::X->throw(
            error => '(path %1 is not a file in revision %2)',
            vars  => [$path, $rev]
        );
    }

    my($fh, $fc) = (undef, '');
    open($fh, '>', \$fc);
    $ctx->cat($fh, $uri . $path, $rev);
    close($fh);

    my $mime_type;
    my $props = $ctx->propget('svn:mime-type', $uri . $path, $rev, 0);
    if(exists $props->{$uri . $path}) {
	$mime_type = $props->{$uri . $path};
    } else {
	$mime_type = 'text/plain';
    }

    return {
        mimetype => $mime_type,
        body => $fc,
    };
}

1;