3 # RCS to ChangeLog generator
5 # Generate a change log prefix from RCS files and the ChangeLog (if any).
6 # Output the new prefix to standard output.
7 # You can edit this prefix by hand, and then prepend it to ChangeLog.
9 # Ignore log entries that start with `#'.
10 # Clump together log entries that start with `{topic} ',
11 # where `topic' contains neither white space nor `}'.
13 # Author: Paul Eggert <eggert@twinsun.com>
15 # $Id: rcs2log,v 1.29 1996/08/24 21:11:14 erik Exp eggert $
17 # Copyright 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
19 # This program is free software; you can redistribute it and/or modify
20 # it under the terms of the GNU General Public License as published by
21 # the Free Software Foundation; either version 2, or (at your option)
24 # This program is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; see the file COPYING. If not, write to the
31 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
32 # Boston, MA 02111-1307, USA.
43 changelog
=ChangeLog
# change log file name
44 datearg
= # rlog date option
45 hostname
= # name of local host (if empty, will deduce it later)
46 indent
=8 # indent of log line
47 length
=79 # suggested max width of log line
48 logins
= # login names for people we know fullnames and mailaddrs of
49 loginFullnameMailaddrs
= # login<tab>fullname<tab>mailaddr triplets
50 logTZ
= # time zone for log dates (if empty, use local time)
51 recursive
= # t if we want recursive rlog
52 revision
= # t if we want revision numbers
53 rlog_options
= # options to pass to rlog
54 tabwidth
=8 # width of horizontal tab
59 -c) changelog
=${2?}; shift;;
60 -i) indent
=${2?}; shift;;
61 -h) hostname
=${2?}; shift;;
62 -l) length
=${2?}; shift;;
63 -[nu
]) # -n is obsolescent; it is replaced by -u.
65 -n) case ${2?}${3?}${4?} in
67 echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
70 loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$2$tab$3$tab$4
73 # If $2 is not tab-separated, use colon for separator.
76 echo >&2 "$0: -u '$2': newlines not allowed"
85 echo >&2 "$0: -u '$2': too many fields"
90 echo >&2 "$0: -u '$2': not enough fields"
93 loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$2
96 logins
=$logins$nl$login
98 -r) rlog_options
=$rlog_options$nl${2?}; shift;;
100 -t) tabwidth
=${2?}; shift;;
102 -*) echo >&2 "$0: usage: $0 [options] [file ...]
104 [-c changelog] [-h hostname] [-i indent] [-l length] [-R]
105 [-r rlog_option] [-t tabwidth] [-v]
106 [-u 'login<TAB>fullname<TAB>mailaddr']..."
114 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
115 m[3]="Apr"; m[4]="May"; m[5]="Jun"
116 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
117 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
121 # Put rlog output into $rlogout.
123 # If no rlog options are given,
124 # log the revisions checked in since the first ChangeLog entry.
125 # Since ChangeLog is only by date, some of these revisions may be duplicates of
126 # what's already in ChangeLog; it's the user's responsibility to remove them.
127 case $rlog_options in
130 if test -s "$changelog"
133 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
138 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
139 # old-fashioned date and time (Emacs 19.31 and earlier)
142 for (i=0; i<=11; i++) if (m[i] == $2) break
144 printf "%d-%02d-%02d\n", year, i+1, dd
148 d
=`$AWK "$e" <"$changelog"` ||
exit
156 # Use rlog's -zLT option, if rlog supports it.
157 case `rlog -zLT 2>&1` in
158 *'unknown option'*) ;;
159 *) rlog_options
=-zLT$nl$rlog_options
162 # Use TZ specified by ChangeLog local variable, if any.
163 if test -s "$changelog"
166 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
169 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
173 logTZ
=`tail "$changelog" | sed -n "$extractTZ"`
175 ?
*) TZ
=$logTZ; export TZ
179 # If CVS is in use, examine its repository, not the normal RCS files.
180 if test ! -f CVS
/Repository
186 repository
=`sed 1q <CVS/Repository` ||
exit
187 test ! -f CVS
/Root || CVSROOT
=`cat <CVS/Root` ||
exit
196 *) repository
=${CVSROOT?}/$repository
198 if test ! -d "$repository"
200 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
206 # With no arguments, examine all files under the RCS directory.
215 RCSdirs
=`find . -name RCS -type d -print`
216 filesFromRCSfiles
='s|,v$||; s|/RCS/|/|; s|^\./||'
220 ?*) find $RCSdirs -type f -print
222 find . -name '*,v' -print
225 sed "$filesFromRCSfiles"
229 for file in RCS
/.
* RCS
/* .
*,v
*,v
232 RCS
/. | RCS
/..
) continue;;
233 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue
247 llogout
=$TMPDIR/rcs2log$
$l
248 rlogout
=$TMPDIR/rcs2log$
$r
250 trap "rm -f $llogout $rlogout; exit 1" 0
253 ?
*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogout;;
254 '') $rlog $rlog_options ${1+"$@"} >$rlogout
258 # Get the full name of each author the logs mention, and set initialize_fullname
259 # to awk code that initializes the `fullname' awk associative array.
260 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
261 # you have to fix the resulting output by hand.
266 case $loginFullnameMailaddrs in
268 case $loginFullnameMailaddrs in
270 sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
271 $loginFullnameMailaddrs
273 loginFullnameMailaddrs
=`cat $llogout`
278 for loginFullnameMailaddr
in $loginFullnameMailaddrs
280 case $loginFullnameMailaddr in
284 set x
$loginFullnameMailaddr
288 initialize_fullname
="$initialize_fullname
289 fullname[\"$login\"] = \"$fullname\""
290 initialize_mailaddr
="$initialize_mailaddr
291 mailaddr[\"$login\"] = \"$mailaddr\""
297 ?
*) sort -u -o $llogout <<EOF || exit
301 output_authors
='/^date: / {
302 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 ~ /^[^;]*;$/) {
303 print substr($5, 1, length($5)-1)
307 $AWK "$output_authors" <$rlogout |
310 ?*) sort -u | comm -23 - $llogout
315 cat >$llogout <<EOF || exit
318 initialize_author_script
='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
319 initialize_author
=`sed -e "$initialize_author_script" <$llogout`
322 alphabet = "abcdefghijklmnopqrstuvwxyz"
323 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
324 '"$initialize_author"'
329 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
330 # Remove the junk from fullnames like "0000-Admin(0000)".
331 fullname = substr(fullname, index(fullname, "-") + 1)
332 fullname = substr(fullname, 1, index(fullname, "(") - 1)
334 if (fullname ~ /,[^ ]/) {
335 # Some sites put comma-separated junk after the fullname.
336 # Remove it, but leave "Bill Gates, Jr" alone.
337 fullname = substr(fullname, 1, index(fullname, ",") - 1)
339 abbr = index(fullname, "&")
343 i = index(alphabet, a)
344 if (i) A = substr(ALPHABET, i, 1)
345 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
348 # Quote quotes and backslashes properly in full names.
349 # Do not use gsub; traditional awk lacks it.
353 p = index(rest, "\\")
354 q = index(rest, "\"")
361 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
362 rest = substr(rest, p+1)
365 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
371 initialize_fullname
=`
374 for author in $authors
375 do nismatch $author passwd.org_dir
377 ypmatch $authors passwd
379 $AWK -F: "$awkscript"
380 `$initialize_fullname
384 # Function to print a single log line.
385 # We don't use awk functions, to stay compatible with old awk versions.
386 # `Log' is the log message (with \n replaced by \r).
387 # `files' contains the affected files.
390 # Following the GNU coding standards, rewrite
391 # * file: (function): comment
393 # * file (function): comment
394 if (Log ~ /^\([^)]*\): /) {
396 files = files " " substr(Log, 1, i)
397 Log = substr(Log, i+3)
400 # If "label: comment" is too long, break the line after the ":".
402 if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, CR)) sep = "\n" indent_string
405 printf "%s*%s:", indent_string, files
407 # Print each line of the log, transliterating \r to \n.
408 while ((i = index(Log, CR)) != 0) {
409 logline = substr(Log, 1, i-1)
410 if (logline ~ /[^'"$tab"' ]/) {
411 printf "%s%s\n", sep, logline
416 Log = substr(Log, i+1)
420 # Pattern to match the `revision' line of rlog output.
421 rlog_revision_pattern
='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
426 hostname || uname -n || uuname -l || cat /etc/whoami
428 echo >&2 "$0: cannot deduce hostname"
435 domainname
=`(domainname) 2>/dev/null` &&
437 *.
*) hostname
=$hostname.
$domainname
443 # Process the rlog output, generating ChangeLog style entries.
445 # First, reformat the rlog output so that each line contains one log entry.
446 # Transliterate \n to \r so that multiline entries fit on a single line.
447 # Discard irrelevant rlog output.
449 BEGIN { repository = "'"$repository"'" }
451 if (repository != "") {
453 if (substr(filename, 1, length(repository) + 1) == repository "/") {
454 filename = substr(filename, length(repository) + 2)
456 if (filename ~ /,v$/) {
457 filename = substr(filename, 1, length(filename) - 2)
462 /^Working file:/ { if (repository == "") filename = $3 }
463 /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
464 if ($0 ~ /'"$rlog_revision_pattern"'/) {
468 if ($0 ~ /^date: [0-9][- +\/0-9:]*;/) {
471 # This is a traditional RCS format date YYYY/MM/DD.
472 # Replace "/"s with "-"s to get ISO format.
474 while ((i = index(date, "/")) != 0) {
475 newdate = newdate substr(date, 1, i-1) "-"
476 date = substr(date, i+1)
480 time = substr($3, 1, length($3) - 1)
481 author = substr($5, 1, length($5)-1)
482 printf "%s %s %s %s %s %c", filename, rev, date, time, author, 13
486 if ($0 ~ /^branches: /) { next }
487 if ($0 ~ /^(-----------*|===========*)$/) { print ""; next }
488 printf "%s%c", $0, 13
492 # Now each line is of the form
493 # FILENAME REVISION YYYY-MM-DD HH:MM:SS[+-TIMEZONE] AUTHOR \rLOG
494 # where \r stands for a carriage return,
495 # and each line of the log is terminated by \r instead of \n.
496 # Sort the log entries, first by date+time (in reverse order),
497 # then by author, then by log entry, and finally by file name and revision
501 # Finally, reformat the sorted log entries.
505 revision = "'"$revision"'"
507 # Some awk variants do not understand "\r" or "\013", so we have to
508 # put a carriage return directly in the file.
509 CR="
" # <-- There is a single CR between the " chars here.
511 # Initialize the fullname and mailaddr associative arrays.
512 '"$initialize_fullname"'
513 '"$initialize_mailaddr"'
515 # Initialize indent string.
518 if (0 < '"$tabwidth"')
519 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
520 indent_string = indent_string "\t"
522 indent_string = indent_string " "
526 newlog = substr($0, 1 + index($0, CR))
528 # Ignore log entries prefixed by "#".
529 if (newlog ~ /^#/) { next }
531 if (Log != newlog || date != $3 || author != $5) {
533 # The previous log and this log differ.
536 if (date != "") '"$printlogline"'
538 # Logs that begin with "{clumpname} " should be grouped together,
539 # and the clumpname should be removed.
540 # Extract the new clumpname from the log header,
541 # and use it to decide whether to output a blank line.
544 if (date == "") sep = ""
545 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
546 i = index(newlog, "}")
547 newclumpname = substr(newlog, 1, i)
548 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
549 newlog = substr(newlog, i+1)
550 if (clumpname == newclumpname) sep = ""
553 clumpname = newclumpname
555 # Get ready for the next log.
558 for (i in filesknown)
562 if (date != $3 || author != $5) {
563 # The previous date+author and this date+author differ.
570 if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
571 zone = " " substr(time, i)
573 # Print "date[ timezone] fullname <email address>".
574 # Get fullname and email address from associative arrays;
575 # default to author and author@hostname if not in arrays.
576 if (fullname[author])
577 auth = fullname[author]
580 printf "%s%s %s ", date, zone, auth
581 if (mailaddr[author])
582 printf "<%s>\n\n", mailaddr[author]
584 printf "<%s@%s>\n\n", author, "'"$hostname"'"
586 if (! filesknown[$1]) {
588 if (files == "") files = " " $1
589 else files = files ", " $1
590 if (revision && $2 != "?") files = files " " $2
594 # Print the last log.
605 exec rm -f $llogout $rlogout