3 # RCS to ChangeLog generator
5 # Generate a change log prefix from RCS files (perhaps in the CVS repository)
6 # and the ChangeLog (if any).
7 # Output the new prefix to standard output.
8 # You can edit this prefix by hand, and then prepend it to ChangeLog.
10 # Ignore log entries that start with `#'.
11 # Clump together log entries that start with `{topic} ',
12 # where `topic' contains neither white space nor `}'.
14 Help
='The default FILEs are the files registered under the working directory.
17 -c CHANGELOG Output a change log prefix to CHANGELOG (default ChangeLog).
18 -h HOSTNAME Use HOSTNAME in change log entries (default current host).
19 -i INDENT Indent change log lines by INDENT spaces (default 8).
20 -l LENGTH Try to limit log lines to LENGTH characters (default 79).
21 -R If no FILEs are given and RCS is used, recurse through working directory.
22 -r OPTION Pass OPTION to subsidiary log command.
23 -t TABWIDTH Tab stops are every TABWIDTH characters (default 8).
24 -u "LOGIN<tab>FULLNAME<tab>MAILADDR" Assume LOGIN has FULLNAME and MAILADDR.
25 -v Append RCS revision to file names in log lines.
27 --version Output version number.
29 Report bugs to <bug-gnu-emacs@prep.ai.mit.edu>.'
31 Id
='$Id: rcs2log,v 1.35 1996/11/03 17:09:27 eggert Exp eggert $'
33 # Copyright 1992, 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
35 # This program is free software; you can redistribute it and/or modify
36 # it under the terms of the GNU General Public License as published by
37 # the Free Software Foundation; either version 2, or (at your option)
40 # This program is distributed in the hope that it will be useful,
41 # but WITHOUT ANY WARRANTY; without even the implied warranty of
42 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 # GNU General Public License for more details.
45 # You should have received a copy of the GNU General Public License
46 # along with this program; see the file COPYING. If not, write to the
47 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
48 # Boston, MA 02111-1307, USA.
50 Copyright
='Copyright 1997 Free Software Foundation, Inc.
51 This program comes with NO WARRANTY, to the extent permitted by law.
52 You may redistribute copies of this program
53 under the terms of the GNU General Public License.
54 For more information about these matters, see the files named COPYING.
55 Author: Paul Eggert <eggert@twinsun.com>'
66 changelog
=ChangeLog
# change log file name
67 datearg
= # rlog date option
68 hostname
= # name of local host (if empty, will deduce it later)
69 indent
=8 # indent of log line
70 length
=79 # suggested max width of log line
71 logins
= # login names for people we know fullnames and mailaddrs of
72 loginFullnameMailaddrs
= # login<tab>fullname<tab>mailaddr triplets
73 logTZ
= # time zone for log dates (if empty, use local time)
74 recursive
= # t if we want recursive rlog
75 revision
= # t if we want revision numbers
76 rlog_options
= # options to pass to rlog
77 tabwidth
=8 # width of horizontal tab
82 -c) changelog
=${2?}; shift;;
83 -i) indent
=${2?}; shift;;
84 -h) hostname
=${2?}; shift;;
85 -l) length
=${2?}; shift;;
86 -[nu
]) # -n is obsolescent; it is replaced by -u.
88 -n) case ${2?}${3?}${4?} in
90 echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
93 loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$2$tab$3$tab$4
96 # If $2 is not tab-separated, use colon for separator.
99 echo >&2 "$0: -u '$2': newlines not allowed"
108 echo >&2 "$0: -u '$2': too many fields"
113 echo >&2 "$0: -u '$2': not enough fields"
116 loginFullnameMailaddrs
=$loginFullnameMailaddrs$nl$2
119 logins
=$logins$nl$login
121 -r) rlog_options
=$rlog_options$nl${2?}; shift;;
123 -t) tabwidth
=${2?}; shift;;
128 echo >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
130 -*) echo >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
141 m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
142 m[3]="Apr"; m[4]="May"; m[5]="Jun"
143 m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
144 m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
148 # Put rlog output into $rlogout.
150 # If no rlog options are given,
151 # log the revisions checked in since the first ChangeLog entry.
152 # Since ChangeLog is only by date, some of these revisions may be duplicates of
153 # what's already in ChangeLog; it's the user's responsibility to remove them.
154 case $rlog_options in
156 if test -s "$changelog"
159 /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
164 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
165 # old-fashioned date and time (Emacs 19.31 and earlier)
168 for (i=0; i<=11; i++) if (m[i] == $2) break
170 printf "%d-%02d-%02d\n", year, i+1, dd
174 d
=`$AWK "$e" <"$changelog"` ||
exit
181 # Use TZ specified by ChangeLog local variable, if any.
182 if test -s "$changelog"
185 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
188 /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
192 logTZ
=`tail "$changelog" | sed -n "$extractTZ"`
194 ?
*) TZ
=$logTZ; export TZ
198 # If CVS is in use, examine its repository, not the normal RCS files.
199 if test ! -f CVS
/Repository
205 repository
=`sed 1q <CVS/Repository` ||
exit
206 test ! -f CVS
/Root || CVSROOT
=`cat <CVS/Root` ||
exit
215 *) repository
=${CVSROOT?}/$repository
217 if test ! -d "$repository"
219 echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
225 # Use $rlog's -zLT option, if $rlog supports it.
226 case `$rlog -zLT 2>&1` in
228 *) rlog_options
=-zLT$nl$rlog_options
231 # With no arguments, examine all files under the RCS directory.
240 RCSdirs
=`find . -name RCS -type d -print`
241 filesFromRCSfiles
='s|,v$||; s|/RCS/|/|; s|^\./||'
245 ?*) find $RCSdirs -type f -print
247 find . -name '*,v' -print
250 sed "$filesFromRCSfiles"
254 for file in RCS
/.
* RCS
/* .
*,v
*,v
257 RCS
/. | RCS
/..
) continue;;
258 RCS
/.\
* | RCS
/\
* | .\
*,v | \
*,v
) test -f "$file" ||
continue
272 llogout
=$TMPDIR/rcs2log$
$l
273 rlogout
=$TMPDIR/rcs2log$
$r
275 trap "rm -f $llogout $rlogout; exit 1" 0
278 ?
*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogout;;
279 '') $rlog $rlog_options ${1+"$@"} >$rlogout
283 # Get the full name of each author the logs mention, and set initialize_fullname
284 # to awk code that initializes the `fullname' awk associative array.
285 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
286 # you have to fix the resulting output by hand.
291 case $loginFullnameMailaddrs in
293 case $loginFullnameMailaddrs in
295 sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
296 $loginFullnameMailaddrs
298 loginFullnameMailaddrs
=`cat $llogout`
303 for loginFullnameMailaddr
in $loginFullnameMailaddrs
305 case $loginFullnameMailaddr in
309 set x
$loginFullnameMailaddr
313 initialize_fullname
="$initialize_fullname
314 fullname[\"$login\"] = \"$fullname\""
315 initialize_mailaddr
="$initialize_mailaddr
316 mailaddr[\"$login\"] = \"$mailaddr\""
322 ?
*) sort -u -o $llogout <<EOF || exit
326 output_authors
='/^date: / {
327 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 ~ /^[^;]*;$/) {
328 print substr($5, 1, length($5)-1)
332 $AWK "$output_authors" <$rlogout |
335 ?*) sort -u | comm -23 - $llogout
340 cat >$llogout <<EOF || exit
343 initialize_author_script
='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
344 initialize_author
=`sed -e "$initialize_author_script" <$llogout`
347 alphabet = "abcdefghijklmnopqrstuvwxyz"
348 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
349 '"$initialize_author"'
354 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
355 # Remove the junk from fullnames like "0000-Admin(0000)".
356 fullname = substr(fullname, index(fullname, "-") + 1)
357 fullname = substr(fullname, 1, index(fullname, "(") - 1)
359 if (fullname ~ /,[^ ]/) {
360 # Some sites put comma-separated junk after the fullname.
361 # Remove it, but leave "Bill Gates, Jr" alone.
362 fullname = substr(fullname, 1, index(fullname, ",") - 1)
364 abbr = index(fullname, "&")
368 i = index(alphabet, a)
369 if (i) A = substr(ALPHABET, i, 1)
370 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
373 # Quote quotes and backslashes properly in full names.
374 # Do not use gsub; traditional awk lacks it.
378 p = index(rest, "\\")
379 q = index(rest, "\"")
386 quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
387 rest = substr(rest, p+1)
390 printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
396 initialize_fullname
=`
399 for author in $authors
400 do nismatch $author passwd.org_dir
402 ypmatch $authors passwd
404 $AWK -F: "$awkscript"
405 `$initialize_fullname
409 # Function to print a single log line.
410 # We don't use awk functions, to stay compatible with old awk versions.
411 # `Log' is the log message (with \n replaced by \r).
412 # `files' contains the affected files.
415 # Following the GNU coding standards, rewrite
416 # * file: (function): comment
418 # * file (function): comment
419 if (Log ~ /^\([^)]*\): /) {
421 files = files " " substr(Log, 1, i)
422 Log = substr(Log, i+3)
425 # If "label: comment" is too long, break the line after the ":".
427 if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, CR)) sep = "\n" indent_string
430 printf "%s*%s:", indent_string, files
432 # Print each line of the log, transliterating \r to \n.
433 while ((i = index(Log, CR)) != 0) {
434 logline = substr(Log, 1, i-1)
435 if (logline ~ /[^'"$tab"' ]/) {
436 printf "%s%s\n", sep, logline
441 Log = substr(Log, i+1)
445 # Pattern to match the `revision' line of rlog output.
446 rlog_revision_pattern
='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
451 hostname || uname -n || uuname -l || cat /etc/whoami
453 echo >&2 "$0: cannot deduce hostname"
460 domainname
=`(domainname) 2>/dev/null` &&
462 *.
*) hostname
=$hostname.
$domainname
468 # Process the rlog output, generating ChangeLog style entries.
470 # First, reformat the rlog output so that each line contains one log entry.
471 # Transliterate \n to \r so that multiline entries fit on a single line.
472 # Discard irrelevant rlog output.
474 BEGIN { repository = "'"$repository"'" }
476 if (repository != "") {
478 if (substr(filename, 1, length(repository) + 1) == repository "/") {
479 filename = substr(filename, length(repository) + 2)
481 if (filename ~ /,v$/) {
482 filename = substr(filename, 1, length(filename) - 2)
484 if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
486 while (substr(filename, i, 1) != "/") i--
487 filename = substr(filename, 1, i - 6) substr(filename, i + 1)
492 /^Working file:/ { if (repository == "") filename = $3 }
493 /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
494 if ($0 ~ /'"$rlog_revision_pattern"'/) {
498 if ($0 ~ /^date: [0-9][- +\/0-9:]*;/) {
501 # This is a traditional RCS format date YYYY/MM/DD.
502 # Replace "/"s with "-"s to get ISO format.
504 while ((i = index(date, "/")) != 0) {
505 newdate = newdate substr(date, 1, i-1) "-"
506 date = substr(date, i+1)
510 time = substr($3, 1, length($3) - 1)
511 author = substr($5, 1, length($5)-1)
512 printf "%s %s %s %s %s %c", filename, rev, date, time, author, 13
516 if ($0 ~ /^branches: /) { next }
517 if ($0 ~ /^(-----------*|===========*)$/) { print ""; next }
518 if ($0 == "Initial revision" || $0 ~ /^file .+ was initially added on branch .+\.$/) {
521 printf "%s%c", $0, 13
525 # Now each line is of the form
526 # FILENAME REVISION YYYY-MM-DD HH:MM:SS[+-TIMEZONE] AUTHOR \rLOG
527 # where \r stands for a carriage return,
528 # and each line of the log is terminated by \r instead of \n.
529 # Sort the log entries, first by date+time (in reverse order),
530 # then by author, then by log entry, and finally by file name and revision
534 # Finally, reformat the sorted log entries.
538 revision = "'"$revision"'"
540 # Some awk variants do not understand "\r" or "\013", so we have to
541 # put a carriage return directly in the file.
542 CR="
" # <-- There is a single CR between the " chars here.
544 # Initialize the fullname and mailaddr associative arrays.
545 '"$initialize_fullname"'
546 '"$initialize_mailaddr"'
548 # Initialize indent string.
551 if (0 < '"$tabwidth"')
552 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
553 indent_string = indent_string "\t"
555 indent_string = indent_string " "
559 newlog = substr($0, 1 + index($0, CR))
561 # Ignore log entries prefixed by "#".
562 if (newlog ~ /^#/) { next }
564 if (Log != newlog || date != $3 || author != $5) {
566 # The previous log and this log differ.
569 if (date != "") '"$printlogline"'
571 # Logs that begin with "{clumpname} " should be grouped together,
572 # and the clumpname should be removed.
573 # Extract the new clumpname from the log header,
574 # and use it to decide whether to output a blank line.
577 if (date == "") sep = ""
578 if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
579 i = index(newlog, "}")
580 newclumpname = substr(newlog, 1, i)
581 while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
582 newlog = substr(newlog, i+1)
583 if (clumpname == newclumpname) sep = ""
586 clumpname = newclumpname
588 # Get ready for the next log.
591 for (i in filesknown)
595 if (date != $3 || author != $5) {
596 # The previous date+author and this date+author differ.
603 if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
604 zone = " " substr(time, i)
606 # Print "date[ timezone] fullname <email address>".
607 # Get fullname and email address from associative arrays;
608 # default to author and author@hostname if not in arrays.
609 if (fullname[author])
610 auth = fullname[author]
613 printf "%s%s %s ", date, zone, auth
614 if (mailaddr[author])
615 printf "<%s>\n\n", mailaddr[author]
617 printf "<%s@%s>\n\n", author, "'"$hostname"'"
619 if (! filesknown[$1]) {
621 if (files == "") files = " " $1
622 else files = files ", " $1
623 if (revision && $2 != "?") files = files " " $2
627 # Print the last log.
638 exec rm -f $llogout $rlogout