3 # RCS to ChangeLog generator
5 # Copyright (C) 1992-1998, 2001-2014 Free Software Foundation, Inc.
7 # Author: Paul Eggert <eggert@twinsun.com>
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 Copyright
='Copyright (C) 2014 Free Software Foundation, Inc.
24 This program comes with NO WARRANTY, to the extent permitted by law.
25 You may redistribute copies of this program
26 under the terms of the GNU General Public License.
27 For more information about these matters, see the files named COPYING.
28 Author: Paul Eggert <eggert@twinsun.com>'
31 Generate ChangeLog entries from RCS files (perhaps in a CVS repository)
32 and the ChangeLog file (if any). An RCS file typically has a name
33 ending in ",v", and represents the entire history of a file that is
34 under revision control. The ChangeLog file logs entries for changes,
35 in reverse chronological order.
37 Generate entries for changes entered into RCS (or CVS) more recently
38 than the newest existing entry in the ChangeLog file. You can then
39 edit these entries by hand, and prepend them to the ChangeLog file.
41 Output the resulting ChangeLog entries to standard output.
42 Each entry looks something like this:
44 2004-04-17 Paul Eggert <eggert@gnu.org>
46 * rcs2log (Help): Clarify wording of the usage message.
47 Problem reported by Alan Mackenzie in
48 <http://mail.gnu.org/archive/html/bug-gnu-emacs/2004-04/msg00188.html>.
50 ChangeLog entries contain the current date, full name, email address
51 including hostname, the name of the affected file, and commentary.
52 RCS and CVS logs lack full names and email addresses, so they are
53 inferred from login names using a heuristic that can be overridden
56 Ignore log entries that start with "#".
57 Clump together log entries that start with "{topic} ",
58 where "topic" contains neither white space nor "}".
60 If no FILE is specified, use all files under the working directory
61 that are maintained under version control.
65 -c FILE Output ChangeLog entries for FILE (default ChangeLog).
66 -h HOSTNAME Use HOSTNAME in change log entries (default current host).
67 -i INDENT Indent change log lines by INDENT spaces (default 8).
68 -l LENGTH Try to limit log lines to LENGTH characters (default 79).
69 -L FILE Use FILE (same format as "rlog") for source of logs.
70 -R If no FILEs are given and RCS is used, recurse through working directory.
71 -r OPTION Pass OPTION to subsidiary command (either "rlog" or "cvs -q log").
72 -t TABWIDTH Tab stops are every TABWIDTH characters (default 8).
73 -u "LOGIN<tab>FULLNAME<tab>EMAILADDR" LOGIN has FULLNAME and EMAILADDR.
74 -v Append RCS revision to file names in log lines.
76 --version Output version number.
78 Report bugs to <bug-gnu-emacs@gnu.org>.'
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 if type mktemp
>/dev
/null
2>&1; then
211 logdir
=$TMPDIR/rcs2log$$
212 (umask 077 && mkdir
"$logdir")
215 -*) logdir
=.
/$logdir;;
218 trap "rm -fr \"$logdir\" 2>/dev/null" 0
222 # If no rlog-format log file is given, generate one into $rlogfile.
227 # If no rlog options are given,
228 # log the revisions checked in since the first ChangeLog entry.
229 # Since ChangeLog is only by date, some of these revisions may be
230 # duplicates of what's already in ChangeLog; it's the user's
231 # responsibility to remove them.
232 case $rlog_options in
234 if test -s "$changelog"
237 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
242 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
243 # old-fashioned date and time (Emacs 19.31 and earlier)
246 for (i=0; i<=11; i++) if (m[i] == $2) break
248 printf "%d-%02d-%02d\n", year, i+1, dd
252 d
=`$AWK "$e" <"$changelog"` ||
exit
254 ?
*) datearg
="-d>$d";;
259 # Use TZ specified by ChangeLog local variable, if any.
260 if test -s "$changelog"
263 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
266 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
270 logTZ
=`tail "$changelog" | sed -n "$extractTZ"`
272 ?
*) TZ
=$logTZ; export TZ
;;
276 # If CVS is in use, examine its repository, not the normal RCS files.
277 if test ! -f CVS
/Repository
283 repository
=`sed 1q <CVS/Repository` ||
exit
284 test ! -f CVS
/Root || CVSROOT
=`cat <CVS/Root` ||
exit
287 /* |
:fork
:* |
:local:*) ;;
290 pository
=`expr "X$CVSROOT" : '[^/]*\(.*\)'`;;
298 repository
=${CVSROOT?}/$repository
301 repository
=`expr "$repository" : ':[^:]*:\(.*\)'`;;
304 if test ! -d "$repository"
306 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
309 pository
=$repository;;
312 # Ensure that $pository ends in exactly one slash.
316 *//) pository
=`expr "X$pository" : 'X\(.*\)/'`;;
318 *) pository
=$pository/; break;;
322 # If no rlog options are given, and if we are in a tagged CVS branch,
323 # log only the changes in that branch.
324 case $rlog_options in
328 CVSTAG
=`cat <CVS/Tag` ||
exit
331 rlog_options
=-r`expr "$CVSTAG" : 'T\(.*\)'`;;
333 echo >&2 "$0: invalid CVS/Tag"; exit 1;;
339 # Use $rlog's -zLT option, if $rlog supports it.
340 case `$rlog -zLT 2>&1` in
343 case $rlog_options in
344 '') rlog_options
=-zLT;;
345 ?
*) rlog_options
=-zLT$nl$rlog_options;;
349 # With no arguments, examine all files under the RCS directory.
358 RCSdirs
=`find . -name RCS -type d -print`
359 filesFromRCSfiles
='s|,v$||; s|/RCS/|/|; s|^\./||'
368 ! -name .rcsfreeze.log \
369 ! -name .rcsfreeze.ver \
372 find . -name '*,v' -print
375 sed "$filesFromRCSfiles"
379 for file in RCS
/.
* RCS
/* .
*,v
*,v
382 RCS
/. | RCS
/.. | RCS
/,*, | RCS
/*_
) continue;;
383 RCS
/.rcsfreeze.log | RCS
/.rcsfreeze.ver
) continue;;
384 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue;;
385 RCS
/*,v | RCS
/.
*,v
) ;;
386 RCS
/* | RCS
/.
*) test -f "$file" ||
continue;;
390 ?
*) files
=$files$nl$file;;
404 ?
*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogfile;;
405 '') $rlog $rlog_options ${1+"$@"} >$rlogfile;;
410 # Prefer the POSIX-style -k options, since POSIX 1003.1-2001 prohibits
411 # support for the traditional-style +M -N options.
412 SORT_K_OPTIONS
='-k 3,4r -k 5 -k 1'
413 sort $SORT_K_OPTIONS </dev
/null
2>/dev
/null || SORT_K_OPTIONS
='+2 -4r +4 +0'
416 # Get the full name of each author the logs mention, and set initialize_fullname
417 # to awk code that initializes the `fullname' awk associative array.
418 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
419 # you have to fix the resulting output by hand.
424 case $loginFullnameMailaddrs in
426 case $loginFullnameMailaddrs in
428 sed 's/["\\]/\\&/g' >"$llogout" <<EOF || exit
429 $loginFullnameMailaddrs
431 loginFullnameMailaddrs
=`cat "$llogout"`;;
436 for loginFullnameMailaddr
in $loginFullnameMailaddrs
439 set x
$loginFullnameMailaddr
443 initialize_fullname
="$initialize_fullname
444 fullname[\"$login\"] = \"$fullname\""
445 initialize_mailaddr
="$initialize_mailaddr
446 mailaddr[\"$login\"] = \"$mailaddr\""
453 sort -u -o "$llogout" <<EOF
459 esac >"$llogout" ||
exit
461 output_authors
='/^date: / {
462 cvsformat = $5 == "author:"
463 if ($2 ~ /^[0-9]*[-\/][0-9][0-9][-\/][0-9][0-9]$/ && (cvsformat ? $3 ~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/ && $4 ~ /^[-+][0-9:]*;$/ : $3 ~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9][-+0-9:]*;$/)) {
464 author = $(5 + cvsformat)
465 if ($(4 + cvsformat) == "author:" && author ~ /^[^;]*;$/) {
466 print substr(author, 1, length(author)-1)
471 $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - "$llogout"
475 cat >"$llogout" <<EOF || exit
478 initialize_author_script
='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
479 initialize_author
=`sed -e "$initialize_author_script" <"$llogout"`
482 alphabet = "abcdefghijklmnopqrstuvwxyz"
483 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
484 '"$initialize_author"'
489 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
490 # Remove the junk from fullnames like "0000-Admin(0000)".
491 fullname = substr(fullname, index(fullname, "-") + 1)
492 fullname = substr(fullname, 1, index(fullname, "(") - 1)
494 if (fullname ~ /,[^ ]/) {
495 # Some sites put comma-separated junk after the fullname.
496 # Remove it, but leave "Bill Gates, Jr" alone.
497 fullname = substr(fullname, 1, index(fullname, ",") - 1)
499 abbr = index(fullname, "&")
503 i = index(alphabet, a)
504 if (i) A = substr(ALPHABET, i, 1)
505 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
508 # Quote quotes and backslashes properly in full names.
509 # Do not use gsub; traditional awk lacks it.
513 p = index(rest, "\\")
514 q = index(rest, "\"")
521 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
522 rest = substr(rest, p+1)
525 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
531 initialize_fullname
=`
533 (getent passwd $authors) ||
536 for author in $authors
537 do NIS_PATH= nismatch $author passwd.org_dir
539 ypmatch $authors passwd
542 $AWK -F: "$awkscript"
543 `$initialize_fullname;;
547 # Function to print a single log line.
548 # We don't use awk functions, to stay compatible with old awk versions.
549 # `Log' is the log message.
550 # `files' contains the affected files.
553 # Following the GNU coding standards, rewrite
554 # * file: (function): comment
556 # * file (function): comment
557 if (Log ~ /^\([^)]*\):[\t\n ]/) {
559 filefunc = substr(Log, 1, i)
560 while ((j = index(filefunc, "\n"))) {
561 files = files " " substr(filefunc, 1, j-1)
562 filefunc = substr(filefunc, j+1)
564 files = files " " filefunc
565 Log = substr(Log, i+3)
568 # If "label: comment" is too long, break the line after the ":".
571 if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
574 printf "%s*%s:", indent_string, files
576 # Print each line of the log.
578 logline = substr(Log, 1, i-1)
579 if (logline ~ /[^'"$tab"' ]/) {
580 printf "%s%s\n", sep, logline
585 Log = substr(Log, i+1)
590 # Pattern to match the `revision' line of rlog output.
591 rlog_revision_pattern
='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
596 hostname || uname -n || uuname -l || cat /etc/whoami
598 echo >&2 "$0: cannot deduce hostname"
605 domainname
=`(domainname) 2>/dev/null` &&
607 *.
*) hostname
=$hostname.
$domainname;;
613 # Process the rlog output, generating ChangeLog style entries.
615 # First, reformat the rlog output so that each line contains one log entry.
616 # Transliterate \n to SOH so that multiline entries fit on a single line.
617 # Discard irrelevant rlog output.
620 pository = "'"$pository"'"
624 if (pository != "") {
625 filename = substr($0, 11)
626 if (substr(filename, 1, length(pository)) == pository) {
627 filename = substr(filename, length(pository) + 1)
629 if (filename ~ /,v$/) {
630 filename = substr(filename, 1, length(filename) - 2)
632 if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
634 while (substr(filename, i, 1) != "/") i--
635 filename = substr(filename, 1, i - 6) substr(filename, i + 1)
640 /^Working file: / { if (repository == "") filename = substr($0, 15) }
641 /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
643 if (line ~ /'"$rlog_revision_pattern"'/) {
647 if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
650 # This is a traditional RCS format date YYYY/MM/DD.
651 # Replace "/"s with "-"s to get ISO format.
653 while ((i = index(date, "/")) != 0) {
654 newdate = newdate substr(date, 1, i-1) "-"
655 date = substr(date, i+1)
660 for (i = 3; i <= NF; i++) {
663 time = substr(time, 1, length(time) - 1)
668 if ($i == "author:") {
671 author = substr(author, 1, length(author) - 1)
676 printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
680 if (line ~ /^branches: /) { next }
681 if (line ~ /^(-----------*|===========*)$/) { print ""; next }
682 if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
685 printf "%s%s", line, SOH
689 # Now each line is of the form
690 # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
691 # where @ stands for an SOH (octal code 001),
692 # and each line of LOG is terminated by SOH instead of \n.
693 # Sort the log entries, first by date+time (in reverse order),
694 # then by author, then by log entry, and finally by file name and revision
696 sort -t"$SOH" $SORT_K_OPTIONS |
698 # Finally, reformat the sorted log entries.
702 revision = "'"$revision"'"
704 # Initialize the fullname and mailaddr associative arrays.
705 '"$initialize_fullname"'
706 '"$initialize_mailaddr"'
708 # Initialize indent string.
711 if (0 < '"$tabwidth"')
712 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
713 indent_string = indent_string "\t"
715 indent_string = indent_string " "
720 for (i = 6; i < NF; i++) newlog = newlog $i "\n"
722 # Ignore log entries prefixed by "#".
723 if (newlog ~ /^#/) { next }
725 if (Log != newlog || date != $3 || author != $5) {
727 # The previous log and this log differ.
730 if (date != "") '"$printlogline"'
732 # Logs that begin with "{clumpname} " should be grouped together,
733 # and the clumpname should be removed.
734 # Extract the new clumpname from the log header,
735 # and use it to decide whether to output a blank line.
738 if (date == "") sep = ""
739 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
740 i = index(newlog, "}")
741 newclumpname = substr(newlog, 1, i)
742 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
743 newlog = substr(newlog, i+1)
744 if (clumpname == newclumpname && date == $3 && author == $5) sep = ""
747 clumpname = newclumpname
749 # Get ready for the next log.
752 for (i in filesknown)
756 if (date != $3 || author != $5) {
757 # The previous date+author and this date+author differ.
764 if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
765 zone = " " substr(time, i)
767 # Print "date[ timezone] fullname <email address>".
768 # Get fullname and email address from associative arrays;
769 # default to author and author@hostname if not in arrays.
770 if (fullname[author])
771 auth = fullname[author]
774 printf "%s%s %s ", date, zone, auth
775 if (mailaddr[author])
776 printf "<%s>\n\n", mailaddr[author]
778 printf "<%s@%s>\n\n", author, "'"$hostname"'"
780 if (! filesknown[$1]) {
782 if (files == "") files = " " $1
783 else files = files ", " $1
784 if (revision && $2 != "?") files = files " " $2
788 # Print the last log.
799 exec rm -fr "$logdir"