Mercurial > hg > buildtools
comparison mkchangelog @ 0:d72d5d73b93a
Added Autopoop and mkchangelog.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Apr 2008 14:31:44 +0300 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d72d5d73b93a |
---|---|
1 #!/usr/bin/perl -w | |
2 use strict; | |
3 my $HG = "hg"; | |
4 | |
5 my $argc = ($#ARGV + 1); | |
6 print STDERR "mkchangelog v0.1 (C) 2008 Matti 'ccr' Hamalainen\n"; | |
7 die("Usage: mkchangelog [revision]\n". | |
8 "Assumes latest tagged revision if no revision given." | |
9 ) unless ($argc <= 1); | |
10 my $startrev = ""; | |
11 if ($argc >= 1) { $startrev = shift; } | |
12 | |
13 | |
14 ### Parse tag information | |
15 my $hgcmd = "$HG tags"; | |
16 open(PIIPPU, '-|', $hgcmd) or die("Cannot execute $hgcmd\n"); | |
17 my %tags = (); | |
18 my $gottags = 0; | |
19 while (<PIIPPU>) { | |
20 chop; | |
21 if (/^(\S+)\s+(\d+):(.+)$/) { | |
22 $tags{$2} = $1; | |
23 $gottags = 1; | |
24 } | |
25 } | |
26 close PIIPPU; | |
27 | |
28 die("No Mercurial tags data found, quitting.\n") unless ($gottags); | |
29 | |
30 ### Do shit | |
31 if ($startrev eq "") { | |
32 foreach my $i (sort { $a <=> $b } keys %tags) { | |
33 if ($tags{$i} ne "tip") { $startrev = $i; } | |
34 } | |
35 } | |
36 | |
37 my $revcmd; | |
38 my $therevs = "tip:$startrev"; | |
39 if ($startrev ne "") { | |
40 $revcmd = "-r $therevs"; | |
41 print STDERR "Getting log for revisions $therevs ...\n"; | |
42 } else { | |
43 $revcmd = ""; | |
44 $therevs = "ALL"; | |
45 print STDERR "Getting log for all revisions ...\n"; | |
46 } | |
47 | |
48 ### Parse log | |
49 $hgcmd = "$HG log -M -v -f $revcmd --template '\@\$REV:#rev#:#node|short#:#files#\$\@\n#desc#\n\@\$END\$\@\n'"; | |
50 open(PIIPPU, '-|', $hgcmd) or die("Cannot execute $hgcmd\n"); | |
51 my %log = (); | |
52 my %loghash = (); | |
53 my %revhash = (); | |
54 my %filehash = (); | |
55 my %rmref = (); | |
56 my $isdesc = 0; | |
57 my $rev = -1; | |
58 my $hash = ""; | |
59 my $text = ""; | |
60 my $gotrevs = 0; | |
61 my $files = ""; | |
62 while (<PIIPPU>) { | |
63 chop; | |
64 if (/^\@\$REV:(\d+):([0-9a-f]{12}):(.*)\$\@$/) { | |
65 $rev = $1; | |
66 $hash = $2; | |
67 $files = $3; | |
68 $text = ""; | |
69 $isdesc = 1; | |
70 $gotrevs = 1; | |
71 } elsif (/^\@\$END\$\@$/) { | |
72 die("lol\n") unless ($isdesc); | |
73 $isdesc = 0; | |
74 $filehash{$rev} = $files; | |
75 $log{$rev} = $text; | |
76 $loghash{$hash} = $rev; | |
77 $revhash{$rev} = $hash; | |
78 } elsif ($isdesc) { | |
79 $text .= $_." "; | |
80 } else { | |
81 print STDERR "? $_\n"; | |
82 } | |
83 } | |
84 close PIIPPU; | |
85 | |
86 die("No Mercurial revision data found? How odd... quitting.\n") unless ($gotrevs); | |
87 | |
88 ### | |
89 my %hide = (); | |
90 foreach my $i (sort { $a <=> $b } keys %log) { | |
91 if ($log{$i} =~ /Backed out changeset ([0-9a-f]{12})/) { | |
92 my $href = $1; | |
93 if (defined($loghash{$href})) { | |
94 $hide{$i} = 1; | |
95 $rmref{$href} = $revhash{$i}; | |
96 } | |
97 } | |
98 } | |
99 | |
100 my $s = "ChangeLog between revisions $therevs"; | |
101 print "$s\n"; | |
102 print "=" x length($s) . "\n\n"; | |
103 | |
104 foreach my $i (sort { $a <=> $b } keys %log) { | |
105 my $href = $revhash{$i}; | |
106 if (!defined($rmref{$href}) && !defined($hide{$i})) { | |
107 my @foo = split(/\s+/,$filehash{$i}); | |
108 my $n = $#foo + 1; | |
109 if ($n > 3) { $n = 3; } | |
110 | |
111 print "- $log{$i} [".($#foo + 1).": "; | |
112 for (my $k = 0; $k < $n; $k++) { | |
113 print $foo[$k]; | |
114 print " " unless ($k+1 == $n); | |
115 } | |
116 print " ..." unless ($#foo <= $n); | |
117 print "]\n"; | |
118 } | |
119 } | |
120 |