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