3 # RCS to ChangeLog generator
6 Generate ChangeLog entries from RCS files (perhaps in a CVS repository)
7 and the ChangeLog file (if any). An RCS file typically has a name
8 ending in ",v", and represents the entire history of a file that is
9 under revision control. The ChangeLog file logs entries for changes,
10 in reverse chronological order.
12 Generate entries for changes entered into RCS (or CVS) more recently
13 than the newest existing entry in the ChangeLog file. You can then
14 edit these entries by hand, and prepend them to the ChangeLog file.
16 Output the resulting ChangeLog entries to standard output.
17 Each entry looks something like this:
19 2004-04-17 Paul Eggert <eggert@gnu.org>
21 * rcs2log (Help): Clarify wording of the usage message.
22 Problem reported by Alan Mackenzie in
23 <http://mail.gnu.org/archive/html/bug-gnu-emacs/2004-04/msg00188.html>.
25 ChangeLog entries contain the current date, full name, email address
26 including hostname, the name of the affected file, and commentary.
27 RCS and CVS logs lack full names and email addresses, so they are
28 inferred from login names using a heuristic that can be overridden
31 Ignore log entries that start with "#".
32 Clump together log entries that start with "{topic} ",
33 where "topic" contains neither white space nor "}".
35 If no FILE is specified, use all files under the working directory
36 that are maintained under version control.
40 -c FILE Output ChangeLog entries for FILE (default ChangeLog).
41 -h HOSTNAME Use HOSTNAME in change log entries (default current host).
42 -i INDENT Indent change log lines by INDENT spaces (default 8).
43 -l LENGTH Try to limit log lines to LENGTH characters (default 79).
44 -L FILE Use FILE (same format as "rlog") for source of logs.
45 -R If no FILEs are given and RCS is used, recurse through working directory.
46 -r OPTION Pass OPTION to subsidiary command (either "rlog" or "cvs -q log").
47 -t TABWIDTH Tab stops are every TABWIDTH characters (default 8).
48 -u "LOGIN<tab>FULLNAME<tab>EMAILADDR" LOGIN has FULLNAME and EMAILADDR.
49 -v Append RCS revision to file names in log lines.
51 --version Output version number.
53 Report bugs to <bug-gnu-emacs@gnu.org>.'
57 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002, 2003,
58 # 2004 Free Software Foundation, Inc.
60 # This program is free software; you can redistribute it and/or modify
61 # it under the terms of the GNU General Public License as published by
62 # the Free Software Foundation; either version 2, or (at your option)
65 # This program is distributed in the hope that it will be useful,
66 # but WITHOUT ANY WARRANTY; without even the implied warranty of
67 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 # GNU General Public License for more details.
70 # You should have received a copy of the GNU General Public License
71 # along with this program; see the file COPYING. If not, write to the
72 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
73 # Boston, MA 02110-1301, USA.
75 Copyright
='Copyright (C) 2004 Free Software Foundation, Inc.
76 This program comes with NO WARRANTY, to the extent permitted by law.
77 You may redistribute copies of this program
78 under the terms of the GNU General Public License.
79 For more information about these matters, see the files named COPYING.
80 Author: Paul Eggert <eggert@twinsun.com>'
82 # Use the traditional C locale.
91 export LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME
93 # These variables each contain a single ASCII character.
94 # Unfortunately, there's no portable way of writing these characters
95 # in older Unix implementations, other than putting them directly into
97 SOH
='\x01' # SOH, octal code 001
106 TMPDIR
=${TMPDIR-/tmp}
107 changelog
=ChangeLog
# change log file name
108 datearg
= # rlog date option
109 hostname
= # name of local host (if empty, will deduce it later)
110 indent
=8 # indent of log line
111 length
=79 # suggested max width of log line
112 logins
= # login names for people we know fullnames and mailaddrs of
113 loginFullnameMailaddrs
= # login<tab>fullname<tab>mailaddr triplets
114 logTZ
= # time zone for log dates (if empty, use local time)
115 recursive
= # t if we want recursive rlog
116 revision
= # t if we want revision numbers
117 rlog_options
= # options to pass to rlog
118 rlogfile
= # log file to read from
119 tabwidth
=8 # width of horizontal tab
124 -c) changelog
=${2?}; shift;;
125 -i) indent
=${2?}; shift;;
126 -h) hostname
=${2?}; shift;;
127 -l) length
=${2?}; shift;;
128 -L) rlogfile
=${2?}; shift;;
129 -[nu
]) # -n is obsolescent; it is replaced by -u.
131 -n) case ${2?}${3?}${4?} in
133 echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
138 shift; shift; shift;;
140 # If $2 is not tab-separated, use colon for separator.
143 echo >&2 "$0: -u '$2': newlines not allowed"
152 echo >&2 "$0: -u '$2': too many fields"
155 uf
="[^$t]*$t" # An unselected field, followed by a separator.
156 sf
="\\([^$t]*\\)" # The selected field.
157 login
=`expr "X$2" : "X$sf"`
159 expr "X$2" : "$uf$sf"
161 expr "X$2" : "$uf$uf$sf"
164 echo >&2 "$0: -u '$2': not enough fields"
171 ?
*) logins
=$logins$nl$login;;
173 case $loginFullnameMailaddrs in
174 '') loginFullnameMailaddrs
=$lfm;;
175 ?
*) loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$lfm;;
178 case $rlog_options in
179 '') rlog_options
=${2?};;
180 ?
*) rlog_options
=$rlog_options$nl${2?};;
184 -t) tabwidth
=${2?}; shift;;
189 echo >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
191 -*) echo >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
202 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
203 m[3]="Apr"; m[4]="May"; m[5]="Jun"
204 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
205 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
208 logdir
=$TMPDIR/rcs2log$$
211 trap "rm -fr $logdir 2>/dev/null" 0
212 (umask 077 && exec mkdir
$logdir) ||
exit
214 # If no rlog-format log file is given, generate one into $rlogfile.
219 # If no rlog options are given,
220 # log the revisions checked in since the first ChangeLog entry.
221 # Since ChangeLog is only by date, some of these revisions may be
222 # duplicates of what's already in ChangeLog; it's the user's
223 # responsibility to remove them.
224 case $rlog_options in
226 if test -s "$changelog"
229 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
234 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
235 # old-fashioned date and time (Emacs 19.31 and earlier)
238 for (i=0; i<=11; i++) if (m[i] == $2) break
240 printf "%d-%02d-%02d\n", year, i+1, dd
244 d
=`$AWK "$e" <"$changelog"` ||
exit
246 ?
*) datearg
="-d>$d";;
251 # Use TZ specified by ChangeLog local variable, if any.
252 if test -s "$changelog"
255 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
258 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
262 logTZ
=`tail "$changelog" | sed -n "$extractTZ"`
264 ?
*) TZ
=$logTZ; export TZ
;;
268 # If CVS is in use, examine its repository, not the normal RCS files.
269 if test ! -f CVS
/Repository
275 repository
=`sed 1q <CVS/Repository` ||
exit
276 test ! -f CVS
/Root || CVSROOT
=`cat <CVS/Root` ||
exit
279 /* |
:fork
:* |
:local:*) ;;
282 pository
=`expr "X$CVSROOT" : '[^/]*\(.*\)'`;;
290 repository
=${CVSROOT?}/$repository
293 repository
=`expr "$repository" : ':[^:]*:\(.*\)'`;;
296 if test ! -d "$repository"
298 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
301 pository
=$repository;;
304 # Ensure that $pository ends in exactly one slash.
308 *//) pository
=`expr "X$pository" : 'X\(.*\)/'`;;
310 *) pository
=$pository/; break;;
314 # If no rlog options are given, and if we are in a tagged CVS branch,
315 # log only the changes in that branch.
316 case $rlog_options in
320 CVSTAG
=`cat <CVS/Tag` ||
exit
323 rlog_options
=-r`expr "$CVSTAG" : 'T\(.*\)'`;;
325 echo >&2 "$0: invalid CVS/Tag"; exit 1;;
331 # Use $rlog's -zLT option, if $rlog supports it.
332 case `$rlog -zLT 2>&1` in
335 case $rlog_options in
336 '') rlog_options
=-zLT;;
337 ?
*) rlog_options
=-zLT$nl$rlog_options;;
341 # With no arguments, examine all files under the RCS directory.
350 RCSdirs
=`find . -name RCS -type d -print`
351 filesFromRCSfiles
='s|,v$||; s|/RCS/|/|; s|^\./||'
360 ! -name .rcsfreeze.log \
361 ! -name .rcsfreeze.ver \
364 find . -name '*,v' -print
367 sed "$filesFromRCSfiles"
371 for file in RCS
/.
* RCS
/* .
*,v
*,v
374 RCS
/. | RCS
/.. | RCS
/,*, | RCS
/*_
) continue;;
375 RCS
/.rcsfreeze.log | RCS
/.rcsfreeze.ver
) continue;;
376 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue;;
377 RCS
/*,v | RCS
/.
*,v
) ;;
378 RCS
/* | RCS
/.
*) test -f "$file" ||
continue;;
382 ?
*) files
=$files$nl$file;;
396 ?
*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogfile;;
397 '') $rlog $rlog_options ${1+"$@"} >$rlogfile;;
402 # Prefer the POSIX-style -k options, since POSIX 1003.1-2001 prohibits
403 # support for the traditional-style +M -N options.
404 SORT_K_OPTIONS
='-k 3,4r -k 5 -k 1'
405 sort $SORT_K_OPTIONS </dev
/null
2>/dev
/null || SORT_K_OPTIONS
='+2 -4r +4 +0'
408 # Get the full name of each author the logs mention, and set initialize_fullname
409 # to awk code that initializes the `fullname' awk associative array.
410 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
411 # you have to fix the resulting output by hand.
416 case $loginFullnameMailaddrs in
418 case $loginFullnameMailaddrs in
420 sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
421 $loginFullnameMailaddrs
423 loginFullnameMailaddrs
=`cat $llogout`;;
428 for loginFullnameMailaddr
in $loginFullnameMailaddrs
431 set x
$loginFullnameMailaddr
435 initialize_fullname
="$initialize_fullname
436 fullname[\"$login\"] = \"$fullname\""
437 initialize_mailaddr
="$initialize_mailaddr
438 mailaddr[\"$login\"] = \"$mailaddr\""
445 sort -u -o $llogout <<EOF
451 esac >$llogout ||
exit
453 output_authors
='/^date: / {
454 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 ~ /^[^;]*;$/) {
455 print substr($5, 1, length($5)-1)
459 $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - $llogout
463 cat >$llogout <<EOF || exit
466 initialize_author_script
='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
467 initialize_author
=`sed -e "$initialize_author_script" <$llogout`
470 alphabet = "abcdefghijklmnopqrstuvwxyz"
471 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
472 '"$initialize_author"'
477 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
478 # Remove the junk from fullnames like "0000-Admin(0000)".
479 fullname = substr(fullname, index(fullname, "-") + 1)
480 fullname = substr(fullname, 1, index(fullname, "(") - 1)
482 if (fullname ~ /,[^ ]/) {
483 # Some sites put comma-separated junk after the fullname.
484 # Remove it, but leave "Bill Gates, Jr" alone.
485 fullname = substr(fullname, 1, index(fullname, ",") - 1)
487 abbr = index(fullname, "&")
491 i = index(alphabet, a)
492 if (i) A = substr(ALPHABET, i, 1)
493 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
496 # Quote quotes and backslashes properly in full names.
497 # Do not use gsub; traditional awk lacks it.
501 p = index(rest, "\\")
502 q = index(rest, "\"")
509 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
510 rest = substr(rest, p+1)
513 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
519 initialize_fullname
=`
521 (getent passwd $authors) ||
524 for author in $authors
525 do NIS_PATH= nismatch $author passwd.org_dir
527 ypmatch $authors passwd
530 $AWK -F: "$awkscript"
531 `$initialize_fullname;;
535 # Function to print a single log line.
536 # We don't use awk functions, to stay compatible with old awk versions.
537 # `Log' is the log message.
538 # `files' contains the affected files.
541 # Following the GNU coding standards, rewrite
542 # * file: (function): comment
544 # * file (function): comment
545 if (Log ~ /^\([^)]*\):[\t\n ]/) {
547 filefunc = substr(Log, 1, i)
548 while ((j = index(filefunc, "\n"))) {
549 files = files " " substr(filefunc, 1, j-1)
550 filefunc = substr(filefunc, j+1)
552 files = files " " filefunc
553 Log = substr(Log, i+3)
556 # If "label: comment" is too long, break the line after the ":".
559 if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
562 printf "%s*%s:", indent_string, files
564 # Print each line of the log.
566 logline = substr(Log, 1, i-1)
567 if (logline ~ /[^'"$tab"' ]/) {
568 printf "%s%s\n", sep, logline
573 Log = substr(Log, i+1)
578 # Pattern to match the `revision' line of rlog output.
579 rlog_revision_pattern
='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
584 hostname || uname -n || uuname -l || cat /etc/whoami
586 echo >&2 "$0: cannot deduce hostname"
593 domainname
=`(domainname) 2>/dev/null` &&
595 *.
*) hostname
=$hostname.
$domainname;;
601 # Process the rlog output, generating ChangeLog style entries.
603 # First, reformat the rlog output so that each line contains one log entry.
604 # Transliterate \n to SOH so that multiline entries fit on a single line.
605 # Discard irrelevant rlog output.
608 pository = "'"$pository"'"
612 if (pository != "") {
613 filename = substr($0, 11)
614 if (substr(filename, 1, length(pository)) == pository) {
615 filename = substr(filename, length(pository) + 1)
617 if (filename ~ /,v$/) {
618 filename = substr(filename, 1, length(filename) - 2)
620 if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
622 while (substr(filename, i, 1) != "/") i--
623 filename = substr(filename, 1, i - 6) substr(filename, i + 1)
628 /^Working file: / { if (repository == "") filename = substr($0, 15) }
629 /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
631 if (line ~ /'"$rlog_revision_pattern"'/) {
635 if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
638 # This is a traditional RCS format date YYYY/MM/DD.
639 # Replace "/"s with "-"s to get ISO format.
641 while ((i = index(date, "/")) != 0) {
642 newdate = newdate substr(date, 1, i-1) "-"
643 date = substr(date, i+1)
647 time = substr($3, 1, length($3) - 1)
648 author = substr($5, 1, length($5)-1)
649 printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
653 if (line ~ /^branches: /) { next }
654 if (line ~ /^(-----------*|===========*)$/) { print ""; next }
655 if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
658 printf "%s%s", line, SOH
662 # Now each line is of the form
663 # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
664 # where @ stands for an SOH (octal code 001),
665 # and each line of LOG is terminated by SOH instead of \n.
666 # Sort the log entries, first by date+time (in reverse order),
667 # then by author, then by log entry, and finally by file name and revision
669 sort -t"$SOH" $SORT_K_OPTIONS |
671 # Finally, reformat the sorted log entries.
675 revision = "'"$revision"'"
677 # Initialize the fullname and mailaddr associative arrays.
678 '"$initialize_fullname"'
679 '"$initialize_mailaddr"'
681 # Initialize indent string.
684 if (0 < '"$tabwidth"')
685 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
686 indent_string = indent_string "\t"
688 indent_string = indent_string " "
693 for (i = 6; i < NF; i++) newlog = newlog $i "\n"
695 # Ignore log entries prefixed by "#".
696 if (newlog ~ /^#/) { next }
698 if (Log != newlog || date != $3 || author != $5) {
700 # The previous log and this log differ.
703 if (date != "") '"$printlogline"'
705 # Logs that begin with "{clumpname} " should be grouped together,
706 # and the clumpname should be removed.
707 # Extract the new clumpname from the log header,
708 # and use it to decide whether to output a blank line.
711 if (date == "") sep = ""
712 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
713 i = index(newlog, "}")
714 newclumpname = substr(newlog, 1, i)
715 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
716 newlog = substr(newlog, i+1)
717 if (clumpname == newclumpname && date == $3 && author == $5) sep = ""
720 clumpname = newclumpname
722 # Get ready for the next log.
725 for (i in filesknown)
729 if (date != $3 || author != $5) {
730 # The previous date+author and this date+author differ.
737 if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
738 zone = " " substr(time, i)
740 # Print "date[ timezone] fullname <email address>".
741 # Get fullname and email address from associative arrays;
742 # default to author and author@hostname if not in arrays.
743 if (fullname[author])
744 auth = fullname[author]
747 printf "%s%s %s ", date, zone, auth
748 if (mailaddr[author])
749 printf "<%s>\n\n", mailaddr[author]
751 printf "<%s@%s>\n\n", author, "'"$hostname"'"
753 if (! filesknown[$1]) {
755 if (files == "") files = " " $1
756 else files = files ", " $1
757 if (revision && $2 != "?") files = files " " $2
761 # Print the last log.
778 # arch-tag: cea067bd-a552-4254-ba17-078208933073