3 # RCS to ChangeLog generator
5 # Copyright (C) 1992-1998, 2001-2018 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 <https://www.gnu.org/licenses/>.
23 Copyright
='Copyright (C) 2018 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 <https://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
134 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
139 shift; shift; shift;;
141 # If $2 is not tab-separated, use colon for separator.
144 printf '%s\n' >&2 "$0: -u '$2': newlines not allowed"
153 printf '%s\n' >&2 "$0: -u '$2': too many fields"
156 uf
="[^$t]*$t" # An unselected field, followed by a separator.
157 sf
="\\([^$t]*\\)" # The selected field.
158 login
=`expr "X$2" : "X$sf"`
160 expr "X$2" : "$uf$sf"
162 expr "X$2" : "$uf$uf$sf"
165 printf '%s\n' >&2 "$0: -u '$2': not enough fields"
172 ?
*) logins
=$logins$nl$login;;
174 case $loginFullnameMailaddrs in
175 '') loginFullnameMailaddrs
=$lfm;;
176 ?
*) loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$lfm;;
179 case $rlog_options in
180 '') rlog_options
=${2?};;
181 ?
*) rlog_options
=$rlog_options$nl${2?};;
185 -t) tabwidth
=${2?}; shift;;
190 printf '%s\n' >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
192 -*) printf '%s\n' >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
203 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
204 m[3]="Apr"; m[4]="May"; m[5]="Jun"
205 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
206 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
209 if type mktemp
>/dev
/null
2>&1; then
212 logdir
=$TMPDIR/rcs2log$$
213 (umask 077 && mkdir
"$logdir")
216 -*) logdir
=.
/$logdir;;
219 trap "rm -fr \"$logdir\" 2>/dev/null" 0
223 # If no rlog-format log file is given, generate one into $rlogfile.
228 # If no rlog options are given,
229 # log the revisions checked in since the first ChangeLog entry.
230 # Since ChangeLog is only by date, some of these revisions may be
231 # duplicates of what's already in ChangeLog; it's the user's
232 # responsibility to remove them.
233 case $rlog_options in
235 if test -s "$changelog"
238 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
243 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
244 # old-fashioned date and time (Emacs 19.31 and earlier)
247 for (i=0; i<=11; i++) if (m[i] == $2) break
249 printf "%d-%02d-%02d\n", year, i+1, dd
253 d
=`$AWK "$e" <"$changelog"` ||
exit
255 ?
*) datearg
="-d>$d";;
260 # Use TZ specified by ChangeLog local variable, if any.
261 if test -s "$changelog"
264 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
267 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
271 logTZ
=`tail "$changelog" | sed -n "$extractTZ"`
273 ?
*) TZ
=$logTZ; export TZ
;;
277 # If CVS is in use, examine its repository, not the normal RCS files.
278 if test ! -f CVS
/Repository
284 repository
=`sed 1q <CVS/Repository` ||
exit
285 test ! -f CVS
/Root || CVSROOT
=`cat <CVS/Root` ||
exit
288 /* |
:fork
:* |
:local:*) ;;
291 pository
=`expr "X$CVSROOT" : '[^/]*\(.*\)'`;;
299 repository
=${CVSROOT?}/$repository
302 repository
=`expr "$repository" : ':[^:]*:\(.*\)'`;;
305 if test ! -d "$repository"
308 "$0: $repository: bad repository (see CVS/Repository)"
311 pository
=$repository;;
314 # Ensure that $pository ends in exactly one slash.
318 *//) pository
=`expr "X$pository" : 'X\(.*\)/'`;;
320 *) pository
=$pository/; break;;
324 # If no rlog options are given, and if we are in a tagged CVS branch,
325 # log only the changes in that branch.
326 case $rlog_options in
330 CVSTAG
=`cat <CVS/Tag` ||
exit
333 rlog_options
=-r`expr "$CVSTAG" : 'T\(.*\)'`;;
335 printf '%s\n' >&2 "$0: invalid CVS/Tag"; exit 1;;
341 # Use $rlog's -zLT option, if $rlog supports it.
342 case `$rlog -zLT 2>&1` in
345 case $rlog_options in
346 '') rlog_options
=-zLT;;
347 ?
*) rlog_options
=-zLT$nl$rlog_options;;
351 # With no arguments, examine all files under the RCS directory.
360 RCSdirs
=`find . -name RCS -type d -print`
361 filesFromRCSfiles
='s|,v$||; s|/RCS/|/|; s|^\./||'
370 ! -name .rcsfreeze.log \
371 ! -name .rcsfreeze.ver \
374 find . -name '*,v' -print
377 sed "$filesFromRCSfiles"
381 for file in RCS
/.
* RCS
/* .
*,v
*,v
384 RCS
/. | RCS
/.. | RCS
/,*, | RCS
/*_
) continue;;
385 RCS
/.rcsfreeze.log | RCS
/.rcsfreeze.ver
) continue;;
386 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue;;
387 RCS
/*,v | RCS
/.
*,v
) ;;
388 RCS
/* | RCS
/.
*) test -f "$file" ||
continue;;
392 ?
*) files
=$files$nl$file;;
406 ?
*) $rlog $rlog_options "$datearg" "$@" >$rlogfile;;
407 '') $rlog $rlog_options "$@" >$rlogfile;;
412 # Prefer the POSIX-style -k options, since POSIX 1003.1-2001 prohibits
413 # support for the traditional-style +M -N options.
414 SORT_K_OPTIONS
='-k 3,4r -k 5 -k 1'
415 sort $SORT_K_OPTIONS </dev
/null
2>/dev
/null || SORT_K_OPTIONS
='+2 -4r +4 +0'
418 # Get the full name of each author the logs mention, and set initialize_fullname
419 # to awk code that initializes the 'fullname' awk associative array.
420 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
421 # you have to fix the resulting output by hand.
426 case $loginFullnameMailaddrs in
428 case $loginFullnameMailaddrs in
430 sed 's/["\\]/\\&/g' >"$llogout" <<EOF || exit
431 $loginFullnameMailaddrs
433 loginFullnameMailaddrs
=`cat "$llogout"`;;
438 for loginFullnameMailaddr
in $loginFullnameMailaddrs
441 set x
$loginFullnameMailaddr
445 initialize_fullname
="$initialize_fullname
446 fullname[\"$login\"] = \"$fullname\""
447 initialize_mailaddr
="$initialize_mailaddr
448 mailaddr[\"$login\"] = \"$mailaddr\""
455 sort -u -o "$llogout" <<EOF
461 esac >"$llogout" ||
exit
463 output_authors
='/^date: / {
464 cvsformat = $5 == "author:"
465 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:]*;$/)) {
466 author = $(5 + cvsformat)
467 if ($(4 + cvsformat) == "author:" && author ~ /^[^;]*;$/) {
468 print substr(author, 1, length(author)-1)
473 $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - "$llogout"
477 cat >"$llogout" <<EOF || exit
480 initialize_author_script
='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
481 initialize_author
=`sed -e "$initialize_author_script" <"$llogout"`
484 alphabet = "abcdefghijklmnopqrstuvwxyz"
485 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
486 '"$initialize_author"'
491 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
492 # Remove the junk from fullnames like "0000-Admin(0000)".
493 fullname = substr(fullname, index(fullname, "-") + 1)
494 fullname = substr(fullname, 1, index(fullname, "(") - 1)
496 if (fullname ~ /,[^ ]/) {
497 # Some sites put comma-separated junk after the fullname.
498 # Remove it, but leave "Bill Gates, Jr" alone.
499 fullname = substr(fullname, 1, index(fullname, ",") - 1)
501 abbr = index(fullname, "&")
505 i = index(alphabet, a)
506 if (i) A = substr(ALPHABET, i, 1)
507 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
510 # Quote quotes and backslashes properly in full names.
511 # Do not use gsub; traditional awk lacks it.
515 p = index(rest, "\\")
516 q = index(rest, "\"")
523 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
524 rest = substr(rest, p+1)
527 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
533 initialize_fullname
=`
535 (getent passwd $authors) ||
538 for author in $authors
539 do NIS_PATH= nismatch $author passwd.org_dir
541 ypmatch $authors passwd
544 $AWK -F: "$awkscript"
545 `$initialize_fullname;;
549 # Function to print a single log line.
550 # We don't use awk functions, to stay compatible with old awk versions.
551 # 'Log' is the log message.
552 # 'files' contains the affected files.
555 # Following the GNU coding standards, rewrite
556 # * file: (function): comment
558 # * file (function): comment
559 if (Log ~ /^\([^)]*\):[\t\n ]/) {
561 filefunc = substr(Log, 1, i)
562 while ((j = index(filefunc, "\n"))) {
563 files = files " " substr(filefunc, 1, j-1)
564 filefunc = substr(filefunc, j+1)
566 files = files " " filefunc
567 Log = substr(Log, i+3)
570 # If "label: comment" is too long, break the line after the ":".
573 if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
576 printf "%s*%s:", indent_string, files
578 # Print each line of the log.
580 logline = substr(Log, 1, i-1)
581 if (logline ~ /[^'"$tab"' ]/) {
582 printf "%s%s\n", sep, logline
587 Log = substr(Log, i+1)
592 # Pattern to match the 'revision' line of rlog output.
593 rlog_revision_pattern
='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
598 hostname || uname -n || uuname -l || cat /etc/whoami
600 printf '%s\n' >&2 "$0: cannot deduce hostname"
607 domainname
=`(domainname) 2>/dev/null` &&
609 *.
*) hostname
=$hostname.
$domainname;;
615 # Process the rlog output, generating ChangeLog style entries.
617 # First, reformat the rlog output so that each line contains one log entry.
618 # Transliterate \n to SOH so that multiline entries fit on a single line.
619 # Discard irrelevant rlog output.
622 pository = "'"$pository"'"
626 if (pository != "") {
627 filename = substr($0, 11)
628 if (substr(filename, 1, length(pository)) == pository) {
629 filename = substr(filename, length(pository) + 1)
631 if (filename ~ /,v$/) {
632 filename = substr(filename, 1, length(filename) - 2)
634 if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
636 while (substr(filename, i, 1) != "/") i--
637 filename = substr(filename, 1, i - 6) substr(filename, i + 1)
642 /^Working file: / { if (repository == "") filename = substr($0, 15) }
643 /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
645 if (line ~ /'"$rlog_revision_pattern"'/) {
649 if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
652 # This is a traditional RCS format date YYYY/MM/DD.
653 # Replace "/"s with "-"s to get ISO format.
655 while ((i = index(date, "/")) != 0) {
656 newdate = newdate substr(date, 1, i-1) "-"
657 date = substr(date, i+1)
662 for (i = 3; i <= NF; i++) {
665 time = substr(time, 1, length(time) - 1)
670 if ($i == "author:") {
673 author = substr(author, 1, length(author) - 1)
678 printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
682 if (line ~ /^branches: /) { next }
683 if (line ~ /^(-----------*|===========*)$/) { print ""; next }
684 if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
687 printf "%s%s", line, SOH
691 # Now each line is of the form
692 # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
693 # where @ stands for an SOH (octal code 001),
694 # and each line of LOG is terminated by SOH instead of \n.
695 # Sort the log entries, first by date+time (in reverse order),
696 # then by author, then by log entry, and finally by file name and revision
698 sort -t"$SOH" $SORT_K_OPTIONS |
700 # Finally, reformat the sorted log entries.
704 revision = "'"$revision"'"
706 # Initialize the fullname and mailaddr associative arrays.
707 '"$initialize_fullname"'
708 '"$initialize_mailaddr"'
710 # Initialize indent string.
713 if (0 < '"$tabwidth"')
714 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
715 indent_string = indent_string "\t"
717 indent_string = indent_string " "
722 for (i = 6; i < NF; i++) newlog = newlog $i "\n"
724 # Ignore log entries prefixed by "#".
725 if (newlog ~ /^#/) { next }
727 if (Log != newlog || date != $3 || author != $5) {
729 # The previous log and this log differ.
732 if (date != "") '"$printlogline"'
734 # Logs that begin with "{clumpname} " should be grouped together,
735 # and the clumpname should be removed.
736 # Extract the new clumpname from the log header,
737 # and use it to decide whether to output a blank line.
740 if (date == "") sep = ""
741 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
742 i = index(newlog, "}")
743 newclumpname = substr(newlog, 1, i)
744 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
745 newlog = substr(newlog, i+1)
746 if (clumpname == newclumpname && date == $3 && author == $5) sep = ""
749 clumpname = newclumpname
751 # Get ready for the next log.
754 for (i in filesknown)
758 if (date != $3 || author != $5) {
759 # The previous date+author and this date+author differ.
766 if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
767 zone = " " substr(time, i)
769 # Print "date[ timezone] fullname <email address>".
770 # Get fullname and email address from associative arrays;
771 # default to author and author@hostname if not in arrays.
772 if (fullname[author])
773 auth = fullname[author]
776 printf "%s%s %s ", date, zone, auth
777 if (mailaddr[author])
778 printf "<%s>\n\n", mailaddr[author]
780 printf "<%s@%s>\n\n", author, "'"$hostname"'"
782 if (! filesknown[$1]) {
784 if (files == "") files = " " $1
785 else files = files ", " $1
786 if (revision && $2 != "?") files = files " " $2
790 # Print the last log.
801 exec rm -fr "$logdir"