-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcvs2cl.pl
executable file
·3250 lines (2533 loc) · 90.4 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.1 $
## $Date: 2010/07/03 13:35:34 $
## $Author: tkamogashira $
##
use strict;
use File::Basename qw( fileparse );
use Getopt::Long qw( GetOptions );
use Text::Wrap qw( );
use Time::Local qw( timegm );
use User::pwent qw( getpwnam );
# 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.
# Call Tree
# name number of lines (10.xii.03)
# parse_options 192
# derive_changelog 13
# +-maybe_grab_accumulation_date 38
# +-read_changelog 277
# +-maybe_read_user_map_file 94
# +-run_ext 9
# +-read_file_path 29
# +-read_symbolic_name 43
# +-read_revision 49
# +-read_date_author_and_state 25
# +-parse_date_author_and_state 20
# +-read_branches 36
# +-output_changelog 424
# +-pretty_file_list 290
# +-common_path_prefix 35
# +-preprocess_msg_text 30
# +-min 1
# +-mywrap 16
# +-last_line_len 5
# +-wrap_log_entry 177
#
# Utilities
#
# xml_escape 6
# slurp_file 11
# debug 5
# version 2
# usage 142
# -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*-
#
# Note about a bug-slash-opportunity:
# -----------------------------------
#
# There's a bug in Text::Wrap, which affects cvs2cl. This script
# reveals it:
#
# #!/usr/bin/perl -w
#
# use Text::Wrap;
#
# my $test_text =
# "This script demonstrates a bug in Text::Wrap. The very long line
# following this paragraph will be relocated relative to the surrounding
# text:
#
# ====================================================================
#
# See? When the bug happens, we'll get the line of equal signs below
# this paragraph, even though it should be above.";
#
#
# # Print out the test text with no wrapping:
# print "$test_text";
# print "\n";
# print "\n";
#
# # Now print it out wrapped, and see the bug:
# print wrap ("\t", " ", "$test_text");
# print "\n";
# print "\n";
#
# If the line of equal signs were one shorter, then the bug doesn't
# happen. Interesting.
#
# Anyway, rather than fix this in Text::Wrap, we might as well write a
# new wrap() which has the following much-needed features:
#
# * initial indentation, like current Text::Wrap()
# * subsequent line indentation, like current Text::Wrap()
# * user chooses among: force-break long words, leave them alone, or die()?
# * preserve existing indentation: chopped chunks from an indented line
# are indented by same (like this line, not counting the asterisk!)
# * optional list of things to preserve on line starts, default ">"
#
# Note that the last two are essentially the same concept, so unify in
# implementation and give a good interface to controlling them.
#
# And how about:
#
# Optionally, when encounter a line pre-indented by same as previous
# line, then strip the newline and refill, but indent by the same.
# Yeah...
# Globals --------------------------------------------------------------------
# In case we have to print it out:
my $VERSION = '$Revision: 1.1 $';
$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;
# What file should we generate (defaults to "ChangeLog")?
my $Log_File_Name = "ChangeLog";
# Grab most recent entry date from existing ChangeLog file, just add
# to that ChangeLog.
my $Cumulative = 0;
# `cvs log -d`, this will repeat the last entry in the old log. This is OK,
# as it guarantees at least one entry in the update changelog, which means
# that there will always be a date to extract for the next update. The repeat
# entry can be removed in postprocessing, if necessary.
# MJP 2003-08-02
# I don't think this actually does anything useful
my $Update = 0;
# Expand usernames to email addresses based on a map file?
my $User_Map_File = '';
my $User_Passwd_File;
my $Mail_Domain;
# Output log in chronological order? [default is reverse chronological order]
my $Chronological_Order = 0;
# Grab user details via gecos
my $Gecos = 0;
# User domain for gecos email addresses
my $Domain;
# Output to a file or to stdout?
my $Output_To_Stdout = 0;
# Eliminate empty log messages?
my $Prune_Empty_Msgs = 0;
# Tags of which not to output
my %ignore_tags;
# Show only revisions with Tags
my %show_tags;
# Don't call Text::Wrap on the body of the message
my $No_Wrap = 0;
# Indentation of log messages
my $Indent = "\t";
# Don't do any pretty print processing
my $Summary = 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 = " ";
# XML Encoding
my $XML_Encoding = '';
# Format more for programs than for humans.
my $XML_Output = 0;
my $No_XML_Namespace = 0;
my $No_XML_ISO_Date = 0;
# Do some special tweaks for log data that was written in FSF
# ChangeLog style.
my $FSF_Style = 0;
# Set iff output should be like an FSF-style ChangeLog.
my $FSF_Output = 0;
# Show times in UTC instead of local time
my $UTC_Times = 0;
# Show times in output?
my $Show_Times = 1;
# Show day of week in output?
my $Show_Day_Of_Week = 0;
# Show revision numbers in output?
my $Show_Revisions = 0;
# Show dead files in output?
my $Show_Dead = 0;
# Hide dead trunk files which were created as a result of additions on a
# branch?
my $Hide_Branch_Additions = 1;
# Show tags (symbolic names) in output?
my $Show_Tags = 0;
# Show tags separately in output?
my $Show_Tag_Dates = 0;
# Show branches by symbolic name in output?
my $Show_Branches = 0;
# Show only revisions on these branches or their ancestors.
my @Follow_Branches;
# Show only revisions on these branches or their ancestors; ignore descendent
# branches.
my @Follow_Only;
# 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;
# Don't shorten directory names from filenames.
my $Common_Dir = 1;
# 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 = '';
# Whether to enable 'delta' mode, and for what start/end tags.
my $Delta_Mode = 0;
my $Delta_From = '';
my $Delta_To = '';
my $TestCode;
# Whether to parse filenames from the RCS filename, and if so what
# prefix to strip.
my $RCS_Root;
# Whether to output information on the # of lines added and removed
# by each file modification.
my $Show_Lines_Modified = 0;
## end vars set by options.
# latest observed times for the start/end tags in delta mode
my $Delta_StartTime = 0;
my $Delta_EndTime = 0;
my $No_Ancestors = 0;
my $No_Extra_Indent = 0;
my $GroupWithinDate = 0;
# ----------------------------------------------------------------------------
package CVS::Utils::ChangeLog::EntrySet;
sub new {
my $class = shift;
my %self;
bless \%self, $class;
}
# -------------------------------------
sub output_changelog {
my $output_type = $XML_Output ? 'XML' : 'Text';
my $output_class = "CVS::Utils::ChangeLog::EntrySet::Output::${output_type}";
my $output = $output_class->new(follow_branches => \@Follow_Branches,
follow_only => \@Follow_Only,
ignore_tags => \%ignore_tags,
show_tags => \%show_tags,
);
$output->output_changelog(@_);
}
# -------------------------------------
sub add_fileentry {
my ($self, $file_full_path, $time, $revision, $state, $lines,
$branch_names, $branch_roots, $branch_numbers,
$symbolic_names, $author, $msg_txt) = @_;
my $qunk =
CVS::Utils::ChangeLog::FileEntry->new($file_full_path, $time, $revision,
$state, $lines,
$branch_names, $branch_roots,
$branch_numbers,
$symbolic_names);
# 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.
unless ( $Hide_Branch_Additions
and
$msg_txt =~ /file .+ was initially added on branch \S+./ ) {
# 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.)
&main::debug ("(pushing log msg for ". $qunk->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.
$self->{$qunk->dir_key}{$author}{$time}{$msg_txt} =
CVS::Utils::ChangeLog::Message->new($msg_txt)
unless exists $self->{$qunk->dir_key}{$author}{$time}{$msg_txt};
$self->{$qunk->dir_key}{$author}{$time}{$msg_txt}->add_fileentry($qunk);
}
}
# ----------------------------------------------------------------------------
package CVS::Utils::ChangeLog::EntrySet::Output::Text;
use base qw( CVS::Utils::ChangeLog::EntrySet::Output );
use File::Basename qw( fileparse );
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
}
# -------------------------------------
sub wday {
my $self = shift; my $class = ref $self;
my ($wday) = @_;
return $Show_Day_Of_Week ? ' ' . $class->weekday_en($wday) : '';
}
# -------------------------------------
sub header_line {
my $self = shift;
my ($time, $author, $lastdate) = @_;
my $header_line = '';
my (undef,$min,$hour,$mday,$mon,$year,$wday)
= $UTC_Times ? gmtime($time) : localtime($time);
my $date = $self->fdatetime($time);
if ($Show_Times) {
$header_line =
sprintf "%s %s\n\n", $date, $author;
} else {
if ( ! defined $lastdate or $date ne $lastdate or ! $GroupWithinDate ) {
if ( $GroupWithinDate ) {
$header_line = "$date\n\n";
} else {
$header_line = "$date $author\n\n";
}
} else {
$header_line = '';
}
}
}
# -------------------------------------
sub preprocess_msg_text {
my $self = shift;
my ($text) = @_;
$text = $self->SUPER::preprocess_msg_text($text);
unless ( $No_Wrap ) {
# Strip off lone newlines, but only for lines that don't begin with
# whitespace or a mail-quoting character, since we want to preserve
# that kind of formatting. Also don't strip newlines that follow a
# period; we handle those specially next. And don't strip
# newlines that precede an open paren.
1 while $text =~ s/(^|\n)([^>\s].*[^.\n])\n([^>\n])/$1$2 $3/g;
# If a newline follows a period, make sure that when we bring up the
# bottom sentence, it begins with two spaces.
1 while $text =~ s/(^|\n)([^>\s].*)\n([^>\n])/$1$2 $3/g;
}
return $text;
}
# -------------------------------------
# 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 {
my $self = shift;
return ''
if $Hide_Filenames;
my $qunksref = shift;
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 $fbegun = 0; # Did we begin printing filenames yet?
my ($common_dir, $qunkrefs) =
$self->_pretty_file_list(\(%unanimous_tags, %non_unanimous_tags, %all_branches), $qunksref);
my @qunkrefs = @$qunkrefs;
# 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));
$beauty .= $fname;
$qunkref->{'printed'} = 1; # Just setting a mark bit, basically
if ( $Show_Tags and defined $qunkref->tags ) {
my @tags = grep ($non_unanimous_tags{$_}, @{$qunkref->tags});
if (@tags) {
$beauty .= " (tags: ";
$beauty .= join (', ', @tags);
$beauty .= ")";
}
}
if ($Show_Revisions) {
# Collect the revision numbers' last components, but don't
# print them -- they'll get printed with the branch name
# later.
$qunkref->revision =~ /.+\.([\d]+)$/;
push (@brevisions, $1);
# todo: we're still collecting branch roots, but we're not
# showing them anywhere. If we do show them, it would be
# nifty to just call them revision "0" on a the branch.
# Yeah, that's the ticket.
}
}
}
$beauty .= " ($branch";
if (@brevisions) {
if ((scalar (@brevisions)) > 1) {
$beauty .= ".[";
$beauty .= (join (',', @brevisions));
$beauty .= "]";
}
else {
# Square brackets are spurious here, since there's no range to
# encapsulate
$beauty .= ".$brevisions[0]";
}
}
$beauty .= ")";
}
}
# Okay; any qunks that were done according to branch are taken care
# of, and marked as printed. Now print everyone else.
my %fileinfo_printed;
foreach my $qunkref (@qunkrefs)
{
next if (defined ($qunkref->{'printed'})); # skip if already printed
my $b = substr ($qunkref->filename, length ($common_dir));
# todo: Shlomo's change was this:
# $beauty .= substr ($qunkref->filename,
# (($common_dir eq "./") ? '' : length ($common_dir)));
$qunkref->{'printed'} = 1; # Set a mark bit.
if ($Show_Revisions || $Show_Tags || $Show_Dead)
{
my $started_addendum = 0;
if ($Show_Revisions) {
$started_addendum = 1;
$b .= " (";
$b .= $qunkref->revision;
}
if ($Show_Dead && $qunkref->state =~ /dead/)
{
# Deliberately not using $started_addendum. Keeping it simple.
$b .= "[DEAD]";
}
if ($Show_Tags && (defined $qunkref->tags)) {
my @tags = grep ($non_unanimous_tags{$_}, @{$qunkref->tags});
if ((scalar (@tags)) > 0) {
if ($started_addendum) {
$b .= ", ";
}
else {
$b .= " (tags: ";
}
$b .= join (', ', @tags);
$started_addendum = 1;
}
}
if ($started_addendum) {
$b .= ")";
}
}
unless ( exists $fileinfo_printed{$b} ) {
if ($fbegun) {
$beauty .= ", ";
} else {
$fbegun = 1;
}
$beauty .= $b, $fileinfo_printed{$b} = 1;
}
}
# Unanimous tags always come last.
if ($Show_Tags && %unanimous_tags)
{
$beauty .= " (utags: ";
$beauty .= join (', ', sort keys (%unanimous_tags));
$beauty .= ")";
}
# todo: still have to take care of branch_roots?
$beauty = "$beauty:";
return $beauty;
}
# -------------------------------------
sub output_tagdate {
my $self = shift;
my ($fh, $time, $tag) = @_;
my $fdatetime = $self->fdatetime($time);
print $fh "$fdatetime tag $tag\n\n";
return;
}
# -------------------------------------
sub format_body {
my $self = shift;
my ($msg, $files, $qunklist) = @_;
my $body;
if ( $No_Wrap and ! $Summary ) {
$msg = $self->preprocess_msg_text($msg);
$files = $self->mywrap("\t", "\t ", "* $files");
$msg =~ s/\n(.+)/\n$Indent$1/g;
unless ($After_Header eq " ") {
$msg =~ s/^(.+)/$Indent$1/g;
}
if ( $Hide_Filenames ) {
$body = $After_Header . $msg;
} else {
$body = $files . $After_Header . $msg;
}
} elsif ( $Summary ) {
my ($filelist, $qunk);
my (@DeletedQunks, @AddedQunks, @ChangedQunks);
$msg = $self->preprocess_msg_text($msg);
#
# Sort the files (qunks) according to the operation that was
# performed. Files which were added have no line change
# indicator, whereas deleted files have state dead.
#
foreach $qunk ( @$qunklist ) {
if ( "dead" eq $qunk->state) {
push @DeletedQunks, $qunk;
} elsif ( ! defined $qunk->lines ) {
push @AddedQunks, $qunk;
} else {
push @ChangedQunks, $qunk;
}
}
#
# The qunks list was originally in tree search order. Let's
# get that back. The lists, if they exist, will be reversed upon
# processing.
#
#
# Now write the three sections onto $filelist
#
if ( @DeletedQunks ) {
$filelist .= "\tDeleted:\n";
foreach $qunk ( @DeletedQunks ) {
$filelist .= "\t\t" . $qunk->filename;
$filelist .= " (" . $qunk->revision . ")";
$filelist .= "\n";
}
undef @DeletedQunks;
}
if ( @AddedQunks ) {
$filelist .= "\tAdded:\n";
foreach $qunk (@AddedQunks) {
$filelist .= "\t\t" . $qunk->filename;
$filelist .= " (" . $qunk->revision . ")";
$filelist .= "\n";
}
undef @AddedQunks ;
}
if ( @ChangedQunks ) {
$filelist .= "\tChanged:\n";
foreach $qunk (@ChangedQunks) {
$filelist .= "\t\t" . $qunk->filename;
$filelist .= " (" . $qunk->revision . ")";
$filelist .= ", \"" . $qunk->state . "\"";
$filelist .= ", lines: " . $qunk->lines;
$filelist .= "\n";
}
undef @ChangedQunks;
}
chomp $filelist;
if ( $Hide_Filenames ) {
$filelist = '';
}
$msg =~ s/\n(.*)/\n$Indent$1/g;
unless ( $After_Header eq " " or $FSF_Style ) {
$msg =~ s/^(.*)/$Indent$1/g;
}
unless ( $No_Wrap ) {
if ( $FSF_Style ) {
$msg = $self->wrap_log_entry($msg, '', 69, 69);
chomp($msg);
chomp($msg);
} else {
$msg = $self->mywrap('', $Indent, "$msg");
$msg =~ s/[ \t]+\n/\n/g;
}
}
$body = $filelist . $After_Header . $msg;
} else { # do wrapping, either FSF-style or regular
my $latter_wrap = $No_Extra_Indent ? $Indent : "$Indent ";
if ( $FSF_Style ) {
$files = $self->mywrap($Indent, $latter_wrap, "* $files");
my $files_last_line_len = 0;
if ( $After_Header eq " " ) {
$files_last_line_len = $self->last_line_len($files);
$files_last_line_len += 1; # for $After_Header
}
$msg = $self->wrap_log_entry($msg, $latter_wrap, 69-$files_last_line_len, 69);
$body = $files . $After_Header . $msg;
} else { # not FSF-style
$msg = $self->preprocess_msg_text($msg);
$body = $files . $After_Header . $msg;
$body = $self->mywrap($Indent, $latter_wrap, "* $body");
$body =~ s/[ \t]+\n/\n/g;
}
}
return $body;
}
# ----------------------------------------------------------------------------
package CVS::Utils::ChangeLog::EntrySet::Output::XML;
use base qw( CVS::Utils::ChangeLog::EntrySet::Output );
use File::Basename qw( fileparse );
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
}
# -------------------------------------
sub header_line {
my $self = shift;
my ($time, $author, $lastdate) = @_;
my $header_line = '';
my $isoDate;
my ($y, $m, $d, $H, $M, $S) = (gmtime($time))[5,4,3,2,1,0];
# Ideally, this would honor $UTC_Times and use +HH:MM syntax
$isoDate = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
$y + 1900, $m + 1, $d, $H, $M, $S);
my (undef,$min,$hour,$mday,$mon,$year,$wday)
= $UTC_Times ? gmtime($time) : localtime($time);
my $date = $self->fdatetime($time);
$wday = $self->wday($wday);
$header_line =
sprintf ("<date>%4u-%02u-%02u</date>\n${wday}<time>%02u:%02u</time>\n",
$year+1900, $mon+1, $mday, $hour, $min);
$header_line .= "<isoDate>$isoDate</isoDate>\n"
unless $No_XML_ISO_Date;
$header_line .= sprintf("<author>%s</author>\n" , $author);
}
# -------------------------------------
sub wday {
my $self = shift; my $class = ref $self;
my ($wday) = @_;
return '<weekday>' . $class->weekday_en($wday) . "</weekday>\n";
}
# -------------------------------------
sub escape {
my $self = shift;
my $txt = shift;
$txt =~ s/&/&/g;
$txt =~ s/</</g;
$txt =~ s/>/>/g;
return $txt;
}
# -------------------------------------
sub output_header {
my $self = shift;
my ($fh) = @_;
my $encoding =
length $XML_Encoding ? qq'encoding="$XML_Encoding"' : '';
my $version = 'version="1.0"';
my $declaration =
sprintf '<?xml %s?>', join ' ', grep length, $version, $encoding;
my $root =
$No_XML_Namespace ?
'<changelog>' :
'<changelog xmlns="http://www.red-bean.com/xmlns/cvs2cl/">';
print $fh "$declaration\n\n$root\n\n";
}
# -------------------------------------
sub output_footer {
my $self = shift;
my ($fh) = @_;
print $fh "</changelog>\n";
}
# -------------------------------------
sub preprocess_msg_text {
my $self = shift;
my ($text) = @_;
$text = $self->SUPER::preprocess_msg_text($text);
$text = $self->escape($text);
chomp $text;
$text = "<msg>${text}</msg>\n";
return $text;
}
# -------------------------------------
# Here we take a bunch of qunks and convert them into a printed
# summary that will include all the information the user asked for.
sub pretty_file_list {
my $self = shift;
my ($qunksref) = @_;
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 $fbegun = 0; # Did we begin printing filenames yet?
my ($common_dir, $qunkrefs) =
$self->_pretty_file_list(\(%unanimous_tags, %non_unanimous_tags, %all_branches),
$qunksref);
my @qunkrefs = @$qunkrefs;
# 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 $state = $qunkref->state;
my $revision = $qunkref->revision;
my $tags = $qunkref->tags;
my $branch = $qunkref->branch;
my $branchroots = $qunkref->roots;
my $lines = $qunkref->lines;
$filename = $self->escape($filename); # probably paranoia
$revision = $self->escape($revision); # definitely paranoia
$beauty .= "<file>\n";
$beauty .= "<name>${filename}</name>\n";
$beauty .= "<cvsstate>${state}</cvsstate>\n";
$beauty .= "<revision>${revision}</revision>\n";
if ($Show_Lines_Modified
&& $lines && $lines =~ m/\+(\d+)\s+-(\d+)/) {
$beauty .= "<linesadded>$1</linesadded>\n";
$beauty .= "<linesremoved>$2</linesremoved>\n";
}
if ($branch) {
$branch = $self->escape($branch); # more paranoia
$beauty .= "<branch>${branch}</branch>\n";
}
foreach my $tag (@$tags) {
$tag = $self->escape($tag); # by now you're used to the paranoia
$beauty .= "<tag>${tag}</tag>\n";
}
foreach my $root (@$branchroots) {
$root = $self->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 = $self->escape($utag); # the usual paranoia
$beauty .= "<utag>${utag}</utag>\n";
}
}
if ($common_dir) {
$common_dir = $self->escape($common_dir);
$beauty .= "<commondir>${common_dir}</commondir>\n";
}
# That's enough for XML, time to go home:
return $beauty;
}
# -------------------------------------
sub output_tagdate {
my $self = shift;
my ($fh, $time, $tag) = @_;
my ($y, $m, $d, $H, $M, $S) = (gmtime($time))[5,4,3,2,1,0];
# Ideally, this would honor $UTC_Times and use +HH:MM syntax
my $isoDate = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
$y + 1900, $m + 1, $d, $H, $M, $S);
print $fh "<tagdate>\n";
print $fh "<tagisodate>$isoDate</tagisodate>\n";
print $fh "<tagdatetag>$tag</tagdatetag>\n";
print $fh "</tagdate>\n\n";
return;
}
# -------------------------------------
sub output_entry {
my $self = shift;
my ($fh, $entry) = @_;
print $fh "<entry>\n$entry</entry>\n\n";
}
# -------------------------------------
sub format_body {
my $self = shift;
my ($msg, $files, $qunklist) = @_;
$msg = $self->preprocess_msg_text($msg);
return $files . $msg;
}
# ----------------------------------------------------------------------------
package CVS::Utils::ChangeLog::EntrySet::Output;