-
Notifications
You must be signed in to change notification settings - Fork 3
/
cvs2cl.pl
1745 lines (1482 loc) · 53.8 KB
/
cvs2cl.pl
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
exec perl -w -x $0 ${1+"$@"} # -*- mode: perl; perl-indent-level: 2; -*-
#!perl -w
##############################################################
### ###
### cvs2cl.pl: produce ChangeLog(s) from `cvs log` output. ###
### ###
##############################################################
## $Revision: 1.2 $
## $Date: 2002/08/11 10:58:42 $
## $Author: t1mpy $
##
## (C) 1999 Karl Fogel <[email protected]>, under the GNU GPL.
##
## (Extensively hacked on by Melissa O'Neill <[email protected]>.)
##
## cvs2cl.pl is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## cvs2cl.pl is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You may have received a copy of the GNU General Public License
## along with cvs2cl.pl; see the file COPYING. If not, write to the
## Free Software Foundation, Inc., 59 Temple Place - Suite 330,
## Boston, MA 02111-1307, USA.
use strict;
use Text::Wrap;
use Time::Local;
use File::Basename;
# The Plan:
#
# Read in the logs for multiple files, spit out a nice ChangeLog that
# mirrors the information entered during `cvs commit'.
#
# The problem presents some challenges. In an ideal world, we could
# detect files with the same author, log message, and checkin time --
# each <filelist, author, time, logmessage> would be a changelog entry.
# We'd sort them; and spit them out. Unfortunately, CVS is *not atomic*
# so checkins can span a range of times. Also, the directory structure
# could be hierarchical.
#
# Another question is whether we really want to have the ChangeLog
# exactly reflect commits. An author could issue two related commits,
# with different log entries, reflecting a single logical change to the
# source. GNU style ChangeLogs group these under a single author/date.
# We try to do the same.
#
# So, we parse the output of `cvs log', storing log messages in a
# multilevel hash that stores the mapping:
# directory => author => time => message => filelist
# As we go, we notice "nearby" commit times and store them together
# (i.e., under the same timestamp), so they appear in the same log
# entry.
#
# When we've read all the logs, we twist this mapping into
# a time => author => message => filelist mapping for each directory.
#
# If we're not using the `--distributed' flag, the directory is always
# considered to be `./', even as descend into subdirectories.
############### Globals ################
# What we run to generate it:
my $Log_Source_Command = "cvs -z3 log";
# In case we have to print it out:
my $VERSION = '$Revision: 1.2 $';
$VERSION =~ s/\S+\s+(\S+)\s+\S+/$1/;
## Vars set by options:
# Print debugging messages?
my $Debug = 0;
# Just show version and exit?
my $Print_Version = 0;
# Just print usage message and exit?
my $Print_Usage = 0;
# Single top-level ChangeLog, or one per subdirectory?
my $Distributed = 0;
# What file should we generate (defaults to "ChangeLog")?
my $Log_File_Name = "ChangeLog";
# Expand usernames to email addresses based on a map file?
my $User_Map_File = "";
# Output to a file or to stdout?
my $Output_To_Stdout = 0;
# Eliminate empty log messages?
my $Prune_Empty_Msgs = 0;
# Don't call Text::Wrap on the body of the message
my $No_Wrap = 0;
# Separates header from log message. Code assumes it is either " " or
# "\n\n", so if there's ever an option to set it to something else,
# make sure to go through all conditionals that use this var.
my $After_Header = " ";
# Format more for programs than for humans.
my $XML_Output = 0;
# Do some special tweaks for log data that was written in FSF
# ChangeLog style.
my $FSF_Style = 0;
# Show times in UTC instead of local time
my $UTC_Times = 0;
# Show day of week in output?
my $Show_Day_Of_Week = 0;
# Show revision numbers in output?
my $Show_Revisions = 0;
# Show tags (symbolic names) in output?
my $Show_Tags = 0;
# Show branches by symbolic name in output?
my $Show_Branches = 0;
# Show only revisions on these branches or their ancestors.
my @Follow_Branches;
# Don't bother with files matching this regexp.
my @Ignore_Files;
# How exactly we match entries. We definitely want "o",
# and user might add "i" by using --case-insensitive option.
my $Case_Insensitive = 0;
# Maybe only show log messages matching a certain regular expression.
my $Regexp_Gate = "";
# Pass this global option string along to cvs, to the left of `log':
my $Global_Opts = "";
# Pass this option string along to the cvs log subcommand:
my $Command_Opts = "";
# Read log output from stdin instead of invoking cvs log?
my $Input_From_Stdin = 0;
# Don't show filenames in output.
my $Hide_Filenames = 0;
# Max checkin duration. CVS checkin is not atomic, so we may have checkin
# times that span a range of time. We assume that checkins will last no
# longer than $Max_Checkin_Duration seconds, and that similarly, no
# checkins will happen from the same users with the same message less
# than $Max_Checkin_Duration seconds apart.
my $Max_Checkin_Duration = 180;
# What to put at the front of [each] ChangeLog.
my $ChangeLog_Header = "";
## end vars set by options.
# In 'cvs log' output, one long unbroken line of equal signs separates
# files:
my $file_separator = "======================================="
. "======================================";
# In 'cvs log' output, a shorter line of dashes separates log messages
# within a file:
my $logmsg_separator = "----------------------------";
############### End globals ############
&parse_options ();
&derive_change_log ();
### Everything below is subroutine definitions. ###
# Fills up a ChangeLog structure in the current directory.
sub derive_change_log ()
{
# See "The Plan" above for a full explanation.
my %grand_poobah;
my $file_full_path;
my $time;
my $revision;
my $author;
my $msg_txt;
my $detected_file_separator;
# We might be expanding usernames
my %usermap;
# In general, it's probably not very maintainable to use state
# variables like this to tell the loop what it's doing at any given
# moment, but this is only the first one, and if we never have more
# than a few of these, it's okay.
my $collecting_symbolic_names = 0;
my %symbolic_names; # Where tag names get stored.
my %branch_names; # We'll grab branch names while we're at it.
my %branch_numbers; # Save some revisions for @Follow_Branches
my @branch_roots; # For showing which files are branch ancestors.
# Bleargh. Compensate for a deficiency of custom wrapping.
if (($After_Header ne " ") and $FSF_Style)
{
$After_Header .= "\t";
}
if (! $Input_From_Stdin) {
open (LOG_SOURCE, "$Log_Source_Command |")
or die "unable to run \"${Log_Source_Command}\"";
}
else {
open (LOG_SOURCE, "-") or die "unable to open stdin for reading";
}
%usermap = &maybe_read_user_map_file ();
while (<LOG_SOURCE>)
{
# If on a new file and don't see filename, skip until we find it, and
# when we find it, grab it.
if ((! (defined $file_full_path)) and /^Working file: (.*)/)
{
$file_full_path = $1;
if (@Ignore_Files)
{
my $base;
($base, undef, undef) = fileparse ($file_full_path);
# Ouch, I wish trailing operators in regexps could be
# evaluated on the fly!
if ($Case_Insensitive) {
if (grep ($file_full_path =~ m|$_|i, @Ignore_Files)) {
undef $file_full_path;
}
}
elsif (grep ($file_full_path =~ m|$_|, @Ignore_Files)) {
undef $file_full_path;
}
}
next;
}
# Just spin wheels if no file defined yet.
next if (! $file_full_path);
# Collect tag names in case we're asked to print them in the output.
if (/^symbolic names:$/) {
$collecting_symbolic_names = 1;
next; # There's no more info on this line, so skip to next
}
if ($collecting_symbolic_names)
{
# All tag names are listed with whitespace in front in cvs log
# output; so if see non-whitespace, then we're done collecting.
if (/^\S/) {
$collecting_symbolic_names = 0;
}
else # we're looking at a tag name, so parse & store it
{
# According to the Cederqvist manual, in node "Tags", tag
# names must start with an uppercase or lowercase letter and
# can contain uppercase and lowercase letters, digits, `-',
# and `_'. However, it's not our place to enforce that, so
# we'll allow anything CVS hands us to be a tag:
/^\s+([^:]+): ([\d.]+)$/;
my $tag_name = $1;
my $tag_rev = $2;
# A branch number either has an odd number of digit sections
# (and hence an even number of dots), or has ".0." as the
# second-to-last digit section. Test for these conditions.
my $real_branch_rev = "";
if (($tag_rev =~ /^(\d+\.\d+\.)+\d+$/) # Even number of dots...
and (! ($tag_rev =~ /^(1\.)+1$/))) # ...but not "1.[1.]1"
{
$real_branch_rev = $tag_rev;
}
elsif ($tag_rev =~ /(\d+\.(\d+\.)+)0.(\d+)/) # Has ".0."
{
$real_branch_rev = $1 . $3;
}
# If we got a branch, record its number.
if ($real_branch_rev)
{
$branch_names{$real_branch_rev} = $tag_name;
if (@Follow_Branches) {
if (grep ($_ eq $tag_name, @Follow_Branches)) {
$branch_numbers{$tag_name} = $real_branch_rev;
}
}
}
else {
# Else it's just a regular (non-branch) tag.
push (@{$symbolic_names{$tag_rev}}, $tag_name);
}
}
}
# End of code for collecting tag names.
# If have file name, but not revision, and see revision, then grab
# it. (We collect unconditionally, even though we may or may not
# ever use it.)
if ((! (defined $revision)) and (/^revision (\d+\.[\d.]+)/))
{
$revision = $1;
if (@Follow_Branches)
{
foreach my $branch (@Follow_Branches)
{
# Special case for following trunk revisions
if (($branch =~ /^trunk$/i) and ($revision =~ /^[0-9]+\.[0-9]+$/))
{
goto dengo;
}
my $branch_number = $branch_numbers{$branch};
if ($branch_number)
{
# Are we on one of the follow branches or an ancestor of
# same?
#
# If this revision is a prefix of the branch number, or
# possibly is less in the minormost number, OR if this
# branch number is a prefix of the revision, then yes.
# Otherwise, no.
#
# So below, we determine if any of those conditions are
# met.
# Trivial case: is this revision on the branch?
# (Compare this way to avoid regexps that screw up Emacs
# indentation, argh.)
if ((substr ($revision, 0, ((length ($branch_number)) + 1)))
eq ($branch_number . "."))
{
goto dengo;
}
# Non-trivial case: check if rev is ancestral to branch
elsif ((length ($branch_number)) > (length ($revision)))
{
$revision =~ /^((?:\d+\.)+)(\d+)$/;
my $r_left = $1; # still has the trailing "."
my $r_end = $2;
$branch_number =~ /^((?:\d+\.)+)(\d+)\.\d+$/;
my $b_left = $1; # still has trailing "."
my $b_mid = $2; # has no trailing "."
if (($r_left eq $b_left)
&& ($r_end <= $b_mid))
{
goto dengo;
}
}
}
}
}
else # (! @Follow_Branches)
{
next;
}
# Else we are following branches, but this revision isn't on the
# path. So skip it.
undef $revision;
dengo:
next;
}
# If we don't have a revision right now, we couldn't possibly
# be looking at anything useful.
if (! (defined ($revision))) {
$detected_file_separator = /^$file_separator$/o;
if ($detected_file_separator) {
# No revisions for this file; can happen, e.g. "cvs log -d DATE"
goto CLEAR;
}
else {
next;
}
}
# If have file name but not date and author, and see date or
# author, then grab them:
unless (defined $time)
{
if (/^date: .*/)
{
($time, $author) = &parse_date_and_author ($_);
if (defined ($usermap{$author}) and $usermap{$author}) {
$author = $usermap{$author};
}
}
else {
$detected_file_separator = /^$file_separator$/o;
if ($detected_file_separator) {
# No revisions for this file; can happen, e.g. "cvs log -d DATE"
goto CLEAR;
}
}
# If the date/time/author hasn't been found yet, we couldn't
# possibly care about anything we see. So skip:
next;
}
# A "branches: ..." line here indicates that one or more branches
# are rooted at this revision. If we're showing branches, then we
# want to show that fact as well, so we collect all the branches
# that this is the latest ancestor of and store them in
# @branch_roots. Just for reference, the format of the line we're
# seeing at this point is:
#
# branches: 1.5.2; 1.5.4; ...;
#
# Okay, here goes:
if (/^branches:\s+(.*);$/)
{
if ($Show_Branches)
{
my $lst = $1;
$lst =~ s/(1\.)+1;|(1\.)+1$//; # ignore the trivial branch 1.1.1
if ($lst) {
@branch_roots = split (/;\s+/, $lst);
}
else {
undef @branch_roots;
}
next;
}
else
{
# Ugh. This really bothers me. Suppose we see a log entry
# like this:
#
# ----------------------------
# revision 1.1
# date: 1999/10/17 03:07:38; author: jrandom; state: Exp;
# branches: 1.1.2;
# Intended first line of log message begins here.
# ----------------------------
#
# The question is, how we can tell the difference between that
# log message and a *two*-line log message whose first line is
#
# "branches: 1.1.2;"
#
# See the problem? The output of "cvs log" is inherently
# ambiguous.
#
# For now, we punt: we liberally assume that people don't
# write log messages like that, and just toss a "branches:"
# line if we see it but are not showing branches. I hope no
# one ever loses real log data because of this.
next;
}
}
# If have file name, time, and author, then we're just grabbing
# log message texts:
$detected_file_separator = /^$file_separator$/o;
if ($detected_file_separator && ! (defined $revision)) {
# No revisions for this file; can happen, e.g. "cvs log -d DATE"
goto CLEAR;
}
unless ($detected_file_separator || /^$logmsg_separator$/o)
{
$msg_txt .= $_; # Normally, just accumulate the message...
next;
}
# ... until a msg separator is encountered:
# Ensure the message contains something:
if ((! $msg_txt)
|| ($msg_txt =~ /^\s*\.\s*$|^\s*$/)
|| ($msg_txt =~ /\*\*\* empty log message \*\*\*/))
{
if ($Prune_Empty_Msgs) {
goto CLEAR;
}
# else
$msg_txt = "[no log message]\n";
}
### Store it all in the Grand Poobah:
{
my $dir_key; # key into %grand_poobah
my %qunk; # complicated little jobbie, see below
# Each revision of a file has a little data structure (a `qunk')
# associated with it. That data structure holds not only the
# file's name, but any additional information about the file
# that might be needed in the output, such as the revision
# number, tags, branches, etc. The reason to have these things
# arranged in a data structure, instead of just appending them
# textually to the file's name, is that we may want to do a
# little rearranging later as we write the output. For example,
# all the files on a given tag/branch will go together, followed
# by the tag in parentheses (so trunk or otherwise non-tagged
# files would go at the end of the file list for a given log
# message). This rearrangement is a lot easier to do if we
# don't have to reparse the text.
#
# A qunk looks like this:
#
# {
# filename => "hello.c",
# revision => "1.4.3.2",
# time => a timegm() return value (moment of commit)
# tags => [ "tag1", "tag2", ... ],
# branch => "branchname" # There should be only one, right?
# branchroots => [ "branchtag1", "branchtag2", ... ]
# }
if ($Distributed) {
# Just the basename, don't include the path.
($qunk{'filename'}, $dir_key, undef) = fileparse ($file_full_path);
}
else {
$dir_key = "./";
$qunk{'filename'} = $file_full_path;
}
# This may someday be used in a more sophisticated calculation
# of what other files are involved in this commit. For now, we
# don't use it, because the common-commit-detection algorithm is
# hypothesized to be "good enough" as it stands.
$qunk{'time'} = $time;
# We might be including revision numbers and/or tags and/or
# branch names in the output. Most of the code from here to
# loop-end deals with organizing these in qunk.
$qunk{'revision'} = $revision;
# Grab the branch, even though we may or may not need it:
$qunk{'revision'} =~ /((?:\d+\.)+)\d+/;
my $branch_prefix = $1;
$branch_prefix =~ s/\.$//; # strip off final dot
if ($branch_names{$branch_prefix}) {
$qunk{'branch'} = $branch_names{$branch_prefix};
}
# If there's anything in the @branch_roots array, then this
# revision is the root of at least one branch. We'll display
# them as branch names instead of revision numbers, the
# substitution for which is done directly in the array:
if (@branch_roots) {
my @roots = map { $branch_names{$_} } @branch_roots;
$qunk{'branchroots'} = \@roots;
}
# Save tags too.
if (defined ($symbolic_names{$revision})) {
$qunk{'tags'} = $symbolic_names{$revision};
delete $symbolic_names{$revision};
}
# Add this file to the list
# (We use many spoonfuls of autovivication magic. Hashes and arrays
# will spring into existence if they aren't there already.)
&debug ("(pushing log msg for ${dir_key}$qunk{'filename'})\n");
# Store with the files in this commit. Later we'll loop through
# again, making sure that revisions with the same log message
# and nearby commit times are grouped together as one commit.
push (@{$grand_poobah{$dir_key}{$author}{$time}{$msg_txt}}, \%qunk);
}
CLEAR:
# Make way for the next message
undef $msg_txt;
undef $time;
undef $revision;
undef $author;
undef @branch_roots;
# Maybe even make way for the next file:
if ($detected_file_separator) {
undef $file_full_path;
undef %branch_names;
undef %branch_numbers;
}
}
close (LOG_SOURCE);
### Process each ChangeLog
while (my ($dir,$authorhash) = each %grand_poobah)
{
&debug ("DOING DIR: $dir\n");
# Here we twist our hash around, from being
# author => time => message => filelist
# in %$authorhash to
# time => author => message => filelist
# in %changelog.
#
# This is also where we merge entries. The algorithm proceeds
# through the timeline of the changelog with a sliding window of
# $Max_Checkin_Duration seconds; within that window, entries that
# have the same log message are merged.
#
# (To save space, we zap %$authorhash after we've copied
# everything out of it.)
my %changelog;
while (my ($author,$timehash) = each %$authorhash)
{
my $lasttime;
my %stamptime;
foreach my $time (sort {$main::a <=> $main::b} (keys %$timehash))
{
my $msghash = $timehash->{$time};
while (my ($msg,$qunklist) = each %$msghash)
{
my $stamptime = $stamptime{$msg};
if ((defined $stamptime)
and (($time - $stamptime) < $Max_Checkin_Duration)
and (defined $changelog{$stamptime}{$author}{$msg}))
{
push(@{$changelog{$stamptime}{$author}{$msg}}, @$qunklist);
}
else {
$changelog{$time}{$author}{$msg} = $qunklist;
$stamptime{$msg} = $time;
}
}
}
}
undef (%$authorhash);
### Now we can write out the ChangeLog!
my ($logfile_here, $logfile_bak, $tmpfile);
if (! $Output_To_Stdout) {
$logfile_here = $dir . $Log_File_Name;
$logfile_here =~ s/^\.\/\//\//; # fix any leading ".//" problem
$tmpfile = "${logfile_here}.cvs2cl$$.tmp";
$logfile_bak = "${logfile_here}.bak";
open (LOG_OUT, ">$tmpfile") or die "Unable to open \"$tmpfile\"";
}
else {
open (LOG_OUT, ">-") or die "Unable to open stdout for writing";
}
print LOG_OUT $ChangeLog_Header;
if ($XML_Output) {
print LOG_OUT "<?xml version=\"1.0\"?>\n\n"
. "<changelog xmlns=\"http://www.red-bean.com/xmlns/cvs2cl/\">\n\n";
}
foreach my $time (sort {$main::b <=> $main::a} (keys %changelog))
{
my $authorhash = $changelog{$time};
while (my ($author,$mesghash) = each %$authorhash)
{
# If XML, escape in outer loop to avoid compound quoting:
if ($XML_Output) {
$author = &xml_escape ($author);
}
while (my ($msg,$qunklist) = each %$mesghash)
{
my $files = &pretty_file_list ($qunklist);
my $header_line; # date and author
my $body; # see below
my $wholething; # $header_line + $body
# Set up the date/author line.
# kff todo: do some more XML munging here, on the header
# part of the entry:
my ($ignore,$min,$hour,$mday,$mon,$year,$wday)
= $UTC_Times ? gmtime($time) : localtime($time);
# XML output includes everything else, we might as well make
# it always include Day Of Week too, for consistency.
if ($Show_Day_Of_Week or $XML_Output) {
$wday = ("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday")[$wday];
$wday = ($XML_Output) ? "<weekday>${wday}</weekday>\n" : " $wday";
}
else {
$wday = "";
}
if ($XML_Output) {
$header_line =
sprintf ("<date>%4u-%02u-%02u</date>\n"
. "${wday}"
. "<time>%02u:%02u</time>\n"
. "<author>%s</author>\n",
$year+1900, $mon+1, $mday, $hour, $min, $author);
}
else {
$header_line =
sprintf ("%4u-%02u-%02u${wday} %02u:%02u %s\n\n",
$year+1900, $mon+1, $mday, $hour, $min, $author);
}
# Reshape the body according to user preferences.
if ($XML_Output)
{
$msg = &preprocess_msg_text ($msg);
$body = $files . $msg;
}
elsif ($No_Wrap)
{
$msg = &preprocess_msg_text ($msg);
$files = wrap ("\t", " ", "$files");
$msg =~ s/\n(.*)/\n\t$1/g;
unless ($After_Header eq " ") {
$msg =~ s/^(.*)/\t$1/g;
}
$body = $files . $After_Header . $msg;
}
else # do wrapping, either FSF-style or regular
{
if ($FSF_Style)
{
$files = wrap ("\t", " ", "$files");
my $files_last_line_len = 0;
if ($After_Header eq " ")
{
$files_last_line_len = &last_line_len ($files);
$files_last_line_len += 1; # for $After_Header
}
$msg = &wrap_log_entry
($msg, "\t", 69 - $files_last_line_len, 69);
$body = $files . $After_Header . $msg;
}
else # not FSF-style
{
$msg = &preprocess_msg_text ($msg);
$body = $files . $After_Header . $msg;
$body = wrap ("\t", " ", "$body");
}
}
$wholething = $header_line . $body;
if ($XML_Output) {
$wholething = "<entry>\n${wholething}</entry>\n";
}
# One last check: make sure it passes the regexp test, if the
# user asked for that. We have to do it here, so that the
# test can match against information in the header as well
# as in the text of the log message.
# How annoying to duplicate so much code just because I
# can't figure out a way to evaluate scalars on the trailing
# operator portion of a regular expression. Grrr.
if ($Case_Insensitive) {
unless ($Regexp_Gate && ($wholething !~ /$Regexp_Gate/oi)) {
print LOG_OUT "${wholething}\n";
}
}
else {
unless ($Regexp_Gate && ($wholething !~ /$Regexp_Gate/o)) {
print LOG_OUT "${wholething}\n";
}
}
}
}
}
if ($XML_Output) {
print LOG_OUT "</changelog>\n";
}
close (LOG_OUT);
if (! $Output_To_Stdout)
{
if (-f $logfile_here) {
rename ($logfile_here, $logfile_bak);
}
rename ($tmpfile, $logfile_here);
}
}
}
sub parse_date_and_author ()
{
# Parses the date/time and author out of a line like:
#
# date: 1999/02/19 23:29:05; author: apharris; state: Exp;
my $line = shift;
my ($year, $mon, $mday, $hours, $min, $secs, $author) = $line =~
m#(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+([^;]+);#
or die "Couldn't parse date ``$line''";
die "Bad date or Y2K issues" unless ($year > 1969 and $year < 2258);
# Kinda arbitrary, but useful as a sanity check
my $time = timegm($secs,$min,$hours,$mday,$mon-1,$year-1900);
return ($time, $author);
}
# Here we take a bunch of qunks and convert them into printed
# summary that will include all the information the user asked for.
sub pretty_file_list ()
{
if ($Hide_Filenames and (! $XML_Output)) {
return "";
}
my $qunksref = shift;
my @qunkrefs = @$qunksref;
my @filenames;
my $beauty = ""; # The accumulating header string for this entry.
my %non_unanimous_tags; # Tags found in a proper subset of qunks
my %unanimous_tags; # Tags found in all qunks
my %all_branches; # Branches found in any qunk
my $common_dir = undef; # Dir prefix common to all files ("" if none)
my $fbegun = 0; # Did we begin printing filenames yet?
# First, loop over the qunks gathering all the tag/branch names.
# We'll put them all in non_unanimous_tags, and take out the
# unanimous ones later.
foreach my $qunkref (@qunkrefs)
{
# Keep track of whether all the files in this commit were in the
# same directory, and memorize it if so. We can make the output a
# little more compact by mentioning the directory only once.
if ((scalar (@qunkrefs)) > 1)
{
if (! (defined ($common_dir)))
{
my ($base, $dir);
($base, $dir, undef) = fileparse ($$qunkref{'filename'});
if ((! (defined ($dir))) # this first case is sheer paranoia
or ($dir eq "")
or ($dir eq "./")
or ($dir eq ".\\"))
{
$common_dir = "";
}
else
{
$common_dir = $dir;
}
}
elsif ($common_dir ne "")
{
# Already have a common dir prefix, so how much of it can we preserve?
$common_dir = &common_path_prefix ($$qunkref{'filename'}, $common_dir);
}
}
else # only one file in this entry anyway, so common dir not an issue
{
$common_dir = "";
}
if (defined ($$qunkref{'branch'})) {
$all_branches{$$qunkref{'branch'}} = 1;
}
if (defined ($$qunkref{'tags'})) {
foreach my $tag (@{$$qunkref{'tags'}}) {
$non_unanimous_tags{$tag} = 1;
}
}
}
# Any tag held by all qunks will be printed specially... but only if
# there are multiple qunks in the first place!
if ((scalar (@qunkrefs)) > 1) {
foreach my $tag (keys (%non_unanimous_tags)) {
my $everyone_has_this_tag = 1;
foreach my $qunkref (@qunkrefs) {
if ((! (defined ($$qunkref{'tags'})))
or (! (grep ($_ eq $tag, @{$$qunkref{'tags'}})))) {
$everyone_has_this_tag = 0;
}
}
if ($everyone_has_this_tag) {
$unanimous_tags{$tag} = 1;
delete $non_unanimous_tags{$tag};
}
}
}
if ($XML_Output)
{
# If outputting XML, then our task is pretty simple, because we
# don't have to detect common dir, common tags, branch prefixing,
# etc. We just output exactly what we have, and don't worry about
# redundancy or readability.
foreach my $qunkref (@qunkrefs)
{
my $filename = $$qunkref{'filename'};
my $revision = $$qunkref{'revision'};
my $tags = $$qunkref{'tags'};
my $branch = $$qunkref{'branch'};
my $branchroots = $$qunkref{'branchroots'};
$filename = &xml_escape ($filename); # probably paranoia
$revision = &xml_escape ($revision); # definitely paranoia
$beauty .= "<file>\n";
$beauty .= "<name>${filename}</name>\n";
$beauty .= "<revision>${revision}</revision>\n";
if ($branch) {
$branch = &xml_escape ($branch); # more paranoia
$beauty .= "<branch>${branch}</branch>\n";
}
foreach my $tag (@$tags) {
$tag = &xml_escape ($tag); # by now you're used to the paranoia
$beauty .= "<tag>${tag}</tag>\n";
}
foreach my $root (@$branchroots) {
$root = &xml_escape ($root); # which is good, because it will continue
$beauty .= "<branchroot>${root}</branchroot>\n";
}
$beauty .= "</file>\n";
}
# Theoretically, we could go home now. But as long as we're here,
# let's print out the common_dir and utags, as a convenience to
# the receiver (after all, earlier code calculated that stuff
# anyway, so we might as well take advantage of it).
if ((scalar (keys (%unanimous_tags))) > 1) {
foreach my $utag ((keys (%unanimous_tags))) {
$utag = &xml_escape ($utag); # the usual paranoia
$beauty .= "<utag>${utag}</utag>\n";
}
}
if ($common_dir) {
$common_dir = &xml_escape ($common_dir);
$beauty .= "<commondir>${common_dir}</commondir>\n";
}
# That's enough for XML, time to go home:
return $beauty;
}
# Else not XML output, so complexly compactify for chordate
# consumption. At this point we have enough global information
# about all the qunks to organize them non-redundantly for output.
if ($common_dir) {
# Note that $common_dir still has its trailing slash
$beauty .= "$common_dir: ";
}
if ($Show_Branches)
{
# For trailing revision numbers.
my @brevisions;
foreach my $branch (keys (%all_branches))
{
foreach my $qunkref (@qunkrefs)
{
if ((defined ($$qunkref{'branch'}))
and ($$qunkref{'branch'} eq $branch))
{
if ($fbegun) {
# kff todo: comma-delimited in XML too? Sure.
$beauty .= ", ";
}
else {
$fbegun = 1;
}
my $fname = substr ($$qunkref{'filename'}, length ($common_dir));