Git::FastExport::Block - A block in a fast-export stream


Git-FastExport documentation Contained in the Git-FastExport distribution.

Index


Code Index:

NAME

Top

Git::FastExport::Block - A block in a fast-export stream

SYNOSPSIS

Top

DESCRIPTION

Top

Git::FastExport::Block represents blocks from a git-fast-export stream.

Internally, it is a simple hash with keys pointing either to a string or a reference to an array of strings, which makes it very easing to edit (when obtained via Git::FastExport next_block() method) or create.

The following two keys are pointing to strings:

All the other keys are pointing to references to arrays of strings (each string representing a line in the fast-export stream:

Of course, which keys are present depend on the type of the block, which is conveniently stored in the type key.

METHODS

Top

A Git::FastExport::Block structure is meant to be used as a hash, and is not protected by an accessor/mutator interface.

However, the module provides a method for ouputing blocks:

as_string()

Return the block as a string suitable for git-fast-import.

AUTHOR

Top

Philippe Bruhat (BooK)

ACKNOWLEDGEMENTS

Top

The original version of this module was created as part of my work for BOOKING.COM, which authorized its publication/distribution under the same terms as Perl itself.

COPYRIGHT

Top

LICENSE

Top

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


Git-FastExport documentation Contained in the Git-FastExport distribution.

package Git::FastExport::Block;

use strict;
use warnings;

my $LF = "\012";

our $VERSION = '0.07';

my %fields = (
    commit     => [qw( mark author committer data from merge files )],
    tag        => [qw( from tagger data )],
    reset      => [qw( from )],
    blob       => [qw( mark data )],
    checkpoint => [],
    progress   => [],
);

'progress 1 objects';

sub as_string {
    my ($self) = @_;
    my $string = $self->{header} . $LF;

    for my $key ( @{ $fields{ $self->{type} } } ) {
        next if !exists $self->{$key};
        if ( $key eq 'data' ) {
            $string
                .= 'data ' . length( $self->{data} ) . $LF . $self->{data};
        }
        else {
            $string .= "$_$LF" for @{ $self->{$key} };
        }
    }
    return $string .= $self->{footer} || '';
}

__END__