blob: b26f30b3a050a542df3e8e9e215efbba42864397 [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossumdb9c0541996-07-30 19:05:41 +00002
3"""Turn a pile of RCS log output into ChangeLog file entries.
4
5"""
6
7import sys
8import string
9import regex
10import getopt
11import time
12
13def main():
14 args = sys.argv[1:]
15 opts, args = getopt.getopt(args, 'p:')
16 prefix = ''
17 for o, a in opts:
Guido van Rossum4117e541998-09-14 16:44:15 +000018 if p == '-p': prefix = a
Guido van Rossumdb9c0541996-07-30 19:05:41 +000019
20 f = sys.stdin
21 allrevs = []
22 while 1:
Guido van Rossum4117e541998-09-14 16:44:15 +000023 file = getnextfile(f)
24 if not file: break
25 revs = []
26 while 1:
27 rev = getnextrev(f, file)
28 if not rev:
29 break
30 revs.append(rev)
31 if revs:
32 allrevs[len(allrevs):] = revs
Guido van Rossumdb9c0541996-07-30 19:05:41 +000033 allrevs.sort()
34 allrevs.reverse()
35 for rev in allrevs:
Guido van Rossum4117e541998-09-14 16:44:15 +000036 formatrev(rev, prefix)
Guido van Rossumdb9c0541996-07-30 19:05:41 +000037
38parsedateprog = regex.compile(
39 '^date: \([0-9]+\)/\([0-9]+\)/\([0-9]+\) ' +
40 '\([0-9]+\):\([0-9]+\):\([0-9]+\); author: \([^ ;]+\)')
41
42authormap = {
43 'guido': 'Guido van Rossum <guido@cnri.reston.va.us>',
44 'jack': 'Jack Jansen <jack@cwi.nl>',
45 'sjoerd': 'Sjoerd Mullender <sjoerd@cwi.nl>',
46 }
47
48def formatrev(rev, prefix):
49 dateline, file, revline, log = rev
50 if parsedateprog.match(dateline) >= 0:
Guido van Rossum4117e541998-09-14 16:44:15 +000051 fields = parsedateprog.group(1, 2, 3, 4, 5, 6)
52 author = parsedateprog.group(7)
53 if authormap.has_key(author): author = authormap[author]
54 tfields = map(string.atoi, fields) + [0, 0, 0]
55 tfields[5] = tfields[5] - time.timezone
56 t = time.mktime(tuple(tfields))
57 print time.ctime(t), '', author
58 words = string.split(log)
59 words[:0] = ['*', prefix + file + ':']
60 maxcol = 72-8
61 col = maxcol
62 for word in words:
63 if col > 0 and col + len(word) >= maxcol:
64 print
65 print '\t' + word,
66 col = -1
67 else:
68 print word,
69 col = col + 1 + len(word)
70 print
71 print
Guido van Rossumdb9c0541996-07-30 19:05:41 +000072
73startprog = regex.compile("^Working file: \(.*\)$")
74
75def getnextfile(f):
76 while 1:
Guido van Rossum4117e541998-09-14 16:44:15 +000077 line = f.readline()
78 if not line: return None
79 if startprog.match(line) >= 0:
80 file = startprog.group(1)
81 # Skip until first revision
82 while 1:
83 line = f.readline()
84 if not line: return None
85 if line[:10] == '='*10: return None
86 if line[:10] == '-'*10: break
87## print "Skipped", line,
88 return file
89## else:
90## print "Ignored", line,
Guido van Rossumdb9c0541996-07-30 19:05:41 +000091
92def getnextrev(f, file):
93 # This is called when we are positioned just after a '---' separator
94 revline = f.readline()
95 dateline = f.readline()
96 log = ''
97 while 1:
Guido van Rossum4117e541998-09-14 16:44:15 +000098 line = f.readline()
99 if not line: break
100 if line[:10] == '='*10:
101 # Ignore the *last* log entry for each file since it
102 # is the revision since which we are logging.
103 return None
104 if line[:10] == '-'*10: break
105 log = log + line
Guido van Rossumdb9c0541996-07-30 19:05:41 +0000106 return dateline, file, revline, log
107
108if __name__ == '__main__':
109 main()