rcs2log 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. #! /bin/sh
  2. # RCS to ChangeLog generator
  3. # Copyright (C) 1992-1998, 2001-2017 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) 2017 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. printf '%s\n' >&2 \
  109. "$0: -n '$2' '$3' '$4': tabs, newlines not allowed"
  110. exit 1;;
  111. esac
  112. login=$2
  113. lfm=$2$tab$3$tab$4
  114. shift; shift; shift;;
  115. -u)
  116. # If $2 is not tab-separated, use colon for separator.
  117. case ${2?} in
  118. *"$nl"*)
  119. printf '%s\n' >&2 "$0: -u '$2': newlines not allowed"
  120. exit 1;;
  121. *"$tab"*)
  122. t=$tab;;
  123. *)
  124. t=':';;
  125. esac
  126. case $2 in
  127. *"$t"*"$t"*"$t"*)
  128. printf '%s\n' >&2 "$0: -u '$2': too many fields"
  129. exit 1;;
  130. *"$t"*"$t"*)
  131. uf="[^$t]*$t" # An unselected field, followed by a separator.
  132. sf="\\([^$t]*\\)" # The selected field.
  133. login=`expr "X$2" : "X$sf"`
  134. lfm="$login$tab"`
  135. expr "X$2" : "$uf$sf"
  136. `"$tab"`
  137. expr "X$2" : "$uf$uf$sf"
  138. `;;
  139. *)
  140. printf '%s\n' >&2 "$0: -u '$2': not enough fields"
  141. exit 1;;
  142. esac
  143. shift;;
  144. esac
  145. case $logins in
  146. '') logins=$login;;
  147. ?*) logins=$logins$nl$login;;
  148. esac
  149. case $loginFullnameMailaddrs in
  150. '') loginFullnameMailaddrs=$lfm;;
  151. ?*) loginFullnameMailaddrs=$loginFullnameMailaddrs$nl$lfm;;
  152. esac;;
  153. -r)
  154. case $rlog_options in
  155. '') rlog_options=${2?};;
  156. ?*) rlog_options=$rlog_options$nl${2?};;
  157. esac
  158. shift;;
  159. -R) recursive=t;;
  160. -t) tabwidth=${2?}; shift;;
  161. -v) revision=t;;
  162. --version)
  163. set $Id
  164. rcs2logVersion=$3
  165. printf '%s\n' >&2 "rcs2log (GNU Emacs) $rcs2logVersion$nl$Copyright"
  166. exit 0;;
  167. -*) printf '%s\n' >&2 "Usage: $0 [OPTION]... [FILE ...]$nl$Help"
  168. case $1 in
  169. --help) exit 0;;
  170. *) exit 1;;
  171. esac;;
  172. *) break;;
  173. esac
  174. shift
  175. done
  176. month_data='
  177. m[0]="Jan"; m[1]="Feb"; m[2]="Mar"
  178. m[3]="Apr"; m[4]="May"; m[5]="Jun"
  179. m[6]="Jul"; m[7]="Aug"; m[8]="Sep"
  180. m[9]="Oct"; m[10]="Nov"; m[11]="Dec"
  181. '
  182. if type mktemp >/dev/null 2>&1; then
  183. logdir=`mktemp -d`
  184. else
  185. logdir=$TMPDIR/rcs2log$$
  186. (umask 077 && mkdir "$logdir")
  187. fi || exit
  188. case $logdir in
  189. -*) logdir=./$logdir;;
  190. esac
  191. trap exit 1 2 13 15
  192. trap "rm -fr \"$logdir\" 2>/dev/null" 0
  193. llogout=$logdir/l
  194. # If no rlog-format log file is given, generate one into $rlogfile.
  195. case $rlogfile in
  196. '')
  197. rlogfile=$logdir/r
  198. # If no rlog options are given,
  199. # log the revisions checked in since the first ChangeLog entry.
  200. # Since ChangeLog is only by date, some of these revisions may be
  201. # duplicates of what's already in ChangeLog; it's the user's
  202. # responsibility to remove them.
  203. case $rlog_options in
  204. '')
  205. if test -s "$changelog"
  206. then
  207. e='
  208. /^[0-9]+-[0-9][0-9]-[0-9][0-9]/{
  209. # ISO 8601 date
  210. print $1
  211. exit
  212. }
  213. /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{
  214. # old-fashioned date and time (Emacs 19.31 and earlier)
  215. '"$month_data"'
  216. year = $5
  217. for (i=0; i<=11; i++) if (m[i] == $2) break
  218. dd = $3
  219. printf "%d-%02d-%02d\n", year, i+1, dd
  220. exit
  221. }
  222. '
  223. d=`$AWK "$e" <"$changelog"` || exit
  224. case $d in
  225. ?*) datearg="-d>$d";;
  226. esac
  227. fi;;
  228. esac
  229. # Use TZ specified by ChangeLog local variable, if any.
  230. if test -s "$changelog"
  231. then
  232. extractTZ='
  233. /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*"\([^"]*\)".*/{
  234. s//\1/; p; q
  235. }
  236. /^.*change-log-time-zone-rule['"$tab"' ]*:['"$tab"' ]*t.*/{
  237. s//UTC0/; p; q
  238. }
  239. '
  240. logTZ=`tail "$changelog" | sed -n "$extractTZ"`
  241. case $logTZ in
  242. ?*) TZ=$logTZ; export TZ;;
  243. esac
  244. fi
  245. # If CVS is in use, examine its repository, not the normal RCS files.
  246. if test ! -f CVS/Repository
  247. then
  248. rlog=rlog
  249. repository=
  250. else
  251. rlog='cvs -q log'
  252. repository=`sed 1q <CVS/Repository` || exit
  253. test ! -f CVS/Root || CVSROOT=`cat <CVS/Root` || exit
  254. pository=
  255. case $CVSROOT in
  256. /* | :fork:* | :local:*) ;;
  257. */*)
  258. # remote repository
  259. pository=`expr "X$CVSROOT" : '[^/]*\(.*\)'`;;
  260. esac
  261. case $pository in
  262. '')
  263. # local repository
  264. case $repository in
  265. /*) ;;
  266. *)
  267. repository=${CVSROOT?}/$repository
  268. case $repository in
  269. :fork:* | :local:*)
  270. repository=`expr "$repository" : ':[^:]*:\(.*\)'`;;
  271. esac;;
  272. esac
  273. if test ! -d "$repository"
  274. then
  275. printf '%s\n' >&2 \
  276. "$0: $repository: bad repository (see CVS/Repository)"
  277. exit 1
  278. fi
  279. pository=$repository;;
  280. esac
  281. # Ensure that $pository ends in exactly one slash.
  282. while :
  283. do
  284. case $pository in
  285. *//) pository=`expr "X$pository" : 'X\(.*\)/'`;;
  286. */) break;;
  287. *) pository=$pository/; break;;
  288. esac
  289. done
  290. # If no rlog options are given, and if we are in a tagged CVS branch,
  291. # log only the changes in that branch.
  292. case $rlog_options in
  293. '')
  294. if test -f CVS/Tag
  295. then
  296. CVSTAG=`cat <CVS/Tag` || exit
  297. case $CVSTAG in
  298. T?*)
  299. rlog_options=-r`expr "$CVSTAG" : 'T\(.*\)'`;;
  300. *)
  301. printf '%s\n' >&2 "$0: invalid CVS/Tag"; exit 1;;
  302. esac
  303. fi;;
  304. esac
  305. fi
  306. # Use $rlog's -zLT option, if $rlog supports it.
  307. case `$rlog -zLT 2>&1` in
  308. *' option'*) ;;
  309. *)
  310. case $rlog_options in
  311. '') rlog_options=-zLT;;
  312. ?*) rlog_options=-zLT$nl$rlog_options;;
  313. esac;;
  314. esac
  315. # With no arguments, examine all files under the RCS directory.
  316. case $# in
  317. 0)
  318. case $repository in
  319. '')
  320. oldIFS=$IFS
  321. IFS=$nl
  322. case $recursive in
  323. t)
  324. RCSdirs=`find . -name RCS -type d -print`
  325. filesFromRCSfiles='s|,v$||; s|/RCS/|/|; s|^\./||'
  326. files=`
  327. {
  328. case $RCSdirs in
  329. ?*) find $RCSdirs \
  330. -type f \
  331. ! -name '*_' \
  332. ! -name ',*,' \
  333. ! -name '.*_' \
  334. ! -name .rcsfreeze.log \
  335. ! -name .rcsfreeze.ver \
  336. -print;;
  337. esac
  338. find . -name '*,v' -print
  339. } |
  340. sort -u |
  341. sed "$filesFromRCSfiles"
  342. `;;
  343. *)
  344. files=
  345. for file in RCS/.* RCS/* .*,v *,v
  346. do
  347. case $file in
  348. RCS/. | RCS/.. | RCS/,*, | RCS/*_) continue;;
  349. RCS/.rcsfreeze.log | RCS/.rcsfreeze.ver) continue;;
  350. RCS/.\* | RCS/\* | .\*,v | \*,v) test -f "$file" || continue;;
  351. RCS/*,v | RCS/.*,v) ;;
  352. RCS/* | RCS/.*) test -f "$file" || continue;;
  353. esac
  354. case $files in
  355. '') files=$file;;
  356. ?*) files=$files$nl$file;;
  357. esac
  358. done
  359. case $files in
  360. '') exit 0;;
  361. esac;;
  362. esac
  363. set x $files
  364. shift
  365. IFS=$oldIFS;;
  366. esac;;
  367. esac
  368. case $datearg in
  369. ?*) $rlog $rlog_options "$datearg" "$@" >$rlogfile;;
  370. '') $rlog $rlog_options "$@" >$rlogfile;;
  371. esac || exit;;
  372. esac
  373. # Prefer the POSIX-style -k options, since POSIX 1003.1-2001 prohibits
  374. # support for the traditional-style +M -N options.
  375. SORT_K_OPTIONS='-k 3,4r -k 5 -k 1'
  376. sort $SORT_K_OPTIONS </dev/null 2>/dev/null || SORT_K_OPTIONS='+2 -4r +4 +0'
  377. # Get the full name of each author the logs mention, and set initialize_fullname
  378. # to awk code that initializes the 'fullname' awk associative array.
  379. # Warning: foreign authors (i.e. not known in the passwd file) are mishandled;
  380. # you have to fix the resulting output by hand.
  381. initialize_fullname=
  382. initialize_mailaddr=
  383. case $loginFullnameMailaddrs in
  384. ?*)
  385. case $loginFullnameMailaddrs in
  386. *\"* | *\\*)
  387. sed 's/["\\]/\\&/g' >"$llogout" <<EOF || exit
  388. $loginFullnameMailaddrs
  389. EOF
  390. loginFullnameMailaddrs=`cat "$llogout"`;;
  391. esac
  392. oldIFS=$IFS
  393. IFS=$nl
  394. for loginFullnameMailaddr in $loginFullnameMailaddrs
  395. do
  396. IFS=$tab
  397. set x $loginFullnameMailaddr
  398. login=$2
  399. fullname=$3
  400. mailaddr=$4
  401. initialize_fullname="$initialize_fullname
  402. fullname[\"$login\"] = \"$fullname\""
  403. initialize_mailaddr="$initialize_mailaddr
  404. mailaddr[\"$login\"] = \"$mailaddr\""
  405. done
  406. IFS=$oldIFS;;
  407. esac
  408. case $logins in
  409. ?*)
  410. sort -u -o "$llogout" <<EOF
  411. $logins
  412. EOF
  413. ;;
  414. '')
  415. : ;;
  416. esac >"$llogout" || exit
  417. output_authors='/^date: / {
  418. cvsformat = $5 == "author:"
  419. 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:]*;$/)) {
  420. author = $(5 + cvsformat)
  421. if ($(4 + cvsformat) == "author:" && author ~ /^[^;]*;$/) {
  422. print substr(author, 1, length(author)-1)
  423. }
  424. }
  425. }'
  426. authors=`
  427. $AWK "$output_authors" <"$rlogfile" | sort -u | comm -23 - "$llogout"
  428. `
  429. case $authors in
  430. ?*)
  431. cat >"$llogout" <<EOF || exit
  432. $authors
  433. EOF
  434. initialize_author_script='s/["\\]/\\&/g; s/.*/author[\"&\"] = 1/'
  435. initialize_author=`sed -e "$initialize_author_script" <"$llogout"`
  436. awkscript='
  437. BEGIN {
  438. alphabet = "abcdefghijklmnopqrstuvwxyz"
  439. ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  440. '"$initialize_author"'
  441. }
  442. {
  443. if (author[$1]) {
  444. fullname = $5
  445. if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) {
  446. # Remove the junk from fullnames like "0000-Admin(0000)".
  447. fullname = substr(fullname, index(fullname, "-") + 1)
  448. fullname = substr(fullname, 1, index(fullname, "(") - 1)
  449. }
  450. if (fullname ~ /,[^ ]/) {
  451. # Some sites put comma-separated junk after the fullname.
  452. # Remove it, but leave "Bill Gates, Jr" alone.
  453. fullname = substr(fullname, 1, index(fullname, ",") - 1)
  454. }
  455. abbr = index(fullname, "&")
  456. if (abbr) {
  457. a = substr($1, 1, 1)
  458. A = a
  459. i = index(alphabet, a)
  460. if (i) A = substr(ALPHABET, i, 1)
  461. fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1)
  462. }
  463. # Quote quotes and backslashes properly in full names.
  464. # Do not use gsub; traditional awk lacks it.
  465. quoted = ""
  466. rest = fullname
  467. for (;;) {
  468. p = index(rest, "\\")
  469. q = index(rest, "\"")
  470. if (p) {
  471. if (q && q<p) p = q
  472. } else {
  473. if (!q) break
  474. p = q
  475. }
  476. quoted = quoted substr(rest, 1, p-1) "\\" substr(rest, p, 1)
  477. rest = substr(rest, p+1)
  478. }
  479. printf "fullname[\"%s\"] = \"%s%s\"\n", $1, quoted, rest
  480. author[$1] = 0
  481. }
  482. }
  483. '
  484. initialize_fullname=`
  485. {
  486. (getent passwd $authors) ||
  487. (
  488. cat /etc/passwd
  489. for author in $authors
  490. do NIS_PATH= nismatch $author passwd.org_dir
  491. done
  492. ypmatch $authors passwd
  493. )
  494. } 2>/dev/null |
  495. $AWK -F: "$awkscript"
  496. `$initialize_fullname;;
  497. esac
  498. # Function to print a single log line.
  499. # We don't use awk functions, to stay compatible with old awk versions.
  500. # 'Log' is the log message.
  501. # 'files' contains the affected files.
  502. printlogline='{
  503. # Following the GNU coding standards, rewrite
  504. # * file: (function): comment
  505. # to
  506. # * file (function): comment
  507. if (Log ~ /^\([^)]*\):[\t\n ]/) {
  508. i = index(Log, ")")
  509. filefunc = substr(Log, 1, i)
  510. while ((j = index(filefunc, "\n"))) {
  511. files = files " " substr(filefunc, 1, j-1)
  512. filefunc = substr(filefunc, j+1)
  513. }
  514. files = files " " filefunc
  515. Log = substr(Log, i+3)
  516. }
  517. # If "label: comment" is too long, break the line after the ":".
  518. sep = " "
  519. i = index(Log, "\n")
  520. if ('"$length"' <= '"$indent"' + 1 + length(files) + i) sep = "\n" indent_string
  521. # Print the label.
  522. printf "%s*%s:", indent_string, files
  523. # Print each line of the log.
  524. while (i) {
  525. logline = substr(Log, 1, i-1)
  526. if (logline ~ /[^'"$tab"' ]/) {
  527. printf "%s%s\n", sep, logline
  528. } else {
  529. print ""
  530. }
  531. sep = indent_string
  532. Log = substr(Log, i+1)
  533. i = index(Log, "\n")
  534. }
  535. }'
  536. # Pattern to match the 'revision' line of rlog output.
  537. rlog_revision_pattern='^revision [0-9]+\.[0-9]+(\.[0-9]+\.[0-9]+)*(['"$tab"' ]+locked by: [^'"$tab"' $,.0-9:;@]*[^'"$tab"' $,:;@][^'"$tab"' $,.0-9:;@]*;)?['"$tab"' ]*$'
  538. case $hostname in
  539. '')
  540. hostname=`(
  541. hostname || uname -n || uuname -l || cat /etc/whoami
  542. ) 2>/dev/null` || {
  543. printf '%s\n' >&2 "$0: cannot deduce hostname"
  544. exit 1
  545. }
  546. case $hostname in
  547. *.*) ;;
  548. *)
  549. domainname=`(domainname) 2>/dev/null` &&
  550. case $domainname in
  551. *.*) hostname=$hostname.$domainname;;
  552. esac;;
  553. esac;;
  554. esac
  555. # Process the rlog output, generating ChangeLog style entries.
  556. # First, reformat the rlog output so that each line contains one log entry.
  557. # Transliterate \n to SOH so that multiline entries fit on a single line.
  558. # Discard irrelevant rlog output.
  559. $AWK '
  560. BEGIN {
  561. pository = "'"$pository"'"
  562. SOH="'"$SOH"'"
  563. }
  564. /^RCS file: / {
  565. if (pository != "") {
  566. filename = substr($0, 11)
  567. if (substr(filename, 1, length(pository)) == pository) {
  568. filename = substr(filename, length(pository) + 1)
  569. }
  570. if (filename ~ /,v$/) {
  571. filename = substr(filename, 1, length(filename) - 2)
  572. }
  573. if (filename ~ /(^|\/)Attic\/[^\/]*$/) {
  574. i = length(filename)
  575. while (substr(filename, i, 1) != "/") i--
  576. filename = substr(filename, 1, i - 6) substr(filename, i + 1)
  577. }
  578. }
  579. rev = "?"
  580. }
  581. /^Working file: / { if (repository == "") filename = substr($0, 15) }
  582. /'"$rlog_revision_pattern"'/, /^(-----------*|===========*)$/ {
  583. line = $0
  584. if (line ~ /'"$rlog_revision_pattern"'/) {
  585. rev = $2
  586. next
  587. }
  588. if (line ~ /^date: [0-9][- +\/0-9:]*;/) {
  589. date = $2
  590. if (date ~ /\//) {
  591. # This is a traditional RCS format date YYYY/MM/DD.
  592. # Replace "/"s with "-"s to get ISO format.
  593. newdate = ""
  594. while ((i = index(date, "/")) != 0) {
  595. newdate = newdate substr(date, 1, i-1) "-"
  596. date = substr(date, i+1)
  597. }
  598. date = newdate date
  599. }
  600. time = ""
  601. for (i = 3; i <= NF; i++) {
  602. time = time $i
  603. if (time ~ /;$/) {
  604. time = substr(time, 1, length(time) - 1)
  605. break
  606. }
  607. }
  608. i++
  609. if ($i == "author:") {
  610. author = $(i + 1)
  611. if (author ~ /;$/) {
  612. author = substr(author, 1, length(author) - 1)
  613. }
  614. } else {
  615. author = ""
  616. }
  617. printf "%s%s%s%s%s%s%s%s%s%s", filename, SOH, rev, SOH, date, SOH, time, SOH, author, SOH
  618. rev = "?"
  619. next
  620. }
  621. if (line ~ /^branches: /) { next }
  622. if (line ~ /^(-----------*|===========*)$/) { print ""; next }
  623. if (line == "Initial revision" || line ~ /^file .+ was initially added on branch .+\.$/) {
  624. line = "New file."
  625. }
  626. printf "%s%s", line, SOH
  627. }
  628. ' <"$rlogfile" |
  629. # Now each line is of the form
  630. # FILENAME@REVISION@YYYY-MM-DD@HH:MM:SS[+-TIMEZONE]@AUTHOR@LOG
  631. # where @ stands for an SOH (octal code 001),
  632. # and each line of LOG is terminated by SOH instead of \n.
  633. # Sort the log entries, first by date+time (in reverse order),
  634. # then by author, then by log entry, and finally by file name and revision
  635. # (just in case).
  636. sort -t"$SOH" $SORT_K_OPTIONS |
  637. # Finally, reformat the sorted log entries.
  638. $AWK -F"$SOH" '
  639. BEGIN {
  640. logTZ = "'"$logTZ"'"
  641. revision = "'"$revision"'"
  642. # Initialize the fullname and mailaddr associative arrays.
  643. '"$initialize_fullname"'
  644. '"$initialize_mailaddr"'
  645. # Initialize indent string.
  646. indent_string = ""
  647. i = '"$indent"'
  648. if (0 < '"$tabwidth"')
  649. for (; '"$tabwidth"' <= i; i -= '"$tabwidth"')
  650. indent_string = indent_string "\t"
  651. while (1 <= i--)
  652. indent_string = indent_string " "
  653. }
  654. {
  655. newlog = ""
  656. for (i = 6; i < NF; i++) newlog = newlog $i "\n"
  657. # Ignore log entries prefixed by "#".
  658. if (newlog ~ /^#/) { next }
  659. if (Log != newlog || date != $3 || author != $5) {
  660. # The previous log and this log differ.
  661. # Print the old log.
  662. if (date != "") '"$printlogline"'
  663. # Logs that begin with "{clumpname} " should be grouped together,
  664. # and the clumpname should be removed.
  665. # Extract the new clumpname from the log header,
  666. # and use it to decide whether to output a blank line.
  667. newclumpname = ""
  668. sep = "\n"
  669. if (date == "") sep = ""
  670. if (newlog ~ /^\{[^'"$tab"' }]*}['"$tab"' ]/) {
  671. i = index(newlog, "}")
  672. newclumpname = substr(newlog, 1, i)
  673. while (substr(newlog, i+1) ~ /^['"$tab"' ]/) i++
  674. newlog = substr(newlog, i+1)
  675. if (clumpname == newclumpname && date == $3 && author == $5) sep = ""
  676. }
  677. printf sep
  678. clumpname = newclumpname
  679. # Get ready for the next log.
  680. Log = newlog
  681. if (files != "")
  682. for (i in filesknown)
  683. filesknown[i] = 0
  684. files = ""
  685. }
  686. if (date != $3 || author != $5) {
  687. # The previous date+author and this date+author differ.
  688. # Print the new one.
  689. date = $3
  690. time = $4
  691. author = $5
  692. zone = ""
  693. if (logTZ && ((i = index(time, "-")) || (i = index(time, "+"))))
  694. zone = " " substr(time, i)
  695. # Print "date[ timezone] fullname <email address>".
  696. # Get fullname and email address from associative arrays;
  697. # default to author and author@hostname if not in arrays.
  698. if (fullname[author])
  699. auth = fullname[author]
  700. else
  701. auth = author
  702. printf "%s%s %s ", date, zone, auth
  703. if (mailaddr[author])
  704. printf "<%s>\n\n", mailaddr[author]
  705. else
  706. printf "<%s@%s>\n\n", author, "'"$hostname"'"
  707. }
  708. if (! filesknown[$1]) {
  709. filesknown[$1] = 1
  710. if (files == "") files = " " $1
  711. else files = files ", " $1
  712. if (revision && $2 != "?") files = files " " $2
  713. }
  714. }
  715. END {
  716. # Print the last log.
  717. if (date != "") {
  718. '"$printlogline"'
  719. printf "\n"
  720. }
  721. }
  722. ' &&
  723. # Exit successfully.
  724. exec rm -fr "$logdir"
  725. # Local Variables:
  726. # tab-width:4
  727. # End: