3 # RCS to ChangeLog generator
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.
10 # Ignore log entries that start with `#'.
11 # Clump together log entries that start with `{topic} ',
12 # where `topic' contains neither white space nor `}'.
14 Help='The default FILEs are the files registered under the working directory.
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).
21 -L FILE Use rlog-format FILE for source of logs.
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.
28 --version Output version number.
30 Report bugs to <bug-gnu-emacs@gnu.org>.'
32 Id='$Id: rcs2log,v 1.48 2001/09/05 23:07:46 eggert Exp $'
34 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2003
35 # Free Software Foundation, Inc.
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)
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.
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.
52 Copyright='Copyright 1992-2003 Free Software Foundation, Inc.
53 This program comes with NO WARRANTY, to the extent permitted by law.
54 You may redistribute copies of this program
55 under the terms of the GNU General Public License.
56 For more information about these matters, see the files named COPYING.
57 Author: Paul Eggert <eggert@twinsun.com>'
62 # Use the traditional C locale.
71 export LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME
73 # These variables each contain a single ASCII character.
74 # Unfortunately, there's no portable way of writing these characters
75 # in older Unix implementations, other than putting them directly into
77 SOH='
\ 1' # SOH, octal code 001
85 : ${MKTEMP="@MKTEMP@"}
89 changelog=ChangeLog # change log file name
90 datearg= # rlog date option
91 hostname= # name of local host (if empty, will deduce it later)
92 indent=8 # indent of log line
93 length=79 # suggested max width of log line
94 logins= # login names for people we know fullnames and mailaddrs of
95 loginFullnameMailaddrs= # login<tab>fullname<tab>mailaddr triplets
96 logTZ= # time zone for log dates (if empty, use local time)
97 recursive= # t if we want recursive rlog
98 revision= # t if we want revision numbers
99 rlog_options= # options to pass to rlog
100 rlogfile= # log file to read from
101 tabwidth=8 # width of horizontal tab
106 -c) changelog=${2?}; shift;;
107 -i) indent=${2?}; shift;;
108 -h) hostname=${2?}; shift;;
109 -l) length=${2?}; shift;;
110 -L) rlogfile=${2?}; shift;;
111 -[nu]) # -n is obsolescent; it is replaced by -u.
113 -n) case ${2?}${3?}${4?} in
115 echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
120 shift; shift; shift;;
122 # If $2 is not tab-separated, use colon for separator.
125 echo >&2 "$0: -u '$2': newlines not allowed"
134 echo >&2 "$0: -u '$2': too many fields"
137 uf="[^$t]*$t" # An unselected field, followed by a separator.
138 sf="\\([^$t]*\\)" # The selected field.
139 login=`expr "X$2" : "X$sf"`
141 expr "X$2" : "$uf$sf"
143 expr "X$2" : "$uf$uf$sf"
146 echo >&2 "$0: -u '$2': not enough fields"
153 ?*) logins=$logins$nl$login;;
155 case $loginFullnameMailaddrs in
156 '') loginFullnameMailaddrs=$lfm;;
157 ?*) loginFullnameMailaddrs=$loginFullnameMailaddrs$nl$lfm;;
160 case $rlog_options in
161 '') rlog_options=${2?};;
162 ?*) rlog_options=$rlog_options$nl${2?};;
166 -t) tabwidth=${2?}; shift;;
171 echo >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
173 -*) echo >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
184 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
185 m[3]="Apr"; m[4]="May"; m[5]="Jun"
186 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
187 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
190 logdir=`$MKTEMP -d $TMPDIR/rcs2log.XXXXXX`
191 test -n "$logdir" || exit
194 trap "rm -fr $logdir 2>/dev/null" 0
196 # If no rlog-format log file is given, generate one into $rlogfile.
201 # If no rlog options are given,
202 # log the revisions checked in since the first ChangeLog entry.
203 # Since ChangeLog is only by date, some of these revisions may be duplicates of
204 # what's already in ChangeLog; it's the user's responsibility to remove them.
205 case $rlog_options in
207 if test -s "$changelog"
210 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
215 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
216 # old-fashioned date and time (Emacs 19.31 and earlier)
219 for (i=0; i<=11; i++) if (m[i] == $2) break
221 printf "%d-%02d-%02d\n", year, i+1, dd
225 d=`$AWK "$e" <"$changelog"` || exit
227 ?*) datearg="-d>$d";;
232 # Use TZ specified by ChangeLog local variable, if any.
233 if test -s "$changelog"
236 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
239 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
243 logTZ=`tail "$changelog" | sed -n "$extractTZ"`
245 ?*) TZ=$logTZ; export TZ;;
249 # If CVS is in use, examine its repository, not the normal RCS files.
250 if test ! -f CVS/Repository
256 repository=`sed 1q <CVS/Repository` || exit
257 test ! -f CVS/Root || CVSROOT=`cat <CVS/Root` || exit
260 echo >&2 "$0: $CVSROOT: CVSROOT has multiple ':/'s"
264 pository=`expr "X$repository" : '.*:\(/.*\)'`;;
269 *) repository=${CVSROOT?}/$repository;;
271 if test ! -d "$repository"
273 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
276 pository=$repository;;
279 # Ensure that $pository ends in exactly one slash.
283 *//) pository=`expr "X$pository" : 'X\(.*\)/'`;;
285 *) pository=$pository/; break;;
291 # Use $rlog's -zLT option, if $rlog supports it.
292 case `$rlog -zLT 2>&1` in
295 case $rlog_options in
296 '') rlog_options=-zLT;;
297 ?*) rlog_options=-zLT$nl$rlog_options;;
301 # With no arguments, examine all files under the RCS directory.
310 RCSdirs=`find . -name RCS -type d -print`
311 filesFromRCSfiles='s|,v$||; s|/RCS/|/|; s|^\./||'
320 ! -name .rcsfreeze.log \
321 ! -name .rcsfreeze.ver \
324 find . -name '*,v' -print
327 sed "$filesFromRCSfiles"
331 for file in RCS/.* RCS/* .*,v *,v
334 RCS/. | RCS/.. | RCS/,*, | RCS/*_) continue;;
335 RCS/.rcsfreeze.log | RCS/.rcsfreeze.ver) continue;;
336 RCS/.\* | RCS/\* | .\*,v | \*,v) test -f "$file" || continue;;
337 RCS/*,v | RCS/.*,v) ;;
338 RCS/* | RCS/.*) test -f "$file" || continue;;
342 ?*) files=$files$nl$file;;
356 ?*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogfile;;
357 '') $rlog $rlog_options ${1+"$@"} >$rlogfile;;
362 # Get the full name of each author the logs mention, and set initialize_fullname
363 # to awk code that initializes the `fullname' awk associative array.
364 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
365 # you have to fix the resulting output by hand.
370 case $loginFullnameMailaddrs in
372 case $loginFullnameMailaddrs in
374 sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
375 $loginFullnameMailaddrs
377 loginFullnameMailaddrs=`cat $llogout`;;
382 for loginFullnameMailaddr in $loginFullnameMailaddrs
385 set x $loginFullnameMailaddr
389 initialize_fullname="$initialize_fullname
390 fullname[\"$login\"] = \"$fullname\""
391 initialize_mailaddr="$initialize_mailaddr
392 mailaddr[\"$login\"] = \"$mailaddr\""
399 sort -u -o $llogout <<EOF
405 esac >$llogout || exit
407 output_authors='/^date: / {
408 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 ~ /^[^;]*;$/) {
409 print substr($5, 1, length($5)-1)
413 $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - $llogout
417 cat >$llogout <<EOF || exit
420 initialize_author_script='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
421 initialize_author=`sed -e "$initialize_author_script" <$llogout`
424 alphabet = "abcdefghijklmnopqrstuvwxyz"
425 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
426 '"$initialize_author"'
431 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
432 # Remove the junk from fullnames like "0000-Admin(0000)".
433 fullname = substr(fullname, index(fullname, "-") + 1)
434 fullname = substr(fullname, 1, index(fullname, "(") - 1)
436 if (fullname ~ /,[^ ]/) {
437 # Some sites put comma-separated junk after the fullname.
438 # Remove it, but leave "Bill Gates, Jr" alone.
439 fullname = substr(fullname, 1, index(fullname, ",") - 1)
441 abbr = index(fullname, "&")
445 i = index(alphabet, a)
446 if (i) A = substr(ALPHABET, i, 1)
447 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
450 # Quote quotes and backslashes properly in full names.
451 # Do not use gsub; traditional awk lacks it.
455 p = index(rest, "\\")
456 q = index(rest, "\"")
463 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
464 rest = substr(rest, p+1)
467 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
473 initialize_fullname=`
475 (getent passwd $authors) ||
478 for author in $authors
479 do NIS_PATH= nismatch $author passwd.org_dir
481 ypmatch $authors passwd
484 $AWK -F: "$awkscript"
485 `$initialize_fullname;;
489 # Function to print a single log line.
490 # We don't use awk functions, to stay compatible with old awk versions.
491 # `Log' is the log message.
492 # `files' contains the affected files.
495 # Following the GNU coding standards, rewrite
496 # * file: (function): comment
498 # * file (function): comment
499 if (Log ~ /^\([^)]*\): /) {
501 filefunc = substr(Log, 1, i)
502 while ((j = index(filefunc, "\n"))) {
503 files = files " " substr(filefunc, 1, j-1)
504 filefunc = substr(filefunc, j+1)
506 files = files " " filefunc
507 Log = substr(Log, i+3)
510 # If "label: comment" is too long, break the line after the ":".
513 if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
516 printf "%s*%s:", indent_string, files
518 # Print each line of the log.
520 logline = substr(Log, 1, i-1)
521 if (logline ~ /[^'"$tab"' ]/) {
522 printf "%s%s\n", sep, logline
527 Log = substr(Log, i+1)
532 # Pattern to match the `revision' line of rlog output.
533 rlog_revision_pattern='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
538 hostname || uname -n || uuname -l || cat /etc/whoami
540 echo >&2 "$0: cannot deduce hostname"
547 domainname=`(domainname) 2>/dev/null` &&
549 *.*) hostname=$hostname.$domainname;;
555 # Process the rlog output, generating ChangeLog style entries.
557 # First, reformat the rlog output so that each line contains one log entry.
558 # Transliterate \n to SOH so that multiline entries fit on a single line.
559 # Discard irrelevant rlog output.
562 pository = "'"$pository"'"
566 if (pository != "") {
567 filename = substr($0, 11)
568 if (substr(filename, 1, length(pository)) == pository) {
569 filename = substr(filename, length(pository) + 1)
571 if (filename ~ /,v$/) {
572 filename = substr(filename, 1, length(filename) - 2)
574 if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
576 while (substr(filename, i, 1) != "/") i--
577 filename = substr(filename, 1, i - 6) substr(filename, i + 1)
582 /^Working file: / { if (repository == "") filename = substr($0, 15) }
583 /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
585 if (line ~ /'"$rlog_revision_pattern"'/) {
589 if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
592 # This is a traditional RCS format date YYYY/MM/DD.
593 # Replace "/"s with "-"s to get ISO format.
595 while ((i = index(date, "/")) != 0) {
596 newdate = newdate substr(date, 1, i-1) "-"
597 date = substr(date, i+1)
601 time = substr($3, 1, length($3) - 1)
602 author = substr($5, 1, length($5)-1)
603 printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
607 if (line ~ /^branches: /) { next }
608 if (line ~ /^(-----------*|===========*)$/) { print ""; next }
609 if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
612 printf "%s%s", line, SOH
616 # Now each line is of the form
617 # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
618 # where @ stands for an SOH (octal code 001),
619 # and each line of LOG is terminated by SOH instead of \n.
620 # Sort the log entries, first by date+time (in reverse order),
621 # then by author, then by log entry, and finally by file name and revision
623 sort -t"$SOH" +2 -4r +4 +0 |
625 # Finally, reformat the sorted log entries.
629 revision = "'"$revision"'"
631 # Initialize the fullname and mailaddr associative arrays.
632 '"$initialize_fullname"'
633 '"$initialize_mailaddr"'
635 # Initialize indent string.
638 if (0 < '"$tabwidth"')
639 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
640 indent_string = indent_string "\t"
642 indent_string = indent_string " "
647 for (i = 6; i < NF; i++) newlog = newlog $i "\n"
649 # Ignore log entries prefixed by "#".
650 if (newlog ~ /^#/) { next }
652 if (Log != newlog || date != $3 || author != $5) {
654 # The previous log and this log differ.
657 if (date != "") '"$printlogline"'
659 # Logs that begin with "{clumpname} " should be grouped together,
660 # and the clumpname should be removed.
661 # Extract the new clumpname from the log header,
662 # and use it to decide whether to output a blank line.
665 if (date == "") sep = ""
666 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
667 i = index(newlog, "}")
668 newclumpname = substr(newlog, 1, i)
669 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
670 newlog = substr(newlog, i+1)
671 if (clumpname == newclumpname) sep = ""
674 clumpname = newclumpname
676 # Get ready for the next log.
679 for (i in filesknown)
683 if (date != $3 || author != $5) {
684 # The previous date+author and this date+author differ.
691 if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
692 zone = " " substr(time, i)
694 # Print "date[ timezone] fullname <email address>".
695 # Get fullname and email address from associative arrays;
696 # default to author and author@hostname if not in arrays.
697 if (fullname[author])
698 auth = fullname[author]
701 printf "%s%s %s ", date, zone, auth
702 if (mailaddr[author])
703 printf "<%s>\n\n", mailaddr[author]
705 printf "<%s@%s>\n\n", author, "'"$hostname"'"
707 if (! filesknown[$1]) {
709 if (files == "") files = " " $1
710 else files = files ", " $1
711 if (revision && $2 != "?") files = files " " $2
715 # Print the last log.