# # # patch "ChangeLog" # from [94848ae5f3945356280d5279c64650cc9c8bc253] # to [79900a0a7bee9d815c77f6561187cc15947b555a] # ============================================================ --- ChangeLog 94848ae5f3945356280d5279c64650cc9c8bc253 +++ ChangeLog 79900a0a7bee9d815c77f6561187cc15947b555a @@ -1,87 +1,89 @@ -#!/bin/sh -# Usage: ChangeLog [] [-d database] [-r revision] -# Construct and print a ChangeLog for the last revisions from their -# date, author, and changelog certs. +#!/usr/bin/perl -# If is not given, it defaults to 15 +use strict; -# If this script is not run from the root of a monotone workspace, both -# the -d and -r options are required. +my $num=15; +my $db; +my $rev; -NUM=15 -MTN=mtn +while (@ARGV) { + my $arg = $ARGV[0]; + if ($arg eq "-d") { + shift @ARGV; + $db = shift(@ARGV); + } elsif ($arg eq "-r") { + shift @ARGV; + $rev = shift(@ARGV); + } else { + $num = shift(@ARGV); + } +} -while ! [ $# -eq 0 ] ; do - case "$1" in - -r) shift; REV="$1";; - -d) shift; DB="-d $1";; - *) NUM=$(($1 - 1));; - esac - shift -done +if (not defined($rev)) { + $rev=`mtn automate get_base_revision_id 2>/dev/null`; + chomp $rev; + $rev=undef if $rev eq ""; +} -if [ "x$REV" = "x" ]; then - REV=`mtn automate get_base_revision_id 2>/dev/null` -fi +my $mtn="mtn"; +if (defined($db)) { + $mtn = $mtn . " -d $db"; +} +if (not defined($rev) or not defined($db)) { + `mtn status >/dev/null 2>&1`; + die "Both -d and -r must be given if not run inside a workspace." if $?; +} +my $revlister = "$mtn automate ancestors $rev | $mtn automate toposort -@ - | tail -n $num"; +open(my $revs, "-|", $revlister) or die "Cannot get rev list"; +my @revisions; +while(<$revs>) { + unshift(@revisions, $_); +} +close($revs); -if [ "x$REV" = "x" ] || [ "x$DB" = "x" ]; then - if ! mtn status >/dev/null 2>/dev/null; then - echo "Both the -d and -r arguments are needed when this" >&2; - echo "script is not run from inside a monotone workspace." >&2; - exit 1; - fi -fi +my @certs; +foreach (@revisions) { + open(my $certs, "$mtn ls certs $_ |") or die "Cannot get certs of $_"; -# Get the contents of a cert -LOG='/^Name.*changelog$/,/^----/! D; /^Name/ D; /^----/ D' -DATE='/^Name.*date$/,/^----/! D; /^Name/ D; /^----/ D' -AUTHOR='/^Name.*author$/,/^----/! D; /^Name/ D; /^----/ D' - -# Remove "duplicate" lines (When the date+author line is unneeded because -# the same info is in the changelog cert (won't match exactly, but should -# both start with ^${year} )) -# Keep the line from the changelog, instead of the generated one -RD=':b; N; /^[[:digit:]]\{4\}.*\n[[:digit:]]\{4\}/ { s/^.*\n//; b b; }; P; D' - -get() -{ - $MTN $DB ls certs "$2" | sed "$1" \ - | sed 's/^[^\:]\+\: //g' + my %certs; + my $certname; + my $in_value = 0; + my $certval = ""; + while(<$certs>) { + if (/^Name *:/) { + s/^Name *: //; + chomp; + $certname = $_; + } elsif (/^Value *:/) { + $in_value = 1; + s/^Value *: //; + $certval = $_; + } elsif (/^-{4}/) { + $in_value = 0; + $certs{$certname} = $certval; + } elsif ($in_value and / *: /) { + s/^ *: //; + $certval .= $_; + } + } + if ($in_value) { + $certs{$certname} = $certval; + } + close($certs); + push(@certs, \%certs); } -tac_() -{ - # apparently freebsd doesn't come with tac, but it - # does have a -r flag for tail that does the same thing. - # but of course the tail that Debian (and presumably other - # linuxes) has doesn't support the -r flag - if which tac >/dev/null 2>&1 - then - tac - else - tail -r - fi -} +for my $revcerts (@certs) { + my $header = $revcerts->{"date"} . " " . $revcerts->{"author"}; + $header =~ s/[\r\n]//g; + my $text = $revcerts->{"changelog"}; -getrevs() -{ - $MTN $DB automate ancestors "$1" \ - | $MTN $DB automate toposort address@hidden \ - | tail -n "$2" | tac_ -} + if ($text =~ /^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}/) { + ($header, $text) = split(/\n/, $text, 2); + } -getlogs() -{ - for i in "$REV" `getrevs "$REV" "$NUM"`; do - echo `get "$DATE" "$i"` '' `get "$AUTHOR" "$i"` - get "$LOG" "$i" | sed '/^\(\t\|[[:digit:]]\{4\}\)/ ! s/^/\t/g' - done -} + print($header, "\n\n"); - -if [ ! x$REV = x ]; then - getlogs | sed "$RD" | sed '/^$/ d' \ - | sed 's/^\([[:digit:]]\{4\}.*\)$/\n\1\n/g' -else - echo "_MTN/revision does not exist!" >&2 -fi + $text =~ s/^/\t/gm; + print($text, "\n"); +}