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