SVN::Dump::Record - A SVN dump record


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

Index


Code Index:

NAME

Top

SVN::Dump::Record - A SVN dump record

SYNOPSIS

Top

    # SVN::Dump::Record objects are returned by the next_record()
    # method of SVN::Dump

DESCRIPTION

Top

An SVN::Dump::Record object represents a Subversion dump record.

METHODS

Top

SVN::Dump provides the following gourps of methods:

Record methods

new()

Create a new empty SVN::Dump::Record object.

type()

Return the record type, as guessed from its headers.

The method dies if the record type cannot be determined.

set_header( $h, $v )

Set the header $h to the value $v.

get_header( $h )

Get the value of header $h.

set_property( $p, $v )

Set the property $p to the value $v.

get_property( $p )

Get the value of property $p.

delete_property( @k )

Delete the

set_text( $t )

Set the value of the text block.

get_text()

Get the value of the text block.

Inner blocks manipulation

A SVN::Dump::Record is composed of several inner blocks of various kinds: SVN::Dump::Headers, SVN::Dump::Property and SVN::Dump::Text.

The following methods provide access to these blocks:

set_headers_block( $headers )
get_headers_block()

Get or set the SVN::Dump::Headers object that represents the record headers.

set_property_block( $property )
get_property_block()

Get or set the SVN::Dump::Property object that represents the record property block.

delete_property( @keys )

Delete the given properties. Behave like the builtin delete().

set_text_block( $text )
get_text_block()

Get or set the SVN::Dump::Text object that represents the record text block.

set_included_record( $record )
get_included_record()

Some special record are actually output recursiveley by svnadmin dump. The "record in the record" is stored within the parent record, so they are parsed as a single record with an included record.

get_record() / set_record() give access to the included record.

According to the Subversion sources (subversion/libsvn_repos/dump.c), this is a "delete original, then add-with-history" node. The dump looks like this:

    Node-path: tags/mytag/myfile
    Node-kind: file
    Node-action: delete

    Node-path: tags/mytag/myfile
    Node-kind: file
    Node-action: add
    Node-copyfrom-rev: 23
    Node-copyfrom-path: trunk/myfile

    


    


    





Note that there is a single blank line after the first header block, and four after the included one.

update_headers()

Update the various ...-length headers. Used internally.

You must call this method if you update the inner property or text blocks directly, or the results of as_string() will be inconsistent.

Information methods

has_prop()

Return a boolean value indicating if the record has a property block.

has_text()

Return a boolean value indicating if the record has a text block.

has_prop_only()

Return a boolean value indicating if the record has only a property block (and no text block).

has_prop_or_text()

Return a boolean value indicating if the record has a property block or a text block.

property_length()

Return the length of the property block.

text_length()

Return the length of the text block.

Output method

as_string()

Return a string representation of the record.

Warning: dumping a record currenly gives back the information that was read from the original dump. Which means that if you modified the property or text block of a record, the headers will be inconstent.

ENCAPSULATION

Top

When using SVN::Dump to manipulate a SVN dump, one should not directly access the SVN::Dump::Headers, SVN::Dump::Property and SVN::Dump::Text components of a SVN::Dump::Record object, but use the appropriate set_...() and get_...() methods of the record object.

These methods compute the appropriate modifications of the header values, so that the as_string() method outputs the correct information after any modification of the record.

SEE ALSO

Top

SVN::Dump::Headers, SVN::Dump::Property, SVN::Dump::Text.

COPYRIGHT

Top

LICENSE

Top

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


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

package SVN::Dump::Record;

use strict;
use warnings;

use SVN::Dump::Headers;
use SVN::Dump::Property;
use SVN::Dump::Text;

my $NL = "\012";

sub new {
    my ($class, @args) = @_;
    return bless {}, $class
}

for my $attr (qw( headers_block property_block text_block included_record )) {
    no strict 'refs';
    *{"set_$attr"} = sub { $_[0]->{$attr} = $_[1]; };
    *{"get_$attr"} = sub { $_[0]->{$attr} };
}

sub type {
    my ($self) = @_;
    return $self->{headers_block} ? $self->{headers_block}->type() : '';
}

sub has_text { return defined $_[0]->get_text_block(); }
sub has_prop { return defined $_[0]->get_property_block(); }
sub has_prop_only {
    return defined $_[0]->get_property_block()
       && !defined $_[0]->get_text_block();
}
sub has_prop_or_text {
    return defined $_[0]->get_property_block()
        || defined $_[0]->get_text_block();
}

# length methods
sub property_length {
    my ($self) = @_;
    my $prop = $self->get_property_block();
    return defined $prop ? length( $prop->as_string() ) : 0;
}

sub text_length {
    my ($self) = @_;
    my $text = $self->get_text();
    return defined $text ? length($text) : 0;
}

sub as_string {
    my ($self) = @_;
    my $headers_block = $self->get_headers_block();

    # the headers block
    my $string = $headers_block->as_string();

    # the properties
    $string .= $self->get_property_block()->as_string()
        if $self->has_prop();

    # the text
    $string .= $self->get_text_block()->as_string()
        if $self->has_text();

    # is there an included record?
    if( my $included = $self->get_included_record() ) {
        $string .= $included->as_string() . $NL;
    }

    # add a record separator if needed
    my $type = $self->type();
    return $string if $type =~ /\A(?:format|uuid)\z/;

    $string .= $type eq 'revision'  ? $NL
        : $self->has_prop_or_text() ? $NL x 2
        :                             $NL ;

    return $string;
}

sub update_headers {
    my ($self)  = @_;
    my $proplen = $self->property_length();
    my $textlen = $self->text_length();

    $self->set_header( 'Text-content-length' => $textlen )
        if defined $self->get_text_block();
    $self->set_header( 'Prop-content-length', $proplen )
        if $proplen;
    $self->set_header( 'Content-length' => $proplen + $textlen );
}

# access methods to the inner blocks
sub set_header {
    my ($self, $h, $v) = @_;
    my $headers = $self->get_headers_block()
      || $self->set_headers_block( SVN::Dump::Headers->new() );
    $headers->set( $h, $v );
}

sub get_header {
    my ($self, $h) = @_;
    return $self->get_headers_block()->get($h);
}

sub set_property {
    my ( $self, $k, $v ) = @_;
    my $prop = $self->get_property_block()
      || $self->set_property_block( SVN::Dump::Property->new() );
    $prop->set( $k, $v );
    $self->update_headers();
    return $v;
}

sub get_property {
    my ($self, $k) = @_;
    return $self->get_property_block()->get($k);
}

sub delete_property {
    my ( $self, @keys ) = @_;
    my $prop = $self->get_property_block()
        || $self->set_property_block( SVN::Dump::Property->new() );
    my @result = $prop->delete(@keys);
    $self->update_headers();
    return wantarray ? @result : pop @result; # behave like delete()
}

sub set_text {
    my ($self, $t) = @_;
    my $text_block = $self->get_text_block()
      || $self->set_text_block( SVN::Dump::Text->new() );

    $text_block->set( $t );
    $self->update_headers();
    return $t;
}

sub get_text {
    my ($self) = @_;
    my $text_block = $self->get_text_block();
    return defined $text_block ? $text_block->get() : undef;
}

1;

__END__