3 # RCS to ChangeLog generator
5 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002, 2003,
6 # 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 Copyright
='Copyright (C) 2008 Free Software Foundation, Inc.
23 This program comes with NO WARRANTY, to the extent permitted by law.
24 You may redistribute copies of this program
25 under the terms of the GNU General Public License.
26 For more information about these matters, see the files named COPYING.
27 Author: Paul Eggert <eggert@twinsun.com>'
30 Generate ChangeLog entries from RCS files (perhaps in a CVS repository)
31 and the ChangeLog file (if any). An RCS file typically has a name
32 ending in ",v", and represents the entire history of a file that is
33 under revision control. The ChangeLog file logs entries for changes,
34 in reverse chronological order.
36 Generate entries for changes entered into RCS (or CVS) more recently
37 than the newest existing entry in the ChangeLog file. You can then
38 edit these entries by hand, and prepend them to the ChangeLog file.
40 Output the resulting ChangeLog entries to standard output.
41 Each entry looks something like this:
43 2004-04-17 Paul Eggert <eggert@gnu.org>
45 * rcs2log (Help): Clarify wording of the usage message.
46 Problem reported by Alan Mackenzie in
47 <http://mail.gnu.org/archive/html/bug-gnu-emacs/2004-04/msg00188.html>.
49 ChangeLog entries contain the current date, full name, email address
50 including hostname, the name of the affected file, and commentary.
51 RCS and CVS logs lack full names and email addresses, so they are
52 inferred from login names using a heuristic that can be overridden
55 Ignore log entries that start with "#".
56 Clump together log entries that start with "{topic} ",
57 where "topic" contains neither white space nor "}".
59 If no FILE is specified, use all files under the working directory
60 that are maintained under version control.
64 -c FILE Output ChangeLog entries for FILE (default ChangeLog).
65 -h HOSTNAME Use HOSTNAME in change log entries (default current host).
66 -i INDENT Indent change log lines by INDENT spaces (default 8).
67 -l LENGTH Try to limit log lines to LENGTH characters (default 79).
68 -L FILE Use FILE (same format as "rlog") for source of logs.
69 -R If no FILEs are given and RCS is used, recurse through working directory.
70 -r OPTION Pass OPTION to subsidiary command (either "rlog" or "cvs -q log").
71 -t TABWIDTH Tab stops are every TABWIDTH characters (default 8).
72 -u "LOGIN<tab>FULLNAME<tab>EMAILADDR" LOGIN has FULLNAME and EMAILADDR.
73 -v Append RCS revision to file names in log lines.
75 --version Output version number.
77 Report bugs to <bug-gnu-emacs@gnu.org>.'
81 # Use the traditional C locale.
90 export LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME
92 # These variables each contain a single ASCII character.
93 # Unfortunately, there's no portable way of writing these characters
94 # in older Unix implementations, other than putting them directly into
96 SOH
='\x01' # SOH, octal code 001
105 TMPDIR
=${TMPDIR-/tmp}
106 changelog
=ChangeLog
# change log file name
107 datearg
= # rlog date option
108 hostname
= # name of local host (if empty, will deduce it later)
109 indent
=8 # indent of log line
110 length
=79 # suggested max width of log line
111 logins
= # login names for people we know fullnames and mailaddrs of
112 loginFullnameMailaddrs
= # login<tab>fullname<tab>mailaddr triplets
113 logTZ
= # time zone for log dates (if empty, use local time)
114 recursive
= # t if we want recursive rlog
115 revision
= # t if we want revision numbers
116 rlog_options
= # options to pass to rlog
117 rlogfile
= # log file to read from
118 tabwidth
=8 # width of horizontal tab
123 -c) changelog
=${2?}; shift;;
124 -i) indent
=${2?}; shift;;
125 -h) hostname
=${2?}; shift;;
126 -l) length
=${2?}; shift;;
127 -L) rlogfile
=${2?}; shift;;
128 -[nu
]) # -n is obsolescent; it is replaced by -u.
130 -n) case ${2?}${3?}${4?} in
132 echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
137 shift; shift; shift;;
139 # If $2 is not tab-separated, use colon for separator.
142 echo >&2 "$0: -u '$2': newlines not allowed"
151 echo >&2 "$0: -u '$2': too many fields"
154 uf
="[^$t]*$t" # An unselected field, followed by a separator.
155 sf
="\\([^$t]*\\)" # The selected field.
156 login
=`expr "X$2" : "X$sf"`
158 expr "X$2" : "$uf$sf"
160 expr "X$2" : "$uf$uf$sf"
163 echo >&2 "$0: -u '$2': not enough fields"
170 ?
*) logins
=$logins$nl$login;;
172 case $loginFullnameMailaddrs in
173 '') loginFullnameMailaddrs
=$lfm;;
174 ?
*) loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$lfm;;
177 case $rlog_options in
178 '') rlog_options
=${2?};;
179 ?
*) rlog_options
=$rlog_options$nl${2?};;
183 -t) tabwidth
=${2?}; shift;;
188 echo >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
190 -*) echo >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
201 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
202 m[3]="Apr"; m[4]="May"; m[5]="Jun"
203 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
204 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
207 logdir
=$TMPDIR/rcs2log$$
210 trap "rm -fr $logdir 2>/dev/null" 0
211 (umask 077 && exec mkdir
$logdir) ||
exit
213 # If no rlog-format log file is given, generate one into $rlogfile.
218 # If no rlog options are given,
219 # log the revisions checked in since the first ChangeLog entry.
220 # Since ChangeLog is only by date, some of these revisions may be
221 # duplicates of what's already in ChangeLog; it's the user's
222 # responsibility to remove them.
223 case $rlog_options in
225 if test -s "$changelog"
228 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
233 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
234 # old-fashioned date and time (Emacs 19.31 and earlier)
237 for (i=0; i<=11; i++) if (m[i] == $2) break
239 printf "%d-%02d-%02d\n", year, i+1, dd
243 d
=`$AWK "$e" <"$changelog"` ||
exit
245 ?
*) datearg
="-d>$d";;
250 # Use TZ specified by ChangeLog local variable, if any.
251 if test -s "$changelog"
254 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
257 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
261 logTZ
=`tail "$changelog" | sed -n "$extractTZ"`
263 ?
*) TZ
=$logTZ; export TZ
;;
267 # If CVS is in use, examine its repository, not the normal RCS files.
268 if test ! -f CVS
/Repository
274 repository
=`sed 1q <CVS/Repository` ||
exit
275 test ! -f CVS
/Root || CVSROOT
=`cat <CVS/Root` ||
exit
278 /* |
:fork
:* |
:local:*) ;;
281 pository
=`expr "X$CVSROOT" : '[^/]*\(.*\)'`;;
289 repository
=${CVSROOT?}/$repository
292 repository
=`expr "$repository" : ':[^:]*:\(.*\)'`;;
295 if test ! -d "$repository"
297 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
300 pository
=$repository;;
303 # Ensure that $pository ends in exactly one slash.
307 *//) pository
=`expr "X$pository" : 'X\(.*\)/'`;;
309 *) pository
=$pository/; break;;
313 # If no rlog options are given, and if we are in a tagged CVS branch,
314 # log only the changes in that branch.
315 case $rlog_options in
319 CVSTAG
=`cat <CVS/Tag` ||
exit
322 rlog_options
=-r`expr "$CVSTAG" : 'T\(.*\)'`;;
324 echo >&2 "$0: invalid CVS/Tag"; exit 1;;
330 # Use $rlog's -zLT option, if $rlog supports it.
331 case `$rlog -zLT 2>&1` in
334 case $rlog_options in
335 '') rlog_options
=-zLT;;
336 ?
*) rlog_options
=-zLT$nl$rlog_options;;
340 # With no arguments, examine all files under the RCS directory.
349 RCSdirs
=`find . -name RCS -type d -print`
350 filesFromRCSfiles
='s|,v$||; s|/RCS/|/|; s|^\./||'
359 ! -name .rcsfreeze.log \
360 ! -name .rcsfreeze.ver \
363 find . -name '*,v' -print
366 sed "$filesFromRCSfiles"
370 for file in RCS
/.
* RCS
/* .
*,v
*,v
373 RCS
/. | RCS
/.. | RCS
/,*, | RCS
/*_
) continue;;
374 RCS
/.rcsfreeze.log | RCS
/.rcsfreeze.ver
) continue;;
375 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue;;
376 RCS
/*,v | RCS
/.
*,v
) ;;
377 RCS
/* | RCS
/.
*) test -f "$file" ||
continue;;
381 ?
*) files
=$files$nl$file;;
395 ?
*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogfile;;
396 '') $rlog $rlog_options ${1+"$@"} >$rlogfile;;
401 # Prefer the POSIX-style -k options, since POSIX 1003.1-2001 prohibits
402 # support for the traditional-style +M -N options.
403 SORT_K_OPTIONS
='-k 3,4r -k 5 -k 1'
404 sort $SORT_K_OPTIONS </dev
/null
2>/dev
/null || SORT_K_OPTIONS
='+2 -4r +4 +0'
407 # Get the full name of each author the logs mention, and set initialize_fullname
408 # to awk code that initializes the `fullname' awk associative array.
409 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
410 # you have to fix the resulting output by hand.
415 case $loginFullnameMailaddrs in
417 case $loginFullnameMailaddrs in
419 sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
420 $loginFullnameMailaddrs
422 loginFullnameMailaddrs
=`cat $llogout`;;
427 for loginFullnameMailaddr
in $loginFullnameMailaddrs
430 set x
$loginFullnameMailaddr
434 initialize_fullname
="$initialize_fullname
435 fullname[\"$login\"] = \"$fullname\""
436 initialize_mailaddr
="$initialize_mailaddr
437 mailaddr[\"$login\"] = \"$mailaddr\""
444 sort -u -o $llogout <<EOF
450 esac >$llogout ||
exit
452 output_authors
='/^date: / {
453 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 ~ /^[^;]*;$/) {
454 print substr($5, 1, length($5)-1)
458 $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - $llogout
462 cat >$llogout <<EOF || exit
465 initialize_author_script
='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
466 initialize_author
=`sed -e "$initialize_author_script" <$llogout`
469 alphabet = "abcdefghijklmnopqrstuvwxyz"
470 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
471 '"$initialize_author"'
476 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
477 # Remove the junk from fullnames like "0000-Admin(0000)".
478 fullname = substr(fullname, index(fullname, "-") + 1)
479 fullname = substr(fullname, 1, index(fullname, "(") - 1)
481 if (fullname ~ /,[^ ]/) {
482 # Some sites put comma-separated junk after the fullname.
483 # Remove it, but leave "Bill Gates, Jr" alone.
484 fullname = substr(fullname, 1, index(fullname, ",") - 1)
486 abbr = index(fullname, "&")
490 i = index(alphabet, a)
491 if (i) A = substr(ALPHABET, i, 1)
492 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
495 # Quote quotes and backslashes properly in full names.
496 # Do not use gsub; traditional awk lacks it.
500 p = index(rest, "\\")
501 q = index(rest, "\"")
508 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
509 rest = substr(rest, p+1)
512 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
518 initialize_fullname
=`
520 (getent passwd $authors) ||
523 for author in $authors
524 do NIS_PATH= nismatch $author passwd.org_dir
526 ypmatch $authors passwd
529 $AWK -F: "$awkscript"
530 `$initialize_fullname;;
534 # Function to print a single log line.
535 # We don't use awk functions, to stay compatible with old awk versions.
536 # `Log' is the log message.
537 # `files' contains the affected files.
540 # Following the GNU coding standards, rewrite
541 # * file: (function): comment
543 # * file (function): comment
544 if (Log ~ /^\([^)]*\):[\t\n ]/) {
546 filefunc = substr(Log, 1, i)
547 while ((j = index(filefunc, "\n"))) {
548 files = files " " substr(filefunc, 1, j-1)
549 filefunc = substr(filefunc, j+1)
551 files = files " " filefunc
552 Log = substr(Log, i+3)
555 # If "label: comment" is too long, break the line after the ":".
558 if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
561 printf "%s*%s:", indent_string, files
563 # Print each line of the log.
565 logline = substr(Log, 1, i-1)
566 if (logline ~ /[^'"$tab"' ]/) {
567 printf "%s%s\n", sep, logline
572 Log = substr(Log, i+1)
577 # Pattern to match the `revision' line of rlog output.
578 rlog_revision_pattern
='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
583 hostname || uname -n || uuname -l || cat /etc/whoami
585 echo >&2 "$0: cannot deduce hostname"
592 domainname
=`(domainname) 2>/dev/null` &&
594 *.
*) hostname
=$hostname.
$domainname;;
600 # Process the rlog output, generating ChangeLog style entries.
602 # First, reformat the rlog output so that each line contains one log entry.
603 # Transliterate \n to SOH so that multiline entries fit on a single line.
604 # Discard irrelevant rlog output.
607 pository = "'"$pository"'"
611 if (pository != "") {
612 filename = substr($0, 11)
613 if (substr(filename, 1, length(pository)) == pository) {
614 filename = substr(filename, length(pository) + 1)
616 if (filename ~ /,v$/) {
617 filename = substr(filename, 1, length(filename) - 2)
619 if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
621 while (substr(filename, i, 1) != "/") i--
622 filename = substr(filename, 1, i - 6) substr(filename, i + 1)
627 /^Working file: / { if (repository == "") filename = substr($0, 15) }
628 /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
630 if (line ~ /'"$rlog_revision_pattern"'/) {
634 if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
637 # This is a traditional RCS format date YYYY/MM/DD.
638 # Replace "/"s with "-"s to get ISO format.
640 while ((i = index(date, "/")) != 0) {
641 newdate = newdate substr(date, 1, i-1) "-"
642 date = substr(date, i+1)
646 time = substr($3, 1, length($3) - 1)
647 author = substr($5, 1, length($5)-1)
648 printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
652 if (line ~ /^branches: /) { next }
653 if (line ~ /^(-----------*|===========*)$/) { print ""; next }
654 if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
657 printf "%s%s", line, SOH
661 # Now each line is of the form
662 # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
663 # where @ stands for an SOH (octal code 001),
664 # and each line of LOG is terminated by SOH instead of \n.
665 # Sort the log entries, first by date+time (in reverse order),
666 # then by author, then by log entry, and finally by file name and revision
668 sort -t"$SOH" $SORT_K_OPTIONS |
670 # Finally, reformat the sorted log entries.
674 revision = "'"$revision"'"
676 # Initialize the fullname and mailaddr associative arrays.
677 '"$initialize_fullname"'
678 '"$initialize_mailaddr"'
680 # Initialize indent string.
683 if (0 < '"$tabwidth"')
684 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
685 indent_string = indent_string "\t"
687 indent_string = indent_string " "
692 for (i = 6; i < NF; i++) newlog = newlog $i "\n"
694 # Ignore log entries prefixed by "#".
695 if (newlog ~ /^#/) { next }
697 if (Log != newlog || date != $3 || author != $5) {
699 # The previous log and this log differ.
702 if (date != "") '"$printlogline"'
704 # Logs that begin with "{clumpname} " should be grouped together,
705 # and the clumpname should be removed.
706 # Extract the new clumpname from the log header,
707 # and use it to decide whether to output a blank line.
710 if (date == "") sep = ""
711 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
712 i = index(newlog, "}")
713 newclumpname = substr(newlog, 1, i)
714 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
715 newlog = substr(newlog, i+1)
716 if (clumpname == newclumpname && date == $3 && author == $5) sep = ""
719 clumpname = newclumpname
721 # Get ready for the next log.
724 for (i in filesknown)
728 if (date != $3 || author != $5) {
729 # The previous date+author and this date+author differ.
736 if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
737 zone = " " substr(time, i)
739 # Print "date[ timezone] fullname <email address>".
740 # Get fullname and email address from associative arrays;
741 # default to author and author@hostname if not in arrays.
742 if (fullname[author])
743 auth = fullname[author]
746 printf "%s%s %s ", date, zone, auth
747 if (mailaddr[author])
748 printf "<%s>\n\n", mailaddr[author]
750 printf "<%s@%s>\n\n", author, "'"$hostname"'"
752 if (! filesknown[$1]) {
754 if (files == "") files = " " $1
755 else files = files ", " $1
756 if (revision && $2 != "?") files = files " " $2
760 # Print the last log.
777 # arch-tag: cea067bd-a552-4254-ba17-078208933073