Mercurial > hg > buildtools
diff mkchangelog @ 0:d72d5d73b93a
Added Autopoop and mkchangelog.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Apr 2008 14:31:44 +0300 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mkchangelog Tue Apr 22 14:31:44 2008 +0300 @@ -0,0 +1,120 @@ +#!/usr/bin/perl -w +use strict; +my $HG = "hg"; + +my $argc = ($#ARGV + 1); +print STDERR "mkchangelog v0.1 (C) 2008 Matti 'ccr' Hamalainen\n"; +die("Usage: mkchangelog [revision]\n". +"Assumes latest tagged revision if no revision given." +) unless ($argc <= 1); +my $startrev = ""; +if ($argc >= 1) { $startrev = shift; } + + +### Parse tag information +my $hgcmd = "$HG tags"; +open(PIIPPU, '-|', $hgcmd) or die("Cannot execute $hgcmd\n"); +my %tags = (); +my $gottags = 0; +while (<PIIPPU>) { + chop; + if (/^(\S+)\s+(\d+):(.+)$/) { + $tags{$2} = $1; + $gottags = 1; + } +} +close PIIPPU; + +die("No Mercurial tags data found, quitting.\n") unless ($gottags); + +### Do shit +if ($startrev eq "") { + foreach my $i (sort { $a <=> $b } keys %tags) { + if ($tags{$i} ne "tip") { $startrev = $i; } + } +} + +my $revcmd; +my $therevs = "tip:$startrev"; +if ($startrev ne "") { + $revcmd = "-r $therevs"; + print STDERR "Getting log for revisions $therevs ...\n"; +} else { + $revcmd = ""; + $therevs = "ALL"; + print STDERR "Getting log for all revisions ...\n"; +} + +### Parse log +$hgcmd = "$HG log -M -v -f $revcmd --template '\@\$REV:#rev#:#node|short#:#files#\$\@\n#desc#\n\@\$END\$\@\n'"; +open(PIIPPU, '-|', $hgcmd) or die("Cannot execute $hgcmd\n"); +my %log = (); +my %loghash = (); +my %revhash = (); +my %filehash = (); +my %rmref = (); +my $isdesc = 0; +my $rev = -1; +my $hash = ""; +my $text = ""; +my $gotrevs = 0; +my $files = ""; +while (<PIIPPU>) { + chop; + if (/^\@\$REV:(\d+):([0-9a-f]{12}):(.*)\$\@$/) { + $rev = $1; + $hash = $2; + $files = $3; + $text = ""; + $isdesc = 1; + $gotrevs = 1; + } elsif (/^\@\$END\$\@$/) { + die("lol\n") unless ($isdesc); + $isdesc = 0; + $filehash{$rev} = $files; + $log{$rev} = $text; + $loghash{$hash} = $rev; + $revhash{$rev} = $hash; + } elsif ($isdesc) { + $text .= $_." "; + } else { + print STDERR "? $_\n"; + } +} +close PIIPPU; + +die("No Mercurial revision data found? How odd... quitting.\n") unless ($gotrevs); + +### +my %hide = (); +foreach my $i (sort { $a <=> $b } keys %log) { + if ($log{$i} =~ /Backed out changeset ([0-9a-f]{12})/) { + my $href = $1; + if (defined($loghash{$href})) { + $hide{$i} = 1; + $rmref{$href} = $revhash{$i}; + } + } +} + +my $s = "ChangeLog between revisions $therevs"; +print "$s\n"; +print "=" x length($s) . "\n\n"; + +foreach my $i (sort { $a <=> $b } keys %log) { + my $href = $revhash{$i}; + if (!defined($rmref{$href}) && !defined($hide{$i})) { + my @foo = split(/\s+/,$filehash{$i}); + my $n = $#foo + 1; + if ($n > 3) { $n = 3; } + + print "- $log{$i} [".($#foo + 1).": "; + for (my $k = 0; $k < $n; $k++) { + print $foo[$k]; + print " " unless ($k+1 == $n); + } + print " ..." unless ($#foo <= $n); + print "]\n"; + } +} +