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