Mercurial > emacs
annotate lib-src/rcs2log @ 636:dce8cdbac0ea
Ignore log messages that start with `#'.
| author | Paul Eggert <eggert@twinsun.com> |
|---|---|
| date | Fri, 08 May 1992 21:45:00 +0000 |
| parents | d2de231ee7f5 |
| children | 36e7f4e402bd |
| rev | line source |
|---|---|
| 527 | 1 #!/bin/sh |
| 2 | |
| 3 # RCS to ChangeLog generator | |
| 4 | |
|
636
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
5 # $Id: rcs2log,v 1.5 1992/04/01 08:57:55 eggert Exp eggert $ |
| 527 | 6 |
| 7 # Generate a change log prefix from RCS/* and the existing ChangeLog (if any). | |
| 8 # Output the new prefix to standard output. | |
| 9 # You can edit this prefix by hand, and then prepend it to ChangeLog. | |
| 10 | |
|
636
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
11 # Ignore log entries that start with `#'. |
|
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
12 # Clump together log entries that start with `{topic} ', |
|
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
13 # where `topic' contains neither white space nor `}'. |
| 527 | 14 |
| 534 | 15 # Parse options. |
| 16 | |
| 17 # defaults | |
| 18 indent=8 # indent of log line | |
| 19 length=79 # suggested max width of log line | |
| 20 tabwidth=8 # width of horizontal tab | |
| 21 | |
| 22 while : | |
| 23 do | |
| 24 case $1 in | |
| 25 -i) indent=${2?};; | |
| 26 -l) length=${2?};; | |
| 27 -t) tabwidth=${2?};; | |
| 28 -*) echo >&2 "$0: usage: $0 [-i indent] [-l length] [-t tabwidth] [file ...]" | |
| 29 exit 1;; | |
| 30 *) break | |
| 31 esac | |
| 32 shift; shift | |
| 33 done | |
| 34 | |
| 35 | |
| 527 | 36 # Log into $rlogout the revisions checked in since the first ChangeLog entry. |
| 37 | |
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
38 date=1970 |
| 527 | 39 if test -s ChangeLog |
| 40 then | |
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
41 # Add 1 to seconds to avoid duplicating most recent log. |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
42 # It's a good thing `rlog' doesn't mind a time ending in `:60'. |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
43 e=' |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
44 /^... ... [ 0-9][0-9] [ 0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9]+ /{ |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
45 printf "%s%.2d %s\n", substr($0,1,17), substr($0,18,2)+1, $5 |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
46 exit |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
47 } |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
48 ' |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
49 d=`awk "$e" <ChangeLog` || exit |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
50 case $d in |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
51 ?*) date=$d |
|
535
4b75abb93479
Don't munge $* when getting date from ChangeLog.
Paul Eggert <eggert@twinsun.com>
parents:
534
diff
changeset
|
52 esac |
| 527 | 53 fi |
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
54 datearg="-d>$date" |
| 527 | 55 |
| 56 rlogout=/tmp/chg$$ | |
| 57 trap exit 1 2 13 15 | |
| 58 trap 'rm -f $rlogout; exit 1' 0 | |
| 59 | |
| 534 | 60 case $# in |
| 61 0) set RCS/* | |
| 62 esac | |
| 63 | |
| 64 rlog "$datearg" "$@" >$rlogout || exit | |
| 527 | 65 |
| 66 | |
| 67 # Get the full name of each author the logs mention, and set initialize_fullname | |
| 68 # to awk code that initializes the `fullname' awk associative array. | |
| 69 # Warning: foreign authors (i.e. not known in the passwd file) are mishandled; | |
| 70 # you have to fix the resulting output by hand. | |
| 71 | |
| 72 authors=` | |
| 73 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]; *author: *\([^; ]*\).*|\1|p' <$rlogout | | |
| 74 sort -u | |
| 75 ` | |
| 76 | |
| 77 initialize_fullname= | |
| 78 for author in $authors | |
| 79 do | |
| 80 fullname=` | |
| 81 (grep "^$author:" /etc/passwd || ypmatch "$author" passwd) | | |
| 82 sed -n 's/^[^:]*:[^:]*:[^:]*:[^:]*:\([^,:]*\).*$/\1/;p;q' | |
| 83 ` | |
| 84 case $fullname in | |
| 85 *\&*) | |
| 86 User=` | |
| 87 expr " $author" : ' \(.\)' | | |
| 88 tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | |
| 89 `` | |
| 90 expr " $author" : ' .\(.*\)' | |
| 91 ` | |
| 92 fullname=`echo "$fullname" | sed "s:&:$User:"` | |
| 93 esac | |
| 534 | 94 case $fullname in |
| 95 ?*) | |
| 96 initialize_fullname="$initialize_fullname | |
| 97 fullname[\"$author\"] = \"$fullname\"" | |
| 98 esac | |
| 527 | 99 done |
| 100 | |
| 101 | |
| 102 # Function to print a single log line. | |
| 103 # We don't use awk functions, to stay compatible with old awk versions. | |
| 104 # `Log' is the log message (with \n replaced by \r). | |
| 594 | 105 # `files' contains the affected files. |
| 527 | 106 printlogline='{ |
| 107 | |
| 108 # Following the GNU coding standards, rewrite | |
| 109 # * file: (function): comment | |
| 110 # to | |
| 111 # * file (function): comment | |
| 112 if (Log ~ /^\([^)]*\): /) { | |
| 113 i = index(Log, ")") | |
| 114 files = files " " substr(Log, 1, i) | |
| 115 Log = substr(Log, i+3) | |
| 116 } | |
| 117 | |
| 118 # If "label: comment" is too long, break the line after the ":". | |
| 119 sep = " " | |
| 534 | 120 if ('"$length"' <= '"$indent"' + 1 + length(files) + index(Log, "\r")) sep = "\n" indent_string |
| 527 | 121 |
| 122 # Print the label. | |
| 534 | 123 printf "%s*%s:", indent_string, files |
| 527 | 124 |
| 125 # Print each line of the log, transliterating \r to \n. | |
| 126 while ((i = index(Log, "\r")) != 0) { | |
| 127 printf "%s%s\n", sep, substr(Log, 1, i-1) | |
| 534 | 128 sep = indent_string |
| 527 | 129 Log = substr(Log, i+1) |
| 130 } | |
| 131 }' | |
| 132 | |
| 133 hostname=`( | |
| 134 hostname || cat /etc/whoami || uuname -l || uname -n | |
| 135 ) 2>/dev/null` || { | |
| 136 echo >&2 "$0: cannot deduce hostname" | |
| 137 exit 1 | |
| 138 } | |
| 139 | |
| 140 | |
| 141 # Process the rlog output, generating ChangeLog style entries. | |
| 142 | |
| 143 # First, reformat the rlog output so that each line contains one log entry. | |
| 144 # Transliterate \n to \r so that multiline entries fit on a single line. | |
| 145 # Discard irrelevant rlog output. | |
| 146 awk <$rlogout ' | |
| 147 /^Working file:/ { filename = $3 } | |
| 148 /^date: /, /^(-----------*|===========*)$/ { | |
| 149 if ($0 ~ /^branches: /) { next } | |
| 150 if ($0 ~ /^date: [0-9][ /0-9:]*;/) { | |
| 151 time = substr($3, 1, length($3)-1) | |
| 152 author = substr($5, 1, length($5)-1) | |
| 153 printf "%s %s %s %s \r", filename, $2, time, author | |
| 154 next | |
| 155 } | |
|
636
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
156 if ($0 ~ /^(-----------*|===========*)$/) { print ""; next } |
|
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
157 printf "%s\r", $0 |
| 527 | 158 } |
| 159 ' | | |
| 160 | |
| 161 # Now each line is of the form | |
| 162 # FILENAME YYYY/MM/DD HH:MM:SS AUTHOR \rLOG | |
| 163 # where \r stands for a carriage return, | |
| 164 # and each line of the log is terminated by \r instead of \n. | |
| 165 # Sort the log entries, first by date (in reverse order), | |
| 166 # then by author, then by log entry, and finally by file name (just in case). | |
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
167 sort +1 -3r +3 +0 | |
| 527 | 168 |
| 169 # Finally, reformat the sorted log entries. | |
| 170 awk ' | |
| 171 BEGIN { | |
| 172 | |
| 173 # Initialize the fullname associative array. | |
| 174 '"$initialize_fullname"' | |
| 175 | |
| 534 | 176 # Initialize indent string. |
| 177 indent_string = "" | |
| 178 i = '"$indent"' | |
| 179 if (0 < '"$tabwidth"') | |
| 180 for (; '"$tabwidth"' <= i; i -= '"$tabwidth"') | |
| 181 indent_string = indent_string "\t" | |
| 182 while (1 <= i--) | |
| 183 indent_string = indent_string " " | |
| 184 | |
| 527 | 185 # Set up date conversion tables. |
| 186 # RCS uses a nice, clean, sortable format, | |
| 187 # but ChangeLog wants the traditional, ugly ctime format. | |
| 188 | |
| 189 # January 1, 0 AD (Gregorian) was Saturday = 6 | |
| 190 EPOCH_WEEKDAY = 6 | |
| 191 # Of course, there was no 0 AD, but the algorithm works anyway. | |
| 192 | |
| 193 w[0]="Sun"; w[1]="Mon"; w[2]="Tue"; w[3]="Wed" | |
| 194 w[4]="Thu"; w[5]="Fri"; w[6]="Sat" | |
| 195 | |
| 196 m[0]="Jan"; m[1]="Feb"; m[2]="Mar" | |
| 197 m[3]="Apr"; m[4]="May"; m[5]="Jun" | |
| 198 m[6]="Jul"; m[7]="Aug"; m[8]="Sep" | |
| 199 m[9]="Oct"; m[10]="Nov"; m[11]="Dec" | |
| 200 | |
| 201 # days in non-leap year thus far, indexed by month (0-12) | |
| 202 mo[0]=0; mo[1]=31; mo[2]=59; mo[3]=90 | |
| 203 mo[4]=120; mo[5]=151; mo[6]=181; mo[7]=212 | |
| 204 mo[8]=243; mo[9]=273; mo[10]=304; mo[11]=334 | |
| 205 mo[12]=365 | |
| 206 } | |
|
636
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
207 |
| 527 | 208 { |
| 209 newlog = substr($0, 1 + index($0, "\r")) | |
|
636
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
210 |
|
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
211 # Ignore log entries prefixed by "#". |
|
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
212 if (newlog ~ /^#/) { next } |
|
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
213 |
| 527 | 214 if (Log != newlog || date != $2 || author != $4) { |
| 594 | 215 |
| 527 | 216 # The previous log and this log differ. |
| 594 | 217 |
| 218 # Print the old log. | |
| 527 | 219 if (date != "") '"$printlogline"' |
| 220 | |
| 594 | 221 # Logs that begin with "{clumpname} " should be grouped together, |
| 222 # and the clumpname should be removed. | |
| 223 # Extract the new clumpname from the log header, | |
| 224 # and use it to decide whether to output a blank line. | |
| 225 newclumpname = "" | |
| 226 sep = "\n" | |
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
227 if (date == "") sep = "" |
|
636
dce8cdbac0ea
Ignore log messages that start with `#'.
Paul Eggert <eggert@twinsun.com>
parents:
602
diff
changeset
|
228 if (newlog ~ /^{[^ }]*}[ ]/) { |
| 594 | 229 i = index(newlog, "}") |
| 230 newclumpname = substr(newlog, 1, i) | |
| 231 while (substr(newlog, i+1) ~ /^[ ]/) i++ | |
| 232 newlog = substr(newlog, i+1) | |
| 233 if (clumpname == newclumpname) sep = "" | |
| 234 } | |
| 235 printf sep | |
| 236 clumpname = newclumpname | |
| 237 | |
| 527 | 238 # Get ready for the next log. |
| 239 Log = newlog | |
| 534 | 240 if (files != "") |
| 241 for (i in filesknown) | |
| 242 filesknown[i] = 0 | |
| 527 | 243 files = "" |
| 244 } | |
| 245 if (date != $2 || author != $4) { | |
| 246 # The previous date+author and this date+author differ. | |
| 247 # Print the new one. | |
| 248 date = $2 | |
| 249 author = $4 | |
| 250 | |
| 251 # Convert nice RCS date like "1992/01/03 00:03:44" | |
| 252 # into ugly ctime date like "Fri Jan 3 00:03:44 1992". | |
| 253 # Calculate day of week from Gregorian calendar. | |
| 254 i = index($2, "/") | |
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
255 year = substr($2, 1, i-1) + 0 |
| 527 | 256 monthday = substr($2, i+1) |
| 257 i = index(monthday, "/") | |
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
258 month = substr(monthday, 1, i-1) + 0 |
|
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
259 day = substr(monthday, i+1) + 0 |
| 527 | 260 leap = 0 |
|
602
d2de231ee7f5
Don't duplicate most recent logs. Fix bug in dates after Feb 29 in leap year.
Paul Eggert <eggert@twinsun.com>
parents:
594
diff
changeset
|
261 if (2 < month && year%4 == 0 && (year%100 != 0 || year%400 == 0)) leap = 1 |
| 527 | 262 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 |
| 263 | |
| 534 | 264 # Print "date fullname (email address)" if the fullname is known; |
| 265 # print "date author" otherwise. | |
| 527 | 266 # Get the fullname from the associative array. |
| 267 # The email address is just author@thishostname. | |
| 534 | 268 printf "%s %s %2d %s %d ", w[days_since_Sunday_before_epoch%7], m[month-1], day, $3, year |
| 269 if (fullname[author]) | |
| 270 printf "%s (%s@%s)\n\n", fullname[author], author, "'"$hostname"'" | |
| 271 else | |
| 272 printf "%s\n\n", author | |
| 527 | 273 } |
| 534 | 274 if (! filesknown[$1]) { |
| 275 filesknown[$1] = 1 | |
| 594 | 276 if (files == "") files = " " $1 |
| 277 else files = files ", " $1 | |
| 534 | 278 } |
| 527 | 279 } |
| 280 END { | |
| 281 # Print the last log. | |
| 594 | 282 if (date != "") { |
| 283 '"$printlogline"' | |
| 284 printf "\n" | |
| 285 } | |
| 527 | 286 } |
| 287 ' && | |
| 288 | |
| 289 | |
| 290 # Exit successfully. | |
| 291 | |
| 292 exec rm -f $rlogout |
