1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
|
#!/usr/bin/perl
# Generate a ChangeLog file from a CVS log.
# Written by Robert Krawitz <rlk@alum.mit.edu>
# This code is in the public domain and may be used
# for any purpose.
use Getopt::Long;
Getopt::Long::Configure("bundling", "no_ignore_case", "pass_through");
use strict;
# Configuration options.
my $emailsuffix;
my $symbolic_name_regexp;
my (@ignoreprefix);
my $reverse = 0;
my $use_rcs_filename = 0;
my $print_each_file = 0;
my $print_time = 0;
GetOptions("e:s" => \$emailsuffix,
"X=s" => \@ignoreprefix,
"r!" => \$reverse,
"R!" => \$use_rcs_filename,
"v!" => \$print_each_file,
"t!" => \$print_time,
"s:s" => \$symbolic_name_regexp);
my %logmsgs = (); # Index by date, time, and author
my %fileversions = ();
my $skipme = 0;
my %basenames = ();
my %plus = ();
my %minus = ();
my @cvsdirs=`find . -type d -name CVS -print`;
@cvsdirs = map { chomp; s,^\./,, } @cvsdirs;
foreach my $d (@cvsdirs) {
if (open ENTRIES, "$d/Entries") {
my ($rootdir) = $d;
$rootdir =~ s/CVS$//;
while (<ENTRIES>) {
my ($type, $file, $version, @junk) = split /\//;
if ($type eq "") {
$basenames{"$file"} = "1";
$file = "$rootdir$file";
$fileversions{$file} = $version;
}
}
close ENTRIES;
}
}
sub compare_versions($$)
{
# vw: version of the working file
# vl: version from the log
# The idea is that we want versions on the current branch, on branches
# leading to the current branch, and on the root prior to the current
# branch.
#
# Example: the current file is 1.5.12.2.4.3
#
# We want versions:
# 1.1
# 1.2
# 1.3
# 1.4
# 1.5
# 1.5.12.1
# 1.5.12.2
# 1.5.12.2.4.1
# 1.5.12.2.4.2
# 1.5.12.2.4.3
#
# We look at the numbers in pairs. The first number in each pair is
# the branch number; the second number is the version on the branch.
# The pairs are of the form (B, V).
#
# If the number of components in the log version is greater than the
# number of components in the working version, we aren't interested.
# This file cannot be a predecessor of the working version; it is
# either a branch off the working version, or it is an entirely different
# branch.
#
# We next iterate over all pairs in the log version. The following must
# be true for all pairs:
#
# Bw = Bl
# Vw >= Vl
#
# Note that there's no problem if the number of components in the
# working version exceeds the number of components in the log version.
#
# There is a special case: If the working version doesn't exist at all,
# we return true if the log version is on the mainline. This lets us
# see log messages from files that have been deleted.
#
# Return value:
#
# 4 if there is no working version and the log version is at top level
#
# 2 if there is no working version and the log version is not at top
# level
#
# 3 if the number of components in the log version exceeds the number
# of components in the working version
#
# 0 if the log version is later than or on a different branch from
# the working version
#
# 1 otherwise (if the log version is a predecessor of the working version)
my ($vw, $vl) = @_;
my (@vvl) = split(/\./, $vl);
if ($vw eq "") {
if ($#vvl < 2) {
return 2;
} else {
return 4;
}
}
my (@vvw) = split(/\./, $vw);
if ($#vvl > $#vvw) {
return 3;
}
my ($i);
for ($i = 0; $i < $#vvl; $i += 2) {
my ($bl) = $vvl[$i];
my ($vl) = $vvl[$i + 1];
my ($bw) = $vvw[$i];
my ($vw) = $vvw[$i + 1];
if ($bw != $bl || $vw < $vl) {
return 0;
}
}
return 1;
}
my ($in_header) = 0;
my ($has_rcs_file) = 0;
my (%symbols);
my $revision;
my $ignore;
my ($skipfile);
my $currentfile;
my $currentbasefile;
my %symbols_printed = ();
while (<>) {
if (/^RCS file: /) {
next if (! $use_rcs_filename);
$in_header = 1;
$has_rcs_file = 1;
chomp;
$currentfile = $_;
$currentfile =~ s,/RCS/,/,;
$currentfile =~ s,^RCS file: *\./,,;
$currentfile =~ s/,v$//;
$currentfile =~ s/\s/\000/g;
if (grep { $currentfile =~ /^$_/ } @ignoreprefix) {
$skipfile = 1;
} else {
$skipfile = 0;
}
$symbols{$currentfile} = {};
next;
} elsif (/^Working file: /) {
if ($has_rcs_file) {
$has_rcs_file = 0;
next;
}
$in_header = 1;
chomp;
($ignore, $ignore, $currentfile) = split(/\s+/, $_, 3);
$currentfile =~ s/\s/\000/g;
if (grep { $currentfile =~ /^$_/ } @ignoreprefix) {
$skipfile = 1;
} else {
$skipfile = 0;
}
$symbols{$currentfile} = {};
next;
} elsif ($in_header && $_ =~ /^symbolic names:/) {
while (<>) {
if (/^\s/) {
my ($name, $revision) = split;
$name =~ s/:$//;
next if (! ($name =~ /$symbolic_name_regexp/));
if (! defined $symbols{$currentfile}{$revision}) {
$symbols{$currentfile}{$revision} = ();
}
push @{$symbols{$currentfile}{$revision}}, $name;
} else {
last;
}
}
} elsif ($_ =~ /^----------------------------$/) {
$in_header = 0;
next;
} elsif (! $in_header && $_ =~ /^revision /) {
($ignore, $revision) = split;
($currentbasefile) = $currentfile;
$currentbasefile =~ s;.*/([^/]+);\1;;
my ($check) = compare_versions($fileversions{$currentfile}, $revision);
#
# Special case -- if a file is not in the current sandbox, but it
# has the same base name as a file in the sandbox, log it;
# otherwise if it is not in the current sandbox, don't log it.
#
if (($check == 2 && (1 || (
($basenames{$currentbasefile} || !($currentfile =~ /\//)) &&
($currentfile =~ /\.[chly]$/)))) ||
$check == 1) {
$skipme = 0;
} else {
# We don't want to print out any symbolic names associated with
# skipped versions.
map {
$symbols_printed{$_} = 1;
} @{$symbols{$currentfile}{$revision}};
$skipme = 1;
}
} elsif (! $in_header && $_ =~ /^date: /) {
my (@stuff) = split;
my ($date, $time, $author, $state, $plus, $minus);
if ($stuff[3] =~ /^[-+][0-9][0-9][0-9][0-9]/) {
$date = $stuff[1];
$time = $stuff[2];
$author = $stuff[5];
$state = $stuff[7];
$plus = $stuff[9];
$minus = $stuff[10];
} else {
$date = $stuff[1];
$time = $stuff[2];
$author = $stuff[4];
$state = $stuff[6];
$plus = $stuff[8];
$minus = $stuff[9];
}
# $time =~ s/[0-9]:[0-9][0-9];$//;
# $time =~ s/[0-9][0-9];$//;
$time =~ s/;$//;
$author =~ s/;$//;
$plus =~ s/;$//;
$minus =~ s/;$//;
my $body = "";
my $firstline = 1;
while (<>) {
if ($_ =~ /^----------------------------$/) {
last;
} elsif ($_ =~ /^=============================================================================$/) {
last;
} elsif ($firstline && $_ =~ /^branches:([ \t]+[0-9]+(\.[0-9]+)+;)+$/) {
next;
} else {
$body .= $_;
$firstline = 0;
}
}
my $junkbody = $body;
$junkbody =~ s/\s//g;
$junkbody .= "x";
my $symbols;
if (defined $symbols{$currentfile}{$revision}) {
$symbols = join " ", @{$symbols{$currentfile}{$revision}};
}
my $datetimeauthor = "$date $time $author $junkbody $currentfile $revision $symbols";
if ($skipfile == 0 && $skipme == 0) {
$logmsgs{$datetimeauthor} = $body;
if ($plus eq "") {
$plus{$datetimeauthor} = "added";
} elsif ($state eq "dead;") {
$plus{$datetimeauthor} = "removed";
} else {
$plus{$datetimeauthor} = $plus;
$minus{$datetimeauthor} = $minus;
}
}
} # Other junk we ignore
}
my $prevmsg="";
my $prevdate="";
my $prevtime="";
my $prevauthor="";
my $header="";
my %deltainfo = ();
my %revinfo = ();
my @chlog = $reverse ? sort keys %logmsgs : reverse sort keys %logmsgs;
my %filenames_printed = ();
my ($date, $time, $author, $junk, $file, $revision, @symbols);
my $filestuff;
sub printmsg($$$$$\%\%)
{
my ($date, $time, $author, $emailsuffix, $prevmsg, $revinfo, $deltainfo) = @_;
if ($print_time) {
$time = " $time";
} else {
$time = "";
}
print "$date$time\t<$author$emailsuffix>\n\n";
my $filestuff = join "", (map { "\t\t$_ ($$revinfo{$_}) ($$deltainfo{$_})\n" } sort keys %revinfo);
$filestuff =~ s/\000/ /g;
$filestuff =~ s/\t/\tFiles:/;
print "$filestuff\n";
$prevmsg =~ s/^/\t/g;
$prevmsg =~ s/\n/\n\t/g;
$prevmsg =~ s/[ \t]+\n/\n/g;
$prevmsg =~ s/[ \t]+$//g;
print "$prevmsg\n";
}
sub printsyms(@) {
my (@symbols_to_print) = @_;
print "===============================================================================\n";
map {
print "Name: $_\n";
} @symbols_to_print;
print "\n";
}
foreach (@chlog) {
($date, $time, $author, $junk, $file, $revision, @symbols) = split;
$date =~ s,/,-,g;
my $msg = $logmsgs{$_};
my $delta;
if (! $minus{$_}) {
$delta = "$plus{$_}";
} else {
$delta = "$plus{$_} $minus{$_}";
}
if (! $print_each_file && $prevmsg eq $msg && !$filenames_printed{$file}) {
$deltainfo{$file} = $delta;
$revinfo{$file} = $revision;
} else {
if ($prevmsg ne "" || keys %deltainfo > 0) {
printmsg($prevdate, $prevtime, $prevauthor, $emailsuffix, $prevmsg, %revinfo, %deltainfo);
%filenames_printed = ();
}
$header = "$date\t<$author$emailsuffix>\n\n";
$prevmsg = $msg;
$prevdate = $date;
$prevauthor = $author;
$prevtime = $time;
%deltainfo = ();
%revinfo = ();
$deltainfo{$file} = $delta;
$revinfo{$file} = $revision;
$filenames_printed{$file} = 1;
}
my (@symbols_to_print);
foreach my $s (@symbols) {
if (! $symbols_printed{$s}) {
push @symbols_to_print, $s;
$symbols_printed{$s} = 1;
}
}
if (@symbols_to_print) {
printsyms(@symbols_to_print);
}
}
if ($prevmsg ne "" || keys %deltainfo > 0) {
printmsg($prevdate, $prevtime, $prevauthor, $emailsuffix, $prevmsg, %revinfo, %deltainfo);
}
|