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