Mercurial > hg > xemacs-beta
comparison lib-src/rcs2log @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
| author | cvs |
|---|---|
| date | Mon, 13 Aug 2007 08:45:50 +0200 |
| parents | |
| children | 929b76928fce |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:376386a54a3c |
|---|---|
| 1 #!/bin/sh | |
| 2 | |
| 3 # RCS to ChangeLog generator | |
| 4 | |
| 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. | |
| 8 | |
| 9 # Ignore log entries that start with `#'. | |
| 10 # Clump together log entries that start with `{topic} ', | |
| 11 # where `topic' contains neither white space nor `}'. | |
| 12 | |
| 13 # Author: Paul Eggert <eggert@twinsun.com> | |
| 14 | |
| 15 # !Id: rcs2log,v 1.18 1994/08/15 22:44:10 eggert Exp ! | |
| 16 | |
| 17 # Copyright 1992, 1993 Free Software Foundation, Inc. | |
| 18 | |
| 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) | |
| 22 # any later version. | |
| 23 # | |
| 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. | |
| 28 # | |
| 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 | |
| 31 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 32 | |
| 33 nl=' | |
| 34 ' | |
| 35 | |
| 36 # Parse options. | |
| 37 | |
| 38 # defaults | |
| 39 : ${TMPDIR=/tmp} | |
| 40 hostname= # name of local host (if empty, will deduce it later) | |
| 41 indent=8 # indent of log line | |
| 42 initialize_fullname= # awk assignments to set up fullname array | |
| 43 initialize_mailaddr= # awk assignments to set up mailaddr array | |
| 44 length=79 # suggested max width of log line | |
| 45 logins= # login names for people we know fullnames and mailaddresses of | |
| 46 loginsout= # temporary file holding sorted logins | |
| 47 rlog_options= # options to pass to rlog | |
| 48 tabwidth=8 # width of horizontal tab | |
| 49 | |
| 50 while : | |
| 51 do | |
| 52 case $1 in | |
| 53 -i) indent=${2?};; | |
| 54 -h) hostname=${2?};; | |
| 55 -l) length=${2?};; | |
| 56 -n) logins=$logins$nl${2?} | |
| 57 loginsout=$TMPDIR/rcs2log$$l | |
| 58 case $2${3?}${4?} in | |
| 59 *\"* | *\\* | *"$nl"*) | |
| 60 echo >&2 "$0: -n '$2' '$3' '$4': special characters not allowed" | |
| 61 exit 1 | |
| 62 esac | |
| 63 initialize_fullname="$initialize_fullname | |
| 64 fullname[\"$2\"] = \"$3\"" | |
| 65 initialize_mailaddr="$initialize_mailaddr | |
| 66 mailaddr[\"$2\"] = \"$4\"" | |
| 67 shift; shift;; | |
| 68 -r) rlog_options=$rlog_options$nl${2?};; | |
| 69 -t) tabwidth=${2?};; | |
| 70 -*) echo >&2 "$0: usage: $0 [options] [file ...] | |
| 71 Options: | |
| 72 [-h hostname] [-i indent] [-l length] [-n login fullname mailaddr]... | |
| 73 [-r rlog_option]... [-t tabwidth]" | |
| 74 exit 1;; | |
| 75 *) break | |
| 76 esac | |
| 77 shift; shift | |
| 78 done | |
| 79 | |
| 80 month_data=' | |
| 81 m[0]="Jan"; m[1]="Feb"; m[2]="Mar" | |
| 82 m[3]="Apr"; m[4]="May"; m[5]="Jun" | |
| 83 m[6]="Jul"; m[7]="Aug"; m[8]="Sep" | |
| 84 m[9]="Oct"; m[10]="Nov"; m[11]="Dec" | |
| 85 | |
| 86 # days in non-leap year thus far, indexed by month (0-12) | |
| 87 mo[0]=0; mo[1]=31; mo[2]=59; mo[3]=90 | |
| 88 mo[4]=120; mo[5]=151; mo[6]=181; mo[7]=212 | |
| 89 mo[8]=243; mo[9]=273; mo[10]=304; mo[11]=334 | |
| 90 mo[12]=365 | |
| 91 ' | |
| 92 | |
| 93 | |
| 94 # Log into $rlogout the revisions checked in since the first ChangeLog entry. | |
| 95 | |
| 96 date=1970 | |
| 97 if test -s ChangeLog | |
| 98 then | |
| 99 # Add 1 to seconds to avoid duplicating most recent log. | |
| 100 e=' | |
| 101 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{ | |
| 102 '"$month_data"' | |
| 103 year = $5 | |
| 104 for (i=0; i<=11; i++) if (m[i] == $2) break | |
| 105 dd = $3 | |
| 106 hh = substr($0,12,2) | |
| 107 mm = substr($0,15,2) | |
| 108 ss = substr($0,18,2) | |
| 109 ss++ | |
| 110 if (ss == 60) { | |
| 111 ss = 0 | |
| 112 mm++ | |
| 113 if (mm == 60) { | |
| 114 mm = 0 | |
| 115 hh++ | |
| 116 if (hh == 24) { | |
| 117 hh = 0 | |
| 118 dd++ | |
| 119 monthdays = mo[i+1] - mo[i] | |
| 120 if (i == 1 && year%4 == 0 && (year%100 != 0 || year%400 == 0)) monthdays++ | |
| 121 if (dd == monthdays + 1) { | |
| 122 dd = 1 | |
| 123 i++ | |
| 124 if (i == 12) { | |
| 125 i = 0 | |
| 126 year++ | |
| 127 } | |
| 128 } | |
| 129 } | |
| 130 } | |
| 131 } | |
| 132 printf "%d/%02d/%02d %02d:%02d:%02d\n", year, i+1, dd, hh, mm, ss | |
| 133 exit | |
| 134 } | |
| 135 ' | |
| 136 d=`awk "$e" <ChangeLog` || exit | |
| 137 case $d in | |
| 138 ?*) date=$d | |
| 139 esac | |
| 140 fi | |
| 141 datearg="-d>$date" | |
| 142 | |
| 143 repository= | |
| 144 rlog=rlog | |
| 145 case $CVSROOT in | |
| 146 ?*) | |
| 147 if test -d "$CVSROOT" && test -f CVS/Repository | |
| 148 then | |
| 149 r=`cat <CVS/Repository` || exit | |
| 150 if test -d "$CVSROOT/$r" | |
| 151 then | |
| 152 repository=$CVSROOT/$r | |
| 153 rlog='cvs log' | |
| 154 fi | |
| 155 fi | |
| 156 esac | |
| 157 | |
| 158 # With no arguments, examine all files under the RCS directory. | |
| 159 case $# in | |
| 160 0) | |
| 161 case $repository in | |
| 162 '') | |
| 163 files= | |
| 164 for file in RCS/.* RCS/* .*,v *,v | |
| 165 do | |
| 166 case $file in | |
| 167 RCS/. | RCS/..) continue;; | |
| 168 RCS/.\* | RCS/\* | .\*,v | \*,v) test -f "$file" || continue | |
| 169 esac | |
| 170 files=$files$nl$file | |
| 171 done | |
| 172 case $files in | |
| 173 '') exit 0 | |
| 174 esac | |
| 175 oldIFS=$IFS | |
| 176 IFS=$nl | |
| 177 set $files | |
| 178 IFS=$oldIFS | |
| 179 esac | |
| 180 esac | |
| 181 | |
| 182 rlogout=$TMPDIR/rcs2log$$r | |
| 183 trap exit 1 2 13 15 | |
| 184 trap "rm -f $loginsout $rlogout; exit 1" 0 | |
| 185 | |
| 186 $rlog "$datearg" $rlog_options ${1+"$@"} >$rlogout || exit | |
| 187 | |
| 188 | |
| 189 # Get the full name of each author the logs mention, and set initialize_fullname | |
| 190 # to awk code that initializes the `fullname' awk associative array. | |
| 191 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled; | |
| 192 # you have to fix the resulting output by hand. | |
| 193 | |
| 194 case $loginsout in | |
| 195 ?*) sort -u -o $loginsout <<EOF || exit | |
| 196 $logins | |
| 197 EOF | |
| 198 esac | |
| 199 authors=` | |
| 200 sed -n 's|^date: *[0-9]*[-/][0-9][0-9][-/][0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9][-+0-9]*; *author: *\([^; ]*\).*|\1|p' <$rlogout | | |
| 201 case $loginsout in | |
| 202 '') sort -u;; | |
| 203 ?*) sort -u | comm -23 - $loginsout | |
| 204 esac | |
| 205 ` | |
| 206 case $authors in | |
| 207 ?*) | |
| 208 initialize_author= | |
| 209 for author in $authors | |
| 210 do | |
| 211 initialize_author="$initialize_author | |
| 212 author[\"$author\"] = 1 | |
| 213 " | |
| 214 done | |
| 215 awkscript=' | |
| 216 BEGIN { | |
| 217 alphabet = "abcdefghijklmnopqrstuvwxyz" | |
| 218 ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| 219 '"$initialize_author"' | |
| 220 } | |
| 221 { | |
| 222 if (author[$1]) { | |
| 223 fullname = $5 | |
| 224 if (fullname ~ /[0-9]+-[^(]*\([0-9]+\)$/) { | |
| 225 # Remove the junk from fullnames like "0000-Admin(0000)". | |
| 226 fullname = substr(fullname, index(fullname, "-") + 1) | |
| 227 fullname = substr(fullname, 1, index(fullname, "(") - 1) | |
| 228 } | |
| 229 if (fullname ~ /,[^ ]/) { | |
| 230 # Some sites put comma-separated junk after the fullname. | |
| 231 # Remove it, but leave "Bill Gates, Jr" alone. | |
| 232 fullname = substr(fullname, 1, index(fullname, ",") - 1) | |
| 233 } | |
| 234 abbr = index(fullname, "&") | |
| 235 if (abbr) { | |
| 236 a = substr($1, 1, 1) | |
| 237 A = a | |
| 238 i = index(alphabet, a) | |
| 239 if (i) A = substr(ALPHABET, i, 1) | |
| 240 fullname = substr(fullname, 1, abbr-1) A substr($1, 2) substr(fullname, abbr+1) | |
| 241 } | |
| 242 printf "fullname[\"%s\"] = \"%s\"\n", $1, fullname | |
| 243 author[$1] = 0 | |
| 244 } | |
| 245 } | |
| 246 ' | |
| 247 | |
| 248 initialize_fullname=` | |
| 249 (cat /etc/passwd; ypmatch $authors passwd) 2>/dev/null | | |
| 250 awk -F: "$awkscript" | |
| 251 `$initialize_fullname | |
| 252 esac | |
| 253 | |
| 254 | |
| 255 # Function to print a single log line. | |
| 256 # We don't use awk functions, to stay compatible with old awk versions. | |
| 257 # `Log' is the log message (with \n replaced by \r). | |
| 258 # `files' contains the affected files. | |
| 259 printlogline='{ | |
| 260 | |
| 261 # Following the GNU coding standards, rewrite | |
| 262 # * file: (function): comment | |
| 263 # to | |
| 264 # * file (function): comment | |
| 265 if (Log ~ /^\([^)]*\): /) { | |
| 266 i = index(Log, ")") | |
| 267 files = files " " substr(Log, 1, i) | |
| 268 Log = substr(Log, i+3) | |
| 269 } | |
| 270 | |
| 271 # If "label: comment" is too long, break the line after the ":". | |
| 272 sep = " " | |
| 273 if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, CR)) sep = "\n" indent_string | |
| 274 | |
| 275 # Print the label. | |
| 276 printf "%s*%s:", indent_string, files | |
| 277 | |
| 278 # Print each line of the log, transliterating \r to \n. | |
| 279 while ((i = index(Log, CR)) != 0) { | |
| 280 logline = substr(Log, 1, i-1) | |
| 281 if (logline ~ /[^ ]/) { | |
| 282 printf "%s%s\n", sep, logline | |
| 283 } else { | |
| 284 print "" | |
| 285 } | |
| 286 sep = indent_string | |
| 287 Log = substr(Log, i+1) | |
| 288 } | |
| 289 }' | |
| 290 | |
| 291 case $hostname in | |
| 292 '') | |
| 293 hostname=`( | |
| 294 hostname || uname -n || uuname -l || cat /etc/whoami | |
| 295 ) 2>/dev/null` || { | |
| 296 echo >&2 "$0: cannot deduce hostname" | |
| 297 exit 1 | |
| 298 } | |
| 299 esac | |
| 300 | |
| 301 | |
| 302 # Process the rlog output, generating ChangeLog style entries. | |
| 303 | |
| 304 # First, reformat the rlog output so that each line contains one log entry. | |
| 305 # Transliterate \n to \r so that multiline entries fit on a single line. | |
| 306 # Discard irrelevant rlog output. | |
| 307 awk <$rlogout ' | |
| 308 /^Working file:/ { filename = $3 } | |
| 309 /^date: /, /^(-----------*|===========*)$/ { | |
| 310 if ($0 ~ /^branches: /) { next } | |
| 311 if ($0 ~ /^date: [0-9][- +\/0-9:]*;/) { | |
| 312 date = $2 | |
| 313 if (date ~ /-/) { | |
| 314 # An ISO format date. Replace all "-"s with "/"s. | |
| 315 newdate = "" | |
| 316 while ((i = index(date, "-")) != 0) { | |
| 317 newdate = newdate substr(date, 1, i-1) "/" | |
| 318 date = substr(date, i+1) | |
| 319 } | |
| 320 date = newdate date | |
| 321 } | |
| 322 # Ignore any time zone; ChangeLog has no room for it. | |
| 323 time = substr($3, 1, 8) | |
| 324 author = substr($5, 1, length($5)-1) | |
| 325 printf "%s %s %s %s %c", filename, date, time, author, 13 | |
| 326 next | |
| 327 } | |
| 328 if ($0 ~ /^(-----------*|===========*)$/) { print ""; next } | |
| 329 printf "%s%c", $0, 13 | |
| 330 } | |
| 331 ' | | |
| 332 | |
| 333 # Now each line is of the form | |
| 334 # FILENAME YYYY/MM/DD HH:MM:SS AUTHOR \rLOG | |
| 335 # where \r stands for a carriage return, | |
| 336 # and each line of the log is terminated by \r instead of \n. | |
| 337 # Sort the log entries, first by date+time (in reverse order), | |
| 338 # then by author, then by log entry, and finally by file name (just in case). | |
| 339 sort +1 -3r +3 +0 | | |
| 340 | |
| 341 # Finally, reformat the sorted log entries. | |
| 342 awk ' | |
| 343 BEGIN { | |
| 344 # Some awks do not understand "\r" or "\013", so we have to | |
| 345 # put a carriage return directly in the file. | |
| 346 CR=" | |
| 347 " # <-- There is a single CR between the " chars here. | |
| 348 | |
| 349 # Initialize the fullname and mailaddr associative arrays. | |
| 350 '"$initialize_fullname"' | |
| 351 '"$initialize_mailaddr"' | |
| 352 | |
| 353 # Initialize indent string. | |
| 354 indent_string = "" | |
| 355 i = '"$indent"' | |
| 356 if (0 < '"$tabwidth"') | |
| 357 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"') | |
| 358 indent_string = indent_string "\t" | |
| 359 while (1 <= i--) | |
| 360 indent_string = indent_string " " | |
| 361 | |
| 362 # Set up date conversion tables. | |
| 363 # RCS uses a nice, clean, sortable format, | |
| 364 # but ChangeLog wants the traditional, ugly ctime format. | |
| 365 | |
| 366 # January 1, 0 AD (Gregorian) was Saturday = 6 | |
| 367 EPOCH_WEEKDAY = 6 | |
| 368 # Of course, there was no 0 AD, but the algorithm works anyway. | |
| 369 | |
| 370 w[0]="Sun"; w[1]="Mon"; w[2]="Tue"; w[3]="Wed" | |
| 371 w[4]="Thu"; w[5]="Fri"; w[6]="Sat" | |
| 372 | |
| 373 '"$month_data"' | |
| 374 } | |
| 375 | |
| 376 { | |
| 377 newlog = substr($0, 1 + index($0, CR)) | |
| 378 | |
| 379 # Ignore log entries prefixed by "#". | |
| 380 if (newlog ~ /^#/) { next } | |
| 381 | |
| 382 if (Log != newlog || date != $2 || author != $4) { | |
| 383 | |
| 384 # The previous log and this log differ. | |
| 385 | |
| 386 # Print the old log. | |
| 387 if (date != "") '"$printlogline"' | |
| 388 | |
| 389 # Logs that begin with "{clumpname} " should be grouped together, | |
| 390 # and the clumpname should be removed. | |
| 391 # Extract the new clumpname from the log header, | |
| 392 # and use it to decide whether to output a blank line. | |
| 393 newclumpname = "" | |
| 394 sep = "\n" | |
| 395 if (date == "") sep = "" | |
| 396 if (newlog ~ /^\{[^ }]*}[ ]/) { | |
| 397 i = index(newlog, "}") | |
| 398 newclumpname = substr(newlog, 1, i) | |
| 399 while (substr(newlog, i+1) ~ /^[ ]/) i++ | |
| 400 newlog = substr(newlog, i+1) | |
| 401 if (clumpname == newclumpname) sep = "" | |
| 402 } | |
| 403 printf sep | |
| 404 clumpname = newclumpname | |
| 405 | |
| 406 # Get ready for the next log. | |
| 407 Log = newlog | |
| 408 if (files != "") | |
| 409 for (i in filesknown) | |
| 410 filesknown[i] = 0 | |
| 411 files = "" | |
| 412 } | |
| 413 if (date != $2 || author != $4) { | |
| 414 # The previous date+author and this date+author differ. | |
| 415 # Print the new one. | |
| 416 date = $2 | |
| 417 author = $4 | |
| 418 | |
| 419 # Convert nice RCS date like "1992/01/03 00:03:44" | |
| 420 # into ugly ctime date like "Fri Jan 3 00:03:44 1992". | |
| 421 # Calculate day of week from Gregorian calendar. | |
| 422 i = index($2, "/") | |
| 423 year = substr($2, 1, i-1) + 0 | |
| 424 monthday = substr($2, i+1) | |
| 425 i = index(monthday, "/") | |
| 426 month = substr(monthday, 1, i-1) + 0 | |
| 427 day = substr(monthday, i+1) + 0 | |
| 428 leap = 0 | |
| 429 if (2 < month && year%4 == 0 && (year%100 != 0 || year%400 == 0)) leap = 1 | |
| 430 days_since_Sunday_before_epoch = EPOCH_WEEKDAY + year * 365 + int((year + 3) / 4) - int((year + 99) / 100) + int((year + 399) / 400) + mo[month-1] + leap + day - 1 | |
| 431 | |
| 432 # Print "date fullname (email address)". | |
| 433 # Get fullname and email address from associative arrays; | |
| 434 # default to author and author@hostname if not in arrays. | |
| 435 if (fullname[author]) | |
| 436 auth = fullname[author] | |
| 437 else | |
| 438 auth = author | |
| 439 printf "%s %s %2d %s %d %s ", w[days_since_Sunday_before_epoch%7], m[month-1], day, $3, year, auth | |
| 440 if (mailaddr[author]) | |
| 441 printf "<%s>\n\n", mailaddr[author] | |
| 442 else | |
| 443 printf "<%s@%s>\n\n", author, "'"$hostname"'" | |
| 444 } | |
| 445 if (! filesknown[$1]) { | |
| 446 filesknown[$1] = 1 | |
| 447 if (files == "") files = " " $1 | |
| 448 else files = files ", " $1 | |
| 449 } | |
| 450 } | |
| 451 END { | |
| 452 # Print the last log. | |
| 453 if (date != "") { | |
| 454 '"$printlogline"' | |
| 455 printf "\n" | |
| 456 } | |
| 457 } | |
| 458 ' && | |
| 459 | |
| 460 | |
| 461 # Exit successfully. | |
| 462 | |
| 463 exec rm -f $loginsout $rlogout |
