~rgrjr/rgrjr-scripts

55a7863bf5acca31a9533d942f73ecd3c1e1de22 — Bob Rogers 1 year, 11 months ago 84711da
Add "bzr log" output support to vc-chrono-log.pl

* vc-chrono-log.pl:
   + (parse_bzr):  Parse Bzr fields.
   + (parse):  Dispatch to parse_bzr if we recognize its divider.
   + (ChronoLog::Entry):  Add a branch slot.
   + (report):  Also report the entry branch.  (There are other
     bzr-specific fields we could include, but this is good for now).
1 files changed, 88 insertions(+), 2 deletions(-)

M vc-chrono-log.pl
M vc-chrono-log.pl => vc-chrono-log.pl +88 -2
@@ 112,14 112,14 @@ use base (qw(ChronoLog::Base));
# define instance accessors.
sub BEGIN {
    ChronoLog::Entry->define_instance_accessors
	(qw(revision commitid author encoded_date msg tags files));
	(qw(revision commitid branch author encoded_date msg tags files));
}

sub report {
    my $self = shift;

    # [can't seem to make these work at top level.  -- rgr, 11-Mar-06.]
    my $per_entry_fields = [ qw(revision author commitid) ];
    my $per_entry_fields = [ qw(revision branch author commitid) ];
    my $per_file_fields = [ qw(state action lines branches) ];

    my $date_format_string = '%Y-%m-%d %H:%M:%S';


@@ 300,6 300,89 @@ sub parse_svn_xml {
    $entries;
}

use constant BZR_DIVIDER
    => "------------------------------------------------------------";

sub parse_bzr {
    my ($self, $source, $first_line) = @_;
    $source ||= *STDIN;

    $self->vcs_name('Bzr');
    my $entries = [ ];
    my $entry_from_rev = $self->entry_from_revision;
    $entry_from_rev = { }, $self->entry_from_revision($entry_from_rev)
	unless $entry_from_rev;

    # Read commits.
    chomp(my $line = $first_line || <$source>);
    while ($line) {
	last 
	    if $line =~ /^Use --include-merged/;
	if ($line eq BZR_DIVIDER) {
	    chomp($line = <$source>);
	    redo;
	}

	# Must have the start of a commit.
	my ($commit_id) = $line =~ /^revno: (\d+)/;
	die "$source:$.:  Unexpected line '$line'.\n"
	    unless $commit_id;

	# Parse RFC822-style keywords.
	my %info;
	my $message = '';
	my $files;
	chomp($line = <$source>);
	while ($line =~ /^\s*([^:]+):\s*(.*)/) {
	    my ($key, $value) = ($1, $2);
	    if ($key eq 'message') {
		# Read the commit message.
		chomp($line = <$source>);
		# [we'll have to do something cleverer if we include merges,
		# which have indentation.  -- rgr, 3-May-22.]
		while ($line =~ s/^  //) {
		    $message .= "\n"
			if $message;
		    $message .= $line;
		    chomp($line = <$source>);
		}
	    }
	    elsif ($key eq 'modified') {
		# Read modified files.
		chomp($line = <$source>);
		while ($line =~ s/^  //) {
		    my $rev = RGR::CVS::FileRevision->new
			(file_name => $line);
		    push(@$files, $rev);
		    chomp($line = <$source>);
		}
	    }
	    else {
		$info{$key} = $value;
		chomp($line = <$source>);
	    }
	}
	unless ($line eq BZR_DIVIDER) {
	    # This is all we expect to see betwen revisions.
	    warn "$.:  Unexpected line: $line";
	}
	my $date = $info{timestamp};
	my $entry = ChronoLog::Entry->new
	    (revision => $commit_id,
	     msg => $message,
	     author => $info{committer} || '?',
	     encoded_date => $date && str2time($date),
	     branch => $info{'branch nick'},
	     files => $files);
	push(@$entries, $entry);
	$entry_from_rev->{$commit_id} = $entry;
    }

    # Produce the sorted set of entries.
    $self->log_entries($entries);
    return $entry_from_rev;
}

sub parse_git {
    my ($self, $source, $first_line) = @_;
    $source ||= *STDIN;


@@ 569,6 652,9 @@ sub parse {
	seek($stream, 0, 0);
	$self->parse_svn_xml($stream);
    }
    elsif ($first_line =~ /^-------/) {
	$self->parse_bzr($stream, $first_line);
    }
    elsif ($first_line =~ /^(commit )?[a-f0-9]{40}/) {
	$self->parse_git($stream, $first_line);
    }