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