3 # RCS to ChangeLog generator
5 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002, 2003,
6 # 2004, 2005, 2006, 2007, 2008, 2009, 2010
7 # Free Software Foundation, Inc.
9 # Author: Paul Eggert <eggert@twinsun.com>
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 Copyright
='Copyright (C) 2010 Free Software Foundation, Inc.
26 This program comes with NO WARRANTY, to the extent permitted by law.
27 You may redistribute copies of this program
28 under the terms of the GNU General Public License.
29 For more information about these matters, see the files named COPYING.
30 Author: Paul Eggert <eggert@twinsun.com>'
33 Generate ChangeLog entries from RCS files (perhaps in a CVS repository)
34 and the ChangeLog file (if any). An RCS file typically has a name
35 ending in ",v", and represents the entire history of a file that is
36 under revision control. The ChangeLog file logs entries for changes,
37 in reverse chronological order.
39 Generate entries for changes entered into RCS (or CVS) more recently
40 than the newest existing entry in the ChangeLog file. You can then
41 edit these entries by hand, and prepend them to the ChangeLog file.
43 Output the resulting ChangeLog entries to standard output.
44 Each entry looks something like this:
46 2004-04-17 Paul Eggert <eggert@gnu.org>
48 * rcs2log (Help): Clarify wording of the usage message.
49 Problem reported by Alan Mackenzie in
50 <http://mail.gnu.org/archive/html/bug-gnu-emacs/2004-04/msg00188.html>.
52 ChangeLog entries contain the current date, full name, email address
53 including hostname, the name of the affected file, and commentary.
54 RCS and CVS logs lack full names and email addresses, so they are
55 inferred from login names using a heuristic that can be overridden
58 Ignore log entries that start with "#".
59 Clump together log entries that start with "{topic} ",
60 where "topic" contains neither white space nor "}".
62 If no FILE is specified, use all files under the working directory
63 that are maintained under version control.
67 -c FILE Output ChangeLog entries for FILE (default ChangeLog).
68 -h HOSTNAME Use HOSTNAME in change log entries (default current host).
69 -i INDENT Indent change log lines by INDENT spaces (default 8).
70 -l LENGTH Try to limit log lines to LENGTH characters (default 79).
71 -L FILE Use FILE (same format as "rlog") for source of logs.
72 -R If no FILEs are given and RCS is used, recurse through working directory.
73 -r OPTION Pass OPTION to subsidiary command (either "rlog" or "cvs -q log").
74 -t TABWIDTH Tab stops are every TABWIDTH characters (default 8).
75 -u "LOGIN<tab>FULLNAME<tab>EMAILADDR" LOGIN has FULLNAME and EMAILADDR.
76 -v Append RCS revision to file names in log lines.
78 --version Output version number.
80 Report bugs to <bug-gnu-emacs@gnu.org>.'
84 # Use the traditional C locale.
93 export LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME
95 # These variables each contain a single ASCII character.
96 # Unfortunately, there's no portable way of writing these characters
97 # in older Unix implementations, other than putting them directly into
99 SOH
='\x01' # SOH, octal code 001
108 TMPDIR
=${TMPDIR-/tmp}
109 changelog
=ChangeLog
# change log file name
110 datearg
= # rlog date option
111 hostname
= # name of local host (if empty, will deduce it later)
112 indent
=8 # indent of log line
113 length
=79 # suggested max width of log line
114 logins
= # login names for people we know fullnames and mailaddrs of
115 loginFullnameMailaddrs
= # login<tab>fullname<tab>mailaddr triplets
116 logTZ
= # time zone for log dates (if empty, use local time)
117 recursive
= # t if we want recursive rlog
118 revision
= # t if we want revision numbers
119 rlog_options
= # options to pass to rlog
120 rlogfile
= # log file to read from
121 tabwidth
=8 # width of horizontal tab
126 -c) changelog
=${2?}; shift;;
127 -i) indent
=${2?}; shift;;
128 -h) hostname
=${2?}; shift;;
129 -l) length
=${2?}; shift;;
130 -L) rlogfile
=${2?}; shift;;
131 -[nu
]) # -n is obsolescent; it is replaced by -u.
133 -n) case ${2?}${3?}${4?} in
135 echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
140 shift; shift; shift;;
142 # If $2 is not tab-separated, use colon for separator.
145 echo >&2 "$0: -u '$2': newlines not allowed"
154 echo >&2 "$0: -u '$2': too many fields"
157 uf
="[^$t]*$t" # An unselected field, followed by a separator.
158 sf
="\\([^$t]*\\)" # The selected field.
159 login
=`expr "X$2" : "X$sf"`
161 expr "X$2" : "$uf$sf"
163 expr "X$2" : "$uf$uf$sf"
166 echo >&2 "$0: -u '$2': not enough fields"
173 ?
*) logins
=$logins$nl$login;;
175 case $loginFullnameMailaddrs in
176 '') loginFullnameMailaddrs
=$lfm;;
177 ?
*) loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$lfm;;
180 case $rlog_options in
181 '') rlog_options
=${2?};;
182 ?
*) rlog_options
=$rlog_options$nl${2?};;
186 -t) tabwidth
=${2?}; shift;;
191 echo >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
193 -*) echo >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
204 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
205 m[3]="Apr"; m[4]="May"; m[5]="Jun"
206 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
207 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
210 logdir
=$TMPDIR/rcs2log$$
213 trap "rm -fr $logdir 2>/dev/null" 0
214 (umask 077 && exec mkdir
$logdir) ||
exit
216 # If no rlog-format log file is given, generate one into $rlogfile.
221 # If no rlog options are given,
222 # log the revisions checked in since the first ChangeLog entry.
223 # Since ChangeLog is only by date, some of these revisions may be
224 # duplicates of what's already in ChangeLog; it's the user's
225 # responsibility to remove them.
226 case $rlog_options in
228 if test -s "$changelog"
231 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
236 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
237 # old-fashioned date and time (Emacs 19.31 and earlier)
240 for (i=0; i<=11; i++) if (m[i] == $2) break
242 printf "%d-%02d-%02d\n", year, i+1, dd
246 d
=`$AWK "$e" <"$changelog"` ||
exit
248 ?
*) datearg
="-d>$d";;
253 # Use TZ specified by ChangeLog local variable, if any.
254 if test -s "$changelog"
257 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
260 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
264 logTZ
=`tail "$changelog" | sed -n "$extractTZ"`
266 ?
*) TZ
=$logTZ; export TZ
;;
270 # If CVS is in use, examine its repository, not the normal RCS files.
271 if test ! -f CVS
/Repository
277 repository
=`sed 1q <CVS/Repository` ||
exit
278 test ! -f CVS
/Root || CVSROOT
=`cat <CVS/Root` ||
exit
281 /* |
:fork
:* |
:local:*) ;;
284 pository
=`expr "X$CVSROOT" : '[^/]*\(.*\)'`;;
292 repository
=${CVSROOT?}/$repository
295 repository
=`expr "$repository" : ':[^:]*:\(.*\)'`;;
298 if test ! -d "$repository"
300 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
303 pository
=$repository;;
306 # Ensure that $pository ends in exactly one slash.
310 *//) pository
=`expr "X$pository" : 'X\(.*\)/'`;;
312 *) pository
=$pository/; break;;
316 # If no rlog options are given, and if we are in a tagged CVS branch,
317 # log only the changes in that branch.
318 case $rlog_options in
322 CVSTAG
=`cat <CVS/Tag` ||
exit
325 rlog_options
=-r`expr "$CVSTAG" : 'T\(.*\)'`;;
327 echo >&2 "$0: invalid CVS/Tag"; exit 1;;
333 # Use $rlog's -zLT option, if $rlog supports it.
334 case `$rlog -zLT 2>&1` in
337 case $rlog_options in
338 '') rlog_options
=-zLT;;
339 ?
*) rlog_options
=-zLT$nl$rlog_options;;
343 # With no arguments, examine all files under the RCS directory.
352 RCSdirs
=`find . -name RCS -type d -print`
353 filesFromRCSfiles
='s|,v$||; s|/RCS/|/|; s|^\./||'
362 ! -name .rcsfreeze.log \
363 ! -name .rcsfreeze.ver \
366 find . -name '*,v' -print
369 sed "$filesFromRCSfiles"
373 for file in RCS
/.
* RCS
/* .
*,v
*,v
376 RCS
/. | RCS
/.. | RCS
/,*, | RCS
/*_
) continue;;
377 RCS
/.rcsfreeze.log | RCS
/.rcsfreeze.ver
) continue;;
378 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue;;
379 RCS
/*,v | RCS
/.
*,v
) ;;
380 RCS
/* | RCS
/.
*) test -f "$file" ||
continue;;
384 ?
*) files
=$files$nl$file;;
398 ?
*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogfile;;
399 '') $rlog $rlog_options ${1+"$@"} >$rlogfile;;
404 # Prefer the POSIX-style -k options, since POSIX 1003.1-2001 prohibits
405 # support for the traditional-style +M -N options.
406 SORT_K_OPTIONS
='-k 3,4r -k 5 -k 1'
407 sort $SORT_K_OPTIONS </dev
/null
2>/dev
/null || SORT_K_OPTIONS
='+2 -4r +4 +0'
410 # Get the full name of each author the logs mention, and set initialize_fullname
411 # to awk code that initializes the `fullname' awk associative array.
412 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
413 # you have to fix the resulting output by hand.
418 case $loginFullnameMailaddrs in
420 case $loginFullnameMailaddrs in
422 sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
423 $loginFullnameMailaddrs
425 loginFullnameMailaddrs
=`cat $llogout`;;
430 for loginFullnameMailaddr
in $loginFullnameMailaddrs
433 set x
$loginFullnameMailaddr
437 initialize_fullname
="$initialize_fullname
438 fullname[\"$login\"] = \"$fullname\""
439 initialize_mailaddr
="$initialize_mailaddr
440 mailaddr[\"$login\"] = \"$mailaddr\""
447 sort -u -o $llogout <<EOF
453 esac >$llogout ||
exit
455 output_authors
='/^date: / {
456 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 ~ /^[^;]*;$/) {
457 print substr($5, 1, length($5)-1)
461 $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - $llogout
465 cat >$llogout <<EOF || exit
468 initialize_author_script
='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
469 initialize_author
=`sed -e "$initialize_author_script" <$llogout`
472 alphabet = "abcdefghijklmnopqrstuvwxyz"
473 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
474 '"$initialize_author"'
479 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
480 # Remove the junk from fullnames like "0000-Admin(0000)".
481 fullname = substr(fullname, index(fullname, "-") + 1)
482 fullname = substr(fullname, 1, index(fullname, "(") - 1)
484 if (fullname ~ /,[^ ]/) {
485 # Some sites put comma-separated junk after the fullname.
486 # Remove it, but leave "Bill Gates, Jr" alone.
487 fullname = substr(fullname, 1, index(fullname, ",") - 1)
489 abbr = index(fullname, "&")
493 i = index(alphabet, a)
494 if (i) A = substr(ALPHABET, i, 1)
495 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
498 # Quote quotes and backslashes properly in full names.
499 # Do not use gsub; traditional awk lacks it.
503 p = index(rest, "\\")
504 q = index(rest, "\"")
511 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
512 rest = substr(rest, p+1)
515 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
521 initialize_fullname
=`
523 (getent passwd $authors) ||
526 for author in $authors
527 do NIS_PATH= nismatch $author passwd.org_dir
529 ypmatch $authors passwd
532 $AWK -F: "$awkscript"
533 `$initialize_fullname;;
537 # Function to print a single log line.
538 # We don't use awk functions, to stay compatible with old awk versions.
539 # `Log' is the log message.
540 # `files' contains the affected files.
543 # Following the GNU coding standards, rewrite
544 # * file: (function): comment
546 # * file (function): comment
547 if (Log ~ /^\([^)]*\):[\t\n ]/) {
549 filefunc = substr(Log, 1, i)
550 while ((j = index(filefunc, "\n"))) {
551 files = files " " substr(filefunc, 1, j-1)
552 filefunc = substr(filefunc, j+1)
554 files = files " " filefunc
555 Log = substr(Log, i+3)
558 # If "label: comment" is too long, break the line after the ":".
561 if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
564 printf "%s*%s:", indent_string, files
566 # Print each line of the log.
568 logline = substr(Log, 1, i-1)
569 if (logline ~ /[^'"$tab"' ]/) {
570 printf "%s%s\n", sep, logline
575 Log = substr(Log, i+1)
580 # Pattern to match the `revision' line of rlog output.
581 rlog_revision_pattern
='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
586 hostname || uname -n || uuname -l || cat /etc/whoami
588 echo >&2 "$0: cannot deduce hostname"
595 domainname
=`(domainname) 2>/dev/null` &&
597 *.
*) hostname
=$hostname.
$domainname;;
603 # Process the rlog output, generating ChangeLog style entries.
605 # First, reformat the rlog output so that each line contains one log entry.
606 # Transliterate \n to SOH so that multiline entries fit on a single line.
607 # Discard irrelevant rlog output.
610 pository = "'"$pository"'"
614 if (pository != "") {
615 filename = substr($0, 11)
616 if (substr(filename, 1, length(pository)) == pository) {
617 filename = substr(filename, length(pository) + 1)
619 if (filename ~ /,v$/) {
620 filename = substr(filename, 1, length(filename) - 2)
622 if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
624 while (substr(filename, i, 1) != "/") i--
625 filename = substr(filename, 1, i - 6) substr(filename, i + 1)
630 /^Working file: / { if (repository == "") filename = substr($0, 15) }
631 /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
633 if (line ~ /'"$rlog_revision_pattern"'/) {
637 if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
640 # This is a traditional RCS format date YYYY/MM/DD.
641 # Replace "/"s with "-"s to get ISO format.
643 while ((i = index(date, "/")) != 0) {
644 newdate = newdate substr(date, 1, i-1) "-"
645 date = substr(date, i+1)
649 time = substr($3, 1, length($3) - 1)
650 author = substr($5, 1, length($5)-1)
651 printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
655 if (line ~ /^branches: /) { next }
656 if (line ~ /^(-----------*|===========*)$/) { print ""; next }
657 if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
660 printf "%s%s", line, SOH
664 # Now each line is of the form
665 # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
666 # where @ stands for an SOH (octal code 001),
667 # and each line of LOG is terminated by SOH instead of \n.
668 # Sort the log entries, first by date+time (in reverse order),
669 # then by author, then by log entry, and finally by file name and revision
671 sort -t"$SOH" $SORT_K_OPTIONS |
673 # Finally, reformat the sorted log entries.
677 revision = "'"$revision"'"
679 # Initialize the fullname and mailaddr associative arrays.
680 '"$initialize_fullname"'
681 '"$initialize_mailaddr"'
683 # Initialize indent string.
686 if (0 < '"$tabwidth"')
687 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
688 indent_string = indent_string "\t"
690 indent_string = indent_string " "
695 for (i = 6; i < NF; i++) newlog = newlog $i "\n"
697 # Ignore log entries prefixed by "#".
698 if (newlog ~ /^#/) { next }
700 if (Log != newlog || date != $3 || author != $5) {
702 # The previous log and this log differ.
705 if (date != "") '"$printlogline"'
707 # Logs that begin with "{clumpname} " should be grouped together,
708 # and the clumpname should be removed.
709 # Extract the new clumpname from the log header,
710 # and use it to decide whether to output a blank line.
713 if (date == "") sep = ""
714 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
715 i = index(newlog, "}")
716 newclumpname = substr(newlog, 1, i)
717 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
718 newlog = substr(newlog, i+1)
719 if (clumpname == newclumpname && date == $3 && author == $5) sep = ""
722 clumpname = newclumpname
724 # Get ready for the next log.
727 for (i in filesknown)
731 if (date != $3 || author != $5) {
732 # The previous date+author and this date+author differ.
739 if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
740 zone = " " substr(time, i)
742 # Print "date[ timezone] fullname <email address>".
743 # Get fullname and email address from associative arrays;
744 # default to author and author@hostname if not in arrays.
745 if (fullname[author])
746 auth = fullname[author]
749 printf "%s%s %s ", date, zone, auth
750 if (mailaddr[author])
751 printf "<%s>\n\n", mailaddr[author]
753 printf "<%s@%s>\n\n", author, "'"$hostname"'"
755 if (! filesknown[$1]) {
757 if (files == "") files = " " $1
758 else files = files ", " $1
759 if (revision && $2 != "?") files = files " " $2
763 # Print the last log.
780 # arch-tag: cea067bd-a552-4254-ba17-078208933073