finally, bump the version
[alioth/cvs.git] / contrib / rcs2log.sh
1 #! /bin/sh
2
3 # Copyright (C) 1995-2005 The Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # RCS to ChangeLog generator
16
17 # Generate a change log prefix from RCS files (perhaps in the CVS repository)
18 # and the ChangeLog (if any).
19 # Output the new prefix to standard output.
20 # You can edit this prefix by hand, and then prepend it to ChangeLog.
21
22 # Ignore log entries that start with `#'.
23 # Clump together log entries that start with `{topic} ',
24 # where `topic' contains neither white space nor `}'.
25
26 Help='The default FILEs are the files registered under the working directory.
27 Options:
28
29   -c CHANGELOG  Output a change log prefix to CHANGELOG (default ChangeLog).
30   -h HOSTNAME  Use HOSTNAME in change log entries (default current host).
31   -i INDENT  Indent change log lines by INDENT spaces (default 8).
32   -l LENGTH  Try to limit log lines to LENGTH characters (default 79).
33   -L FILE  Use rlog-format FILE for source of logs.
34   -n  Obsolete, use -u instead (whose syntax differs).
35   -R  If no FILEs are given and RCS is used, recurse through working directory.
36   -r OPTION  Pass OPTION to subsidiary log command.
37   -t TABWIDTH  Tab stops are every TABWIDTH characters (default 8).
38   -u "LOGIN<tab>FULLNAME<tab>MAILADDR"  Assume LOGIN has FULLNAME and MAILADDR.
39   -v  Append RCS revision to file names in log lines.
40   --help  Output help.
41   --version  Output version number.
42
43 Report bugs to <bug-gnu-emacs@gnu.org>.'
44
45 Id='$Id: rcs2log,v 1.48 2001/09/05 23:07:46 eggert Exp $'
46
47 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2003
48 #  Free Software Foundation, Inc.
49
50 # This program is free software; you can redistribute it and/or modify
51 # it under the terms of the GNU General Public License as published by
52 # the Free Software Foundation; either version 2, or (at your option)
53 # any later version.
54 #
55 # This program is distributed in the hope that it will be useful,
56 # but WITHOUT ANY WARRANTY; without even the implied warranty of
57 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58 # GNU General Public License for more details.
59 #
60 # You should have received a copy of the GNU General Public License
61 # along with this program; see the file COPYING.  If not, write to the
62 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
63 # Boston, MA 02111-1307, USA.
64
65 Copyright='Copyright 1992-2003 Free Software Foundation, Inc.
66 This program comes with NO WARRANTY, to the extent permitted by law.
67 You may redistribute copies of this program
68 under the terms of the GNU General Public License.
69 For more information about these matters, see the files named COPYING.
70 Author: Paul Eggert <eggert@twinsun.com>'
71
72 # functions
73 @MKTEMP_SH_FUNCTION@
74
75 # Use the traditional C locale.
76 LANG=C
77 LANGUAGE=C
78 LC_ALL=C
79 LC_COLLATE=C
80 LC_CTYPE=C
81 LC_MESSAGES=C
82 LC_NUMERIC=C
83 LC_TIME=C
84 export LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME
85
86 # These variables each contain a single ASCII character.
87 # Unfortunately, there's no portable way of writing these characters
88 # in older Unix implementations, other than putting them directly into
89 # this text file.
90 SOH='\ 1' # SOH, octal code 001
91 tab='   '
92 nl='
93 '
94
95 # Parse options.
96
97 # defaults
98 : ${MKTEMP="@MKTEMP@"}
99 : ${AWK=awk}
100 : ${TMPDIR=/tmp}
101
102 changelog=ChangeLog # change log file name
103 datearg= # rlog date option
104 hostname= # name of local host (if empty, will deduce it later)
105 indent=8 # indent of log line
106 length=79 # suggested max width of log line
107 logins= # login names for people we know fullnames and mailaddrs of
108 loginFullnameMailaddrs= # login<tab>fullname<tab>mailaddr triplets
109 logTZ= # time zone for log dates (if empty, use local time)
110 recursive= # t if we want recursive rlog
111 revision= # t if we want revision numbers
112 rlog_options= # options to pass to rlog
113 rlogfile= # log file to read from
114 tabwidth=8 # width of horizontal tab
115
116 while :
117 do
118         case $1 in
119         -c)     changelog=${2?}; shift;;
120         -i)     indent=${2?}; shift;;
121         -h)     hostname=${2?}; shift;;
122         -l)     length=${2?}; shift;;
123         -L)     rlogfile=${2?}; shift;;
124         -[nu])  # -n is obsolescent; it is replaced by -u.
125                 case $1 in
126                 -n)     case ${2?}${3?}${4?} in
127                         *"$tab"* | *"$nl"*)
128                                 echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
129                                 exit 1;;
130                         esac
131                         login=$2
132                         lfm=$2$tab$3$tab$4
133                         shift; shift; shift;;
134                 -u)
135                         # If $2 is not tab-separated, use colon for separator.
136                         case ${2?} in
137                         *"$nl"*)
138                                 echo >&2 "$0: -u '$2': newlines not allowed"
139                                 exit 1;;
140                         *"$tab"*)
141                                 t=$tab;;
142                         *)
143                                 t=':';;
144                         esac
145                         case $2 in
146                         *"$t"*"$t"*"$t"*)
147                                 echo >&2 "$0: -u '$2': too many fields"
148                                 exit 1;;
149                         *"$t"*"$t"*)
150                                 uf="[^$t]*$t" # An unselected field, followed by a separator.
151                                 sf="\\([^$t]*\\)" # The selected field.
152                                 login=`expr "X$2" : "X$sf"`
153                                 lfm="$login$tab"`
154                                         expr "X$2" : "$uf$sf"
155                                   `"$tab"`
156                                         expr "X$2" : "$uf$uf$sf"
157                                 `;;
158                         *)
159                                 echo >&2 "$0: -u '$2': not enough fields"
160                                 exit 1;;
161                         esac
162                         shift;;
163                 esac
164                 case $logins in
165                 '') logins=$login;;
166                 ?*) logins=$logins$nl$login;;
167                 esac
168                 case $loginFullnameMailaddrs in
169                 '') loginFullnameMailaddrs=$lfm;;
170                 ?*) loginFullnameMailaddrs=$loginFullnameMailaddrs$nl$lfm;;
171                 esac;;
172         -r)
173                 case $rlog_options in
174                 '') rlog_options=${2?};;
175                 ?*) rlog_options=$rlog_options$nl${2?};;
176                 esac
177                 shift;;
178         -R)     recursive=t;;
179         -t)     tabwidth=${2?}; shift;;
180         -v)     revision=t;;
181         --version)
182                 set $Id
183                 rcs2logVersion=$3
184                 echo >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
185                 exit 0;;
186         -*)     echo >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
187                 case $1 in
188                 --help) exit 0;;
189                 *) exit 1;;
190                 esac;;
191         *)      break;;
192         esac
193         shift
194 done
195
196 month_data='
197         m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
198         m[3]="Apr"; m[4]="May"; m[5]="Jun"
199         m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
200         m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
201 '
202
203 logdir=$($MKTEMP -d $TMPDIR/rcs2log.XXXXXXXXXX)
204 test -n "$logdir" || exit
205 llogout=$logdir/l
206 trap exit 1 2 13 15
207 trap "rm -fr $logdir 2>/dev/null" 0
208
209 # If no rlog-format log file is given, generate one into $rlogfile.
210 case $rlogfile in
211 '')
212         rlogfile=$logdir/r
213
214         # If no rlog options are given,
215         # log the revisions checked in since the first ChangeLog entry.
216         # Since ChangeLog is only by date, some of these revisions may be duplicates of
217         # what's already in ChangeLog; it's the user's responsibility to remove them.
218         case $rlog_options in
219         '')
220                 if test -s "$changelog"
221                 then
222                         e='
223                                 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
224                                         # ISO 8601 date
225                                         print $1
226                                         exit
227                                 }
228                                 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
229                                         # old-fashioned date and time (Emacs 19.31 and earlier)
230                                         '"$month_data"'
231                                         year = $5
232                                         for (i=0; i<=11; i++) if (m[i] == $2) break
233                                         dd = $3
234                                         printf "%d-%02d-%02d\n", year, i+1, dd
235                                         exit
236                                 }
237                         '
238                         d=`$AWK "$e" <"$changelog"` || exit
239                         case $d in
240                         ?*) datearg="-d>$d";;
241                         esac
242                 fi;;
243         esac
244
245         # Use TZ specified by ChangeLog local variable, if any.
246         if test -s "$changelog"
247         then
248                 extractTZ='
249                         /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
250                                 s//\1/; p; q
251                         }
252                         /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
253                                 s//UTC0/; p; q
254                         }
255                 '
256                 logTZ=`tail "$changelog" | sed -n "$extractTZ"`
257                 case $logTZ in
258                 ?*) TZ=$logTZ; export TZ;;
259                 esac
260         fi
261
262         # If CVS is in use, examine its repository, not the normal RCS files.
263         if test ! -f CVS/Repository
264         then
265                 rlog=rlog
266                 repository=
267         else
268                 rlog='cvs -q log'
269                 repository=`sed 1q <CVS/Repository` || exit
270                 test ! -f CVS/Root || CVSROOT=`cat <CVS/Root` || exit
271                 case $CVSROOT in
272                 *:/*:/*)
273                         echo >&2 "$0: $CVSROOT: CVSROOT has multiple ':/'s"
274                         exit 1;;
275                 *:/*)
276                         # remote repository
277                         pository=`expr "X$repository" : '.*:\(/.*\)'`;;
278                 *)
279                         # local repository
280                         case $repository in
281                         /*) ;;
282                         *) repository=${CVSROOT?}/$repository;;
283                         esac
284                         if test ! -d "$repository"
285                         then
286                                 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
287                                 exit 1
288                         fi
289                         pository=$repository;;
290                 esac
291
292                 # Ensure that $pository ends in exactly one slash.
293                 while :
294                 do
295                         case $pository in
296                         *//) pository=`expr "X$pository" : 'X\(.*\)/'`;;
297                         */) break;;
298                         *) pository=$pository/; break;;
299                         esac
300                 done
301
302         fi
303
304         # Use $rlog's -zLT option, if $rlog supports it.
305         case `$rlog -zLT 2>&1` in
306         *' option'*) ;;
307         *)
308                 case $rlog_options in
309                 '') rlog_options=-zLT;;
310                 ?*) rlog_options=-zLT$nl$rlog_options;;
311                 esac;;
312         esac
313
314         # With no arguments, examine all files under the RCS directory.
315         case $# in
316         0)
317                 case $repository in
318                 '')
319                         oldIFS=$IFS
320                         IFS=$nl
321                         case $recursive in
322                         t)
323                                 RCSdirs=`find . -name RCS -type d -print`
324                                 filesFromRCSfiles='s|,v$||; s|/RCS/|/|; s|^\./||'
325                                 files=`
326                                         {
327                                                 case $RCSdirs in
328                                                 ?*) find $RCSdirs \
329                                                                 -type f \
330                                                                 ! -name '*_' \
331                                                                 ! -name ',*,' \
332                                                                 ! -name '.*_' \
333                                                                 ! -name .rcsfreeze.log \
334                                                                 ! -name .rcsfreeze.ver \
335                                                                 -print;;
336                                                 esac
337                                                 find . -name '*,v' -print
338                                         } |
339                                         sort -u |
340                                         sed "$filesFromRCSfiles"
341                                 `;;
342                         *)
343                                 files=
344                                 for file in RCS/.* RCS/* .*,v *,v
345                                 do
346                                         case $file in
347                                         RCS/. | RCS/.. | RCS/,*, | RCS/*_) continue;;
348                                         RCS/.rcsfreeze.log | RCS/.rcsfreeze.ver) continue;;
349                                         RCS/.\* | RCS/\* | .\*,v | \*,v) test -f "$file" || continue;;
350                                         RCS/*,v | RCS/.*,v) ;;
351                                         RCS/* | RCS/.*) test -f "$file" || continue;;
352                                         esac
353                                         case $files in
354                                         '') files=$file;;
355                                         ?*) files=$files$nl$file;;
356                                         esac
357                                 done
358                                 case $files in
359                                 '') exit 0;;
360                                 esac;;
361                         esac
362                         set x $files
363                         shift
364                         IFS=$oldIFS;;
365                 esac;;
366         esac
367
368         case $datearg in
369         ?*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogfile;;
370         '') $rlog $rlog_options ${1+"$@"} >$rlogfile;;
371         esac || exit;;
372 esac
373
374
375 # Get the full name of each author the logs mention, and set initialize_fullname
376 # to awk code that initializes the `fullname' awk associative array.
377 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
378 # you have to fix the resulting output by hand.
379
380 initialize_fullname=
381 initialize_mailaddr=
382
383 case $loginFullnameMailaddrs in
384 ?*)
385         case $loginFullnameMailaddrs in
386         *\"* | *\\*)
387                 sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
388 $loginFullnameMailaddrs
389 EOF
390                 loginFullnameMailaddrs=`cat $llogout`;;
391         esac
392
393         oldIFS=$IFS
394         IFS=$nl
395         for loginFullnameMailaddr in $loginFullnameMailaddrs
396         do
397                 IFS=$tab
398                 set x $loginFullnameMailaddr
399                 login=$2
400                 fullname=$3
401                 mailaddr=$4
402                 initialize_fullname="$initialize_fullname
403                         fullname[\"$login\"] = \"$fullname\""
404                 initialize_mailaddr="$initialize_mailaddr
405                         mailaddr[\"$login\"] = \"$mailaddr\""
406         done
407         IFS=$oldIFS;;
408 esac
409
410 case $logins in
411 ?*)
412         sort -u -o $llogout <<EOF
413 $logins
414 EOF
415         ;;
416 '')
417         : ;;
418 esac >$llogout || exit
419
420 output_authors='/^date: / {
421         if ($2 ~ /^[0-9]*[-\/][0-9][0-9][-\/][0-9][0-9]$/ && $3 ~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9][-+0-9:]*;$/ && $4 == "author:" && $5 ~ /^[^;]*;$/) {
422                 print substr($5, 1, length($5)-1)
423         }
424 }'
425 authors=`
426         $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - $llogout
427 `
428 case $authors in
429 ?*)
430         cat >$llogout <<EOF || exit
431 $authors
432 EOF
433         initialize_author_script='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
434         initialize_author=`sed -e "$initialize_author_script" <$llogout`
435         awkscript='
436                 BEGIN {
437                         alphabet = "abcdefghijklmnopqrstuvwxyz"
438                         ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
439                         '"$initialize_author"'
440                 }
441                 {
442                         if (author[$1]) {
443                                 fullname = $5
444                                 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
445                                         # Remove the junk from fullnames like "0000-Admin(0000)".
446                                         fullname = substr(fullname, index(fullname, "-") + 1)
447                                         fullname = substr(fullname, 1, index(fullname, "(") - 1)
448                                 }
449                                 if (fullname ~ /,[^ ]/) {
450                                         # Some sites put comma-separated junk after the fullname.
451                                         # Remove it, but leave "Bill Gates, Jr" alone.
452                                         fullname = substr(fullname, 1, index(fullname, ",") - 1)
453                                 }
454                                 abbr = index(fullname, "&")
455                                 if (abbr) {
456                                         a = substr($1, 1, 1)
457                                         A = a
458                                         i = index(alphabet, a)
459                                         if (i) A = substr(ALPHABET, i, 1)
460                                         fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
461                                 }
462
463                                 # Quote quotes and backslashes properly in full names.
464                                 # Do not use gsub; traditional awk lacks it.
465                                 quoted = ""
466                                 rest = fullname
467                                 for (;;) {
468                                         p = index(rest, "\\")
469                                         q = index(rest, "\"")
470                                         if (p) {
471                                                 if (q && q<p) p = q
472                                         } else {
473                                                 if (!q) break
474                                                 p = q
475                                         }
476                                         quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
477                                         rest = substr(rest, p+1)
478                                 }
479
480                                 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
481                                 author[$1] = 0
482                         }
483                 }
484         '
485
486         initialize_fullname=`
487                 {
488                         (getent passwd $authors) ||
489                         (
490                                 cat /etc/passwd
491                                 for author in $authors
492                                 do NIS_PATH= nismatch $author passwd.org_dir
493                                 done
494                                 ypmatch $authors passwd
495                         )
496                 } 2>/dev/null |
497                 $AWK -F: "$awkscript"
498         `$initialize_fullname;;
499 esac
500
501
502 # Function to print a single log line.
503 # We don't use awk functions, to stay compatible with old awk versions.
504 # `Log' is the log message.
505 # `files' contains the affected files.
506 printlogline='{
507
508         # Following the GNU coding standards, rewrite
509         #       * file: (function): comment
510         # to
511         #       * file (function): comment
512         if (Log ~ /^\([^)]*\): /) {
513                 i = index(Log, ")")
514                 filefunc = substr(Log, 1, i)
515                 while ((j = index(filefunc, "\n"))) {
516                         files = files " " substr(filefunc, 1, j-1)
517                         filefunc = substr(filefunc, j+1)
518                 }
519                 files = files " " filefunc
520                 Log = substr(Log, i+3)
521         }
522
523         # If "label: comment" is too long, break the line after the ":".
524         sep = " "
525         i = index(Log, "\n")
526         if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
527
528         # Print the label.
529         printf "%s*%s:", indent_string, files
530
531         # Print each line of the log.
532         while (i) {
533                 logline = substr(Log, 1, i-1)
534                 if (logline ~ /[^'"$tab"' ]/) {
535                         printf "%s%s\n", sep, logline
536                 } else {
537                         print ""
538                 }
539                 sep = indent_string
540                 Log = substr(Log, i+1)
541                 i = index(Log, "\n")
542         }
543 }'
544
545 # Pattern to match the `revision' line of rlog output.
546 rlog_revision_pattern='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
547
548 case $hostname in
549 '')
550         hostname=`(
551                 hostname || uname -n || uuname -l || cat /etc/whoami
552         ) 2>/dev/null` || {
553                 echo >&2 "$0: cannot deduce hostname"
554                 exit 1
555         }
556
557         case $hostname in
558         *.*) ;;
559         *)
560                 domainname=`(domainname) 2>/dev/null` &&
561                 case $domainname in
562                 *.*) hostname=$hostname.$domainname;;
563                 esac;;
564         esac;;
565 esac
566
567
568 # Process the rlog output, generating ChangeLog style entries.
569
570 # First, reformat the rlog output so that each line contains one log entry.
571 # Transliterate \n to SOH so that multiline entries fit on a single line.
572 # Discard irrelevant rlog output.
573 $AWK '
574         BEGIN {
575                 pository = "'"$pository"'"
576                 SOH="'"$SOH"'"
577         }
578         /^RCS file: / {
579                 if (pository != "") {
580                         filename = substr($0, 11)
581                         if (substr(filename, 1, length(pository)) == pository) {
582                                 filename = substr(filename, length(pository) + 1)
583                         }
584                         if (filename ~ /,v$/) {
585                                 filename = substr(filename, 1, length(filename) - 2)
586                         }
587                         if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
588                                 i = length(filename)
589                                 while (substr(filename, i, 1) != "/") i--
590                                 filename = substr(filename, 1, i - 6) substr(filename, i + 1)
591                         }
592                 }
593                 rev = "?"
594         }
595         /^Working file: / { if (repository == "") filename = substr($0, 15) }
596         /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
597                 line = $0
598                 if (line ~ /'"$rlog_revision_pattern"'/) {
599                         rev = $2
600                         next
601                 }
602                 if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
603                         date = $2
604                         if (date ~ /\//) {
605                                 # This is a traditional RCS format date YYYY/MM/DD.
606                                 # Replace "/"s with "-"s to get ISO format.
607                                 newdate = ""
608                                 while ((i = index(date, "/")) != 0) {
609                                         newdate = newdate substr(date, 1, i-1) "-"
610                                         date = substr(date, i+1)
611                                 }
612                                 date = newdate date
613                         }
614                         time = substr($3, 1, length($3) - 1)
615                         author = substr($5, 1, length($5)-1)
616                         printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
617                         rev = "?"
618                         next
619                 }
620                 if (line ~ /^branches: /) { next }
621                 if (line ~ /^(-----------*|===========*)$/) { print ""; next }
622                 if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
623                         line = "New file."
624                 }
625                 printf "%s%s", line, SOH
626         }
627 ' <"$rlogfile" |
628
629 # Now each line is of the form
630 # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
631 #       where @ stands for an SOH (octal code 001),
632 #       and each line of LOG is terminated by SOH instead of \n.
633 # Sort the log entries, first by date+time (in reverse order),
634 # then by author, then by log entry, and finally by file name and revision
635 # (just in case).
636 sort -t"$SOH" -k 3,4r -k 5 -k 1 |
637
638 # Finally, reformat the sorted log entries.
639 $AWK -F"$SOH" '
640         BEGIN {
641                 logTZ = "'"$logTZ"'"
642                 revision = "'"$revision"'"
643
644                 # Initialize the fullname and mailaddr associative arrays.
645                 '"$initialize_fullname"'
646                 '"$initialize_mailaddr"'
647
648                 # Initialize indent string.
649                 indent_string = ""
650                 i = '"$indent"'
651                 if (0 < '"$tabwidth"')
652                         for (;  '"$tabwidth"' <= i;  i -= '"$tabwidth"')
653                                 indent_string = indent_string "\t"
654                 while (1 <= i--)
655                         indent_string = indent_string " "
656         }
657
658         {
659                 newlog = ""
660                 for (i = 6; i < NF; i++) newlog = newlog $i "\n"
661
662                 # Ignore log entries prefixed by "#".
663                 if (newlog ~ /^#/) { next }
664
665                 if (Log != newlog || date != $3 || author != $5) {
666
667                         # The previous log and this log differ.
668
669                         # Print the old log.
670                         if (date != "") '"$printlogline"'
671
672                         # Logs that begin with "{clumpname} " should be grouped together,
673                         # and the clumpname should be removed.
674                         # Extract the new clumpname from the log header,
675                         # and use it to decide whether to output a blank line.
676                         newclumpname = ""
677                         sep = "\n"
678                         if (date == "") sep = ""
679                         if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
680                                 i = index(newlog, "}")
681                                 newclumpname = substr(newlog, 1, i)
682                                 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
683                                 newlog = substr(newlog, i+1)
684                                 if (clumpname == newclumpname) sep = ""
685                         }
686                         printf sep
687                         clumpname = newclumpname
688
689                         # Get ready for the next log.
690                         Log = newlog
691                         if (files != "")
692                                 for (i in filesknown)
693                                         filesknown[i] = 0
694                         files = ""
695                 }
696                 if (date != $3  ||  author != $5) {
697                         # The previous date+author and this date+author differ.
698                         # Print the new one.
699                         date = $3
700                         time = $4
701                         author = $5
702
703                         zone = ""
704                         if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
705                                 zone = " " substr(time, i)
706
707                         # Print "date[ timezone]  fullname  <email address>".
708                         # Get fullname and email address from associative arrays;
709                         # default to author and author@hostname if not in arrays.
710                         if (fullname[author])
711                                 auth = fullname[author]
712                         else
713                                 auth = author
714                         printf "%s%s  %s  ", date, zone, auth
715                         if (mailaddr[author])
716                                 printf "<%s>\n\n", mailaddr[author]
717                         else
718                                 printf "<%s@%s>\n\n", author, "'"$hostname"'"
719                 }
720                 if (! filesknown[$1]) {
721                         filesknown[$1] = 1
722                         if (files == "") files = " " $1
723                         else files = files ", " $1
724                         if (revision && $2 != "?") files = files " " $2
725                 }
726         }
727         END {
728                 # Print the last log.
729                 if (date != "") {
730                         '"$printlogline"'
731                         printf "\n"
732                 }
733         }
734 ' &&
735
736
737 # Exit successfully.
738
739 exec rm -fr $logdir
740
741 # Local Variables:
742 # tab-width:4
743 # End: