rcs2log 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. #! /bin/sh
  2. # RCS to ChangeLog generator
  3. # Copyright (C) 1992-1998, 2001-2012 Free Software Foundation, Inc.
  4. # Author: Paul Eggert <eggert@twinsun.com>
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. Copyright='Copyright (C) 2012 Free Software Foundation, Inc.
  16. This program comes with NO WARRANTY, to the extent permitted by law.
  17. You may redistribute copies of this program
  18. under the terms of the GNU General Public License.
  19. For more information about these matters, see the files named COPYING.
  20. Author: Paul Eggert <eggert@twinsun.com>'
  21. Help='
  22. Generate ChangeLog entries from RCS files (perhaps in a CVS repository)
  23. and the ChangeLog file (if any). An RCS file typically has a name
  24. ending in ",v", and represents the entire history of a file that is
  25. under revision control. The ChangeLog file logs entries for changes,
  26. in reverse chronological order.
  27. Generate entries for changes entered into RCS (or CVS) more recently
  28. than the newest existing entry in the ChangeLog file. You can then
  29. edit these entries by hand, and prepend them to the ChangeLog file.
  30. Output the resulting ChangeLog entries to standard output.
  31. Each entry looks something like this:
  32. 2004-04-17 Paul Eggert <eggert@gnu.org>
  33. * rcs2log (Help): Clarify wording of the usage message.
  34. Problem reported by Alan Mackenzie in
  35. <http://mail.gnu.org/archive/html/bug-gnu-emacs/2004-04/msg00188.html>.
  36. ChangeLog entries contain the current date, full name, email address
  37. including hostname, the name of the affected file, and commentary.
  38. RCS and CVS logs lack full names and email addresses, so they are
  39. inferred from login names using a heuristic that can be overridden
  40. via the -u option.
  41. Ignore log entries that start with "#".
  42. Clump together log entries that start with "{topic} ",
  43. where "topic" contains neither white space nor "}".
  44. If no FILE is specified, use all files under the working directory
  45. that are maintained under version control.
  46. Options:
  47. -c FILE Output ChangeLog entries for FILE (default ChangeLog).
  48. -h HOSTNAME Use HOSTNAME in change log entries (default current host).
  49. -i INDENT Indent change log lines by INDENT spaces (default 8).
  50. -l LENGTH Try to limit log lines to LENGTH characters (default 79).
  51. -L FILE Use FILE (same format as "rlog") for source of logs.
  52. -R If no FILEs are given and RCS is used, recurse through working directory.
  53. -r OPTION Pass OPTION to subsidiary command (either "rlog" or "cvs -q log").
  54. -t TABWIDTH Tab stops are every TABWIDTH characters (default 8).
  55. -u "LOGIN<tab>FULLNAME<tab>EMAILADDR" LOGIN has FULLNAME and EMAILADDR.
  56. -v Append RCS revision to file names in log lines.
  57. --help Output help.
  58. --version Output version number.
  59. Report bugs to <bug-gnu-emacs@gnu.org>.'
  60. Id='$Id$'
  61. # Use the traditional C locale.
  62. LANG=C
  63. LANGUAGE=C
  64. LC_ALL=C
  65. LC_COLLATE=C
  66. LC_CTYPE=C
  67. LC_MESSAGES=C
  68. LC_NUMERIC=C
  69. LC_TIME=C
  70. export LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME
  71. # These variables each contain a single ASCII character.
  72. # Unfortunately, there's no portable way of writing these characters
  73. # in older Unix implementations, other than putting them directly into
  74. # this text file.
  75. SOH='' # SOH, octal code 001
  76. tab=' '
  77. nl='
  78. '
  79. # Parse options.
  80. # defaults
  81. AWK=${AWK-awk}
  82. TMPDIR=${TMPDIR-/tmp}
  83. changelog=ChangeLog # change log file name
  84. datearg= # rlog date option
  85. hostname= # name of local host (if empty, will deduce it later)
  86. indent=8 # indent of log line
  87. length=79 # suggested max width of log line
  88. logins= # login names for people we know fullnames and mailaddrs of
  89. loginFullnameMailaddrs= # login<tab>fullname<tab>mailaddr triplets
  90. logTZ= # time zone for log dates (if empty, use local time)
  91. recursive= # t if we want recursive rlog
  92. revision= # t if we want revision numbers
  93. rlog_options= # options to pass to rlog
  94. rlogfile= # log file to read from
  95. tabwidth=8 # width of horizontal tab
  96. while :
  97. do
  98. case $1 in
  99. -c) changelog=${2?}; shift;;
  100. -i) indent=${2?}; shift;;
  101. -h) hostname=${2?}; shift;;
  102. -l) length=${2?}; shift;;
  103. -L) rlogfile=${2?}; shift;;
  104. -[nu]) # -n is obsolescent; it is replaced by -u.
  105. case $1 in
  106. -n) case ${2?}${3?}${4?} in
  107. *"$tab"* | *"$nl"*)
  108. echo >&2 "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
  109. exit 1;;
  110. esac
  111. login=$2
  112. lfm=$2$tab$3$tab$4
  113. shift; shift; shift;;
  114. -u)
  115. # If $2 is not tab-separated, use colon for separator.
  116. case ${2?} in
  117. *"$nl"*)
  118. echo >&2 "$0: -u '$2': newlines not allowed"
  119. exit 1;;
  120. *"$tab"*)
  121. t=$tab;;
  122. *)
  123. t=':';;
  124. esac
  125. case $2 in
  126. *"$t"*"$t"*"$t"*)
  127. echo >&2 "$0: -u '$2': too many fields"
  128. exit 1;;
  129. *"$t"*"$t"*)
  130. uf="[^$t]*$t" # An unselected field, followed by a separator.
  131. sf="\\([^$t]*\\)" # The selected field.
  132. login=`expr "X$2" : "X$sf"`
  133. lfm="$login$tab"`
  134. expr "X$2" : "$uf$sf"
  135. `"$tab"`
  136. expr "X$2" : "$uf$uf$sf"
  137. `;;
  138. *)
  139. echo >&2 "$0: -u '$2': not enough fields"
  140. exit 1;;
  141. esac
  142. shift;;
  143. esac
  144. case $logins in
  145. '') logins=$login;;
  146. ?*) logins=$logins$nl$login;;
  147. esac
  148. case $loginFullnameMailaddrs in
  149. '') loginFullnameMailaddrs=$lfm;;
  150. ?*) loginFullnameMailaddrs=$loginFullnameMailaddrs$nl$lfm;;
  151. esac;;
  152. -r)
  153. case $rlog_options in
  154. '') rlog_options=${2?};;
  155. ?*) rlog_options=$rlog_options$nl${2?};;
  156. esac
  157. shift;;
  158. -R) recursive=t;;
  159. -t) tabwidth=${2?}; shift;;
  160. -v) revision=t;;
  161. --version)
  162. set $Id
  163. rcs2logVersion=$3
  164. echo >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
  165. exit 0;;
  166. -*) echo >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
  167. case $1 in
  168. --help) exit 0;;
  169. *) exit 1;;
  170. esac;;
  171. *) break;;
  172. esac
  173. shift
  174. done
  175. month_data='
  176. m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
  177. m[3]="Apr"; m[4]="May"; m[5]="Jun"
  178. m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
  179. m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
  180. '
  181. logdir=$TMPDIR/rcs2log$$
  182. llogout=$logdir/l
  183. trap exit 1 2 13 15
  184. trap "rm -fr $logdir 2>/dev/null" 0
  185. (umask 077 && exec mkdir $logdir) || exit
  186. # If no rlog-format log file is given, generate one into $rlogfile.
  187. case $rlogfile in
  188. '')
  189. rlogfile=$logdir/r
  190. # If no rlog options are given,
  191. # log the revisions checked in since the first ChangeLog entry.
  192. # Since ChangeLog is only by date, some of these revisions may be
  193. # duplicates of what's already in ChangeLog; it's the user's
  194. # responsibility to remove them.
  195. case $rlog_options in
  196. '')
  197. if test -s "$changelog"
  198. then
  199. e='
  200. /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
  201. # ISO 8601 date
  202. print $1
  203. exit
  204. }
  205. /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
  206. # old-fashioned date and time (Emacs 19.31 and earlier)
  207. '"$month_data"'
  208. year = $5
  209. for (i=0; i<=11; i++) if (m[i] == $2) break
  210. dd = $3
  211. printf "%d-%02d-%02d\n", year, i+1, dd
  212. exit
  213. }
  214. '
  215. d=`$AWK "$e" <"$changelog"` || exit
  216. case $d in
  217. ?*) datearg="-d>$d";;
  218. esac
  219. fi;;
  220. esac
  221. # Use TZ specified by ChangeLog local variable, if any.
  222. if test -s "$changelog"
  223. then
  224. extractTZ='
  225. /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
  226. s//\1/; p; q
  227. }
  228. /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
  229. s//UTC0/; p; q
  230. }
  231. '
  232. logTZ=`tail "$changelog" | sed -n "$extractTZ"`
  233. case $logTZ in
  234. ?*) TZ=$logTZ; export TZ;;
  235. esac
  236. fi
  237. # If CVS is in use, examine its repository, not the normal RCS files.
  238. if test ! -f CVS/Repository
  239. then
  240. rlog=rlog
  241. repository=
  242. else
  243. rlog='cvs -q log'
  244. repository=`sed 1q <CVS/Repository` || exit
  245. test ! -f CVS/Root || CVSROOT=`cat <CVS/Root` || exit
  246. pository=
  247. case $CVSROOT in
  248. /* | :fork:* | :local:*) ;;
  249. */*)
  250. # remote repository
  251. pository=`expr "X$CVSROOT" : '[^/]*\(.*\)'`;;
  252. esac
  253. case $pository in
  254. '')
  255. # local repository
  256. case $repository in
  257. /*) ;;
  258. *)
  259. repository=${CVSROOT?}/$repository
  260. case $repository in
  261. :fork:* | :local:*)
  262. repository=`expr "$repository" : ':[^:]*:\(.*\)'`;;
  263. esac;;
  264. esac
  265. if test ! -d "$repository"
  266. then
  267. echo >&2 "$0: $repository: bad repository (see CVS/Repository)"
  268. exit 1
  269. fi
  270. pository=$repository;;
  271. esac
  272. # Ensure that $pository ends in exactly one slash.
  273. while :
  274. do
  275. case $pository in
  276. *//) pository=`expr "X$pository" : 'X\(.*\)/'`;;
  277. */) break;;
  278. *) pository=$pository/; break;;
  279. esac
  280. done
  281. # If no rlog options are given, and if we are in a tagged CVS branch,
  282. # log only the changes in that branch.
  283. case $rlog_options in
  284. '')
  285. if test -f CVS/Tag
  286. then
  287. CVSTAG=`cat <CVS/Tag` || exit
  288. case $CVSTAG in
  289. T?*)
  290. rlog_options=-r`expr "$CVSTAG" : 'T\(.*\)'`;;
  291. *)
  292. echo >&2 "$0: invalid CVS/Tag"; exit 1;;
  293. esac
  294. fi;;
  295. esac
  296. fi
  297. # Use $rlog's -zLT option, if $rlog supports it.
  298. case `$rlog -zLT 2>&1` in
  299. *' option'*) ;;
  300. *)
  301. case $rlog_options in
  302. '') rlog_options=-zLT;;
  303. ?*) rlog_options=-zLT$nl$rlog_options;;
  304. esac;;
  305. esac
  306. # With no arguments, examine all files under the RCS directory.
  307. case $# in
  308. 0)
  309. case $repository in
  310. '')
  311. oldIFS=$IFS
  312. IFS=$nl
  313. case $recursive in
  314. t)
  315. RCSdirs=`find . -name RCS -type d -print`
  316. filesFromRCSfiles='s|,v$||; s|/RCS/|/|; s|^\./||'
  317. files=`
  318. {
  319. case $RCSdirs in
  320. ?*) find $RCSdirs \
  321. -type f \
  322. ! -name '*_' \
  323. ! -name ',*,' \
  324. ! -name '.*_' \
  325. ! -name .rcsfreeze.log \
  326. ! -name .rcsfreeze.ver \
  327. -print;;
  328. esac
  329. find . -name '*,v' -print
  330. } |
  331. sort -u |
  332. sed "$filesFromRCSfiles"
  333. `;;
  334. *)
  335. files=
  336. for file in RCS/.* RCS/* .*,v *,v
  337. do
  338. case $file in
  339. RCS/. | RCS/.. | RCS/,*, | RCS/*_) continue;;
  340. RCS/.rcsfreeze.log | RCS/.rcsfreeze.ver) continue;;
  341. RCS/.\* | RCS/\* | .\*,v | \*,v) test -f "$file" || continue;;
  342. RCS/*,v | RCS/.*,v) ;;
  343. RCS/* | RCS/.*) test -f "$file" || continue;;
  344. esac
  345. case $files in
  346. '') files=$file;;
  347. ?*) files=$files$nl$file;;
  348. esac
  349. done
  350. case $files in
  351. '') exit 0;;
  352. esac;;
  353. esac
  354. set x $files
  355. shift
  356. IFS=$oldIFS;;
  357. esac;;
  358. esac
  359. case $datearg in
  360. ?*) $rlog $rlog_options "$datearg" ${1+"$@"} >$rlogfile;;
  361. '') $rlog $rlog_options ${1+"$@"} >$rlogfile;;
  362. esac || exit;;
  363. esac
  364. # Prefer the POSIX-style -k options, since POSIX 1003.1-2001 prohibits
  365. # support for the traditional-style +M -N options.
  366. SORT_K_OPTIONS='-k 3,4r -k 5 -k 1'
  367. sort $SORT_K_OPTIONS </dev/null 2>/dev/null || SORT_K_OPTIONS='+2 -4r +4 +0'
  368. # Get the full name of each author the logs mention, and set initialize_fullname
  369. # to awk code that initializes the `fullname' awk associative array.
  370. # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
  371. # you have to fix the resulting output by hand.
  372. initialize_fullname=
  373. initialize_mailaddr=
  374. case $loginFullnameMailaddrs in
  375. ?*)
  376. case $loginFullnameMailaddrs in
  377. *\"* | *\\*)
  378. sed 's/["\\]/\\&/g' >$llogout <<EOF || exit
  379. $loginFullnameMailaddrs
  380. EOF
  381. loginFullnameMailaddrs=`cat $llogout`;;
  382. esac
  383. oldIFS=$IFS
  384. IFS=$nl
  385. for loginFullnameMailaddr in $loginFullnameMailaddrs
  386. do
  387. IFS=$tab
  388. set x $loginFullnameMailaddr
  389. login=$2
  390. fullname=$3
  391. mailaddr=$4
  392. initialize_fullname="$initialize_fullname
  393. fullname[\"$login\"] = \"$fullname\""
  394. initialize_mailaddr="$initialize_mailaddr
  395. mailaddr[\"$login\"] = \"$mailaddr\""
  396. done
  397. IFS=$oldIFS;;
  398. esac
  399. case $logins in
  400. ?*)
  401. sort -u -o $llogout <<EOF
  402. $logins
  403. EOF
  404. ;;
  405. '')
  406. : ;;
  407. esac >$llogout || exit
  408. output_authors='/^date: / {
  409. 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 ~ /^[^;]*;$/) {
  410. print substr($5, 1, length($5)-1)
  411. }
  412. }'
  413. authors=`
  414. $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - $llogout
  415. `
  416. case $authors in
  417. ?*)
  418. cat >$llogout <<EOF || exit
  419. $authors
  420. EOF
  421. initialize_author_script='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
  422. initialize_author=`sed -e "$initialize_author_script" <$llogout`
  423. awkscript='
  424. BEGIN {
  425. alphabet = "abcdefghijklmnopqrstuvwxyz"
  426. ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  427. '"$initialize_author"'
  428. }
  429. {
  430. if (author[$1]) {
  431. fullname = $5
  432. if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
  433. # Remove the junk from fullnames like "0000-Admin(0000)".
  434. fullname = substr(fullname, index(fullname, "-") + 1)
  435. fullname = substr(fullname, 1, index(fullname, "(") - 1)
  436. }
  437. if (fullname ~ /,[^ ]/) {
  438. # Some sites put comma-separated junk after the fullname.
  439. # Remove it, but leave "Bill Gates, Jr" alone.
  440. fullname = substr(fullname, 1, index(fullname, ",") - 1)
  441. }
  442. abbr = index(fullname, "&")
  443. if (abbr) {
  444. a = substr($1, 1, 1)
  445. A = a
  446. i = index(alphabet, a)
  447. if (i) A = substr(ALPHABET, i, 1)
  448. fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
  449. }
  450. # Quote quotes and backslashes properly in full names.
  451. # Do not use gsub; traditional awk lacks it.
  452. quoted = ""
  453. rest = fullname
  454. for (;;) {
  455. p = index(rest, "\\")
  456. q = index(rest, "\"")
  457. if (p) {
  458. if (q && q<p) p = q
  459. } else {
  460. if (!q) break
  461. p = q
  462. }
  463. quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
  464. rest = substr(rest, p+1)
  465. }
  466. printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
  467. author[$1] = 0
  468. }
  469. }
  470. '
  471. initialize_fullname=`
  472. {
  473. (getent passwd $authors) ||
  474. (
  475. cat /etc/passwd
  476. for author in $authors
  477. do NIS_PATH= nismatch $author passwd.org_dir
  478. done
  479. ypmatch $authors passwd
  480. )
  481. } 2>/dev/null |
  482. $AWK -F: "$awkscript"
  483. `$initialize_fullname;;
  484. esac
  485. # Function to print a single log line.
  486. # We don't use awk functions, to stay compatible with old awk versions.
  487. # `Log' is the log message.
  488. # `files' contains the affected files.
  489. printlogline='{
  490. # Following the GNU coding standards, rewrite
  491. # * file: (function): comment
  492. # to
  493. # * file (function): comment
  494. if (Log ~ /^\([^)]*\):[\t\n ]/) {
  495. i = index(Log, ")")
  496. filefunc = substr(Log, 1, i)
  497. while ((j = index(filefunc, "\n"))) {
  498. files = files " " substr(filefunc, 1, j-1)
  499. filefunc = substr(filefunc, j+1)
  500. }
  501. files = files " " filefunc
  502. Log = substr(Log, i+3)
  503. }
  504. # If "label: comment" is too long, break the line after the ":".
  505. sep = " "
  506. i = index(Log, "\n")
  507. if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
  508. # Print the label.
  509. printf "%s*%s:", indent_string, files
  510. # Print each line of the log.
  511. while (i) {
  512. logline = substr(Log, 1, i-1)
  513. if (logline ~ /[^'"$tab"' ]/) {
  514. printf "%s%s\n", sep, logline
  515. } else {
  516. print ""
  517. }
  518. sep = indent_string
  519. Log = substr(Log, i+1)
  520. i = index(Log, "\n")
  521. }
  522. }'
  523. # Pattern to match the `revision' line of rlog output.
  524. rlog_revision_pattern='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
  525. case $hostname in
  526. '')
  527. hostname=`(
  528. hostname || uname -n || uuname -l || cat /etc/whoami
  529. ) 2>/dev/null` || {
  530. echo >&2 "$0: cannot deduce hostname"
  531. exit 1
  532. }
  533. case $hostname in
  534. *.*) ;;
  535. *)
  536. domainname=`(domainname) 2>/dev/null` &&
  537. case $domainname in
  538. *.*) hostname=$hostname.$domainname;;
  539. esac;;
  540. esac;;
  541. esac
  542. # Process the rlog output, generating ChangeLog style entries.
  543. # First, reformat the rlog output so that each line contains one log entry.
  544. # Transliterate \n to SOH so that multiline entries fit on a single line.
  545. # Discard irrelevant rlog output.
  546. $AWK '
  547. BEGIN {
  548. pository = "'"$pository"'"
  549. SOH="'"$SOH"'"
  550. }
  551. /^RCS file: / {
  552. if (pository != "") {
  553. filename = substr($0, 11)
  554. if (substr(filename, 1, length(pository)) == pository) {
  555. filename = substr(filename, length(pository) + 1)
  556. }
  557. if (filename ~ /,v$/) {
  558. filename = substr(filename, 1, length(filename) - 2)
  559. }
  560. if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
  561. i = length(filename)
  562. while (substr(filename, i, 1) != "/") i--
  563. filename = substr(filename, 1, i - 6) substr(filename, i + 1)
  564. }
  565. }
  566. rev = "?"
  567. }
  568. /^Working file: / { if (repository == "") filename = substr($0, 15) }
  569. /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
  570. line = $0
  571. if (line ~ /'"$rlog_revision_pattern"'/) {
  572. rev = $2
  573. next
  574. }
  575. if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
  576. date = $2
  577. if (date ~ /\//) {
  578. # This is a traditional RCS format date YYYY/MM/DD.
  579. # Replace "/"s with "-"s to get ISO format.
  580. newdate = ""
  581. while ((i = index(date, "/")) != 0) {
  582. newdate = newdate substr(date, 1, i-1) "-"
  583. date = substr(date, i+1)
  584. }
  585. date = newdate date
  586. }
  587. time = substr($3, 1, length($3) - 1)
  588. author = substr($5, 1, length($5)-1)
  589. printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
  590. rev = "?"
  591. next
  592. }
  593. if (line ~ /^branches: /) { next }
  594. if (line ~ /^(-----------*|===========*)$/) { print ""; next }
  595. if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
  596. line = "New file."
  597. }
  598. printf "%s%s", line, SOH
  599. }
  600. ' <"$rlogfile" |
  601. # Now each line is of the form
  602. # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
  603. # where @ stands for an SOH (octal code 001),
  604. # and each line of LOG is terminated by SOH instead of \n.
  605. # Sort the log entries, first by date+time (in reverse order),
  606. # then by author, then by log entry, and finally by file name and revision
  607. # (just in case).
  608. sort -t"$SOH" $SORT_K_OPTIONS |
  609. # Finally, reformat the sorted log entries.
  610. $AWK -F"$SOH" '
  611. BEGIN {
  612. logTZ = "'"$logTZ"'"
  613. revision = "'"$revision"'"
  614. # Initialize the fullname and mailaddr associative arrays.
  615. '"$initialize_fullname"'
  616. '"$initialize_mailaddr"'
  617. # Initialize indent string.
  618. indent_string = ""
  619. i = '"$indent"'
  620. if (0 < '"$tabwidth"')
  621. for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
  622. indent_string = indent_string "\t"
  623. while (1 <= i--)
  624. indent_string = indent_string " "
  625. }
  626. {
  627. newlog = ""
  628. for (i = 6; i < NF; i++) newlog = newlog $i "\n"
  629. # Ignore log entries prefixed by "#".
  630. if (newlog ~ /^#/) { next }
  631. if (Log != newlog || date != $3 || author != $5) {
  632. # The previous log and this log differ.
  633. # Print the old log.
  634. if (date != "") '"$printlogline"'
  635. # Logs that begin with "{clumpname} " should be grouped together,
  636. # and the clumpname should be removed.
  637. # Extract the new clumpname from the log header,
  638. # and use it to decide whether to output a blank line.
  639. newclumpname = ""
  640. sep = "\n"
  641. if (date == "") sep = ""
  642. if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
  643. i = index(newlog, "}")
  644. newclumpname = substr(newlog, 1, i)
  645. while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
  646. newlog = substr(newlog, i+1)
  647. if (clumpname == newclumpname && date == $3 && author == $5) sep = ""
  648. }
  649. printf sep
  650. clumpname = newclumpname
  651. # Get ready for the next log.
  652. Log = newlog
  653. if (files != "")
  654. for (i in filesknown)
  655. filesknown[i] = 0
  656. files = ""
  657. }
  658. if (date != $3 || author != $5) {
  659. # The previous date+author and this date+author differ.
  660. # Print the new one.
  661. date = $3
  662. time = $4
  663. author = $5
  664. zone = ""
  665. if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
  666. zone = " " substr(time, i)
  667. # Print "date[ timezone] fullname <email address>".
  668. # Get fullname and email address from associative arrays;
  669. # default to author and author@hostname if not in arrays.
  670. if (fullname[author])
  671. auth = fullname[author]
  672. else
  673. auth = author
  674. printf "%s%s %s ", date, zone, auth
  675. if (mailaddr[author])
  676. printf "<%s>\n\n", mailaddr[author]
  677. else
  678. printf "<%s@%s>\n\n", author, "'"$hostname"'"
  679. }
  680. if (! filesknown[$1]) {
  681. filesknown[$1] = 1
  682. if (files == "") files = " " $1
  683. else files = files ", " $1
  684. if (revision && $2 != "?") files = files " " $2
  685. }
  686. }
  687. END {
  688. # Print the last log.
  689. if (date != "") {
  690. '"$printlogline"'
  691. printf "\n"
  692. }
  693. }
  694. ' &&
  695. # Exit successfully.
  696. exec rm -fr $logdir
  697. # Local Variables:
  698. # tab-width:4
  699. # End: