3 """Consolidate a bunch of CVS or RCS logs read from stdin.
5 Input should be the output of a CVS or RCS logging command, e.g.
9 which dumps all log messages from release1.4 upwards (assuming that
10 release 1.4 was tagged with tag 'release14'). Note the trailing
13 This collects all the revision records and outputs them sorted by date
14 rather than by file, collapsing duplicate revision record, i.e.,
15 records with the same message for different files.
17 The -t option causes it to truncate (discard) the last revision log
18 entry; this is useful when using something like the above cvs log
19 command, which shows the revisions including the given tag, while you
20 probably want everything *since* that tag.
22 XXX This code was created by reverse engineering CVS 1.9 and RCS 5.7
27 import os
, sys
, getopt
, string
, re
29 sep1
= '='*77 + '\n' # file separator
30 sep2
= '-'*28 + '\n' # revision separator
36 opts
, args
= getopt
.getopt(sys
.argv
[1:], "tr")
44 chunk
= read_chunk(sys
.stdin
)
47 records
= digest_chunk(chunk
)
50 database
[len(database
):] = records
54 format_output(database
)
57 """Read a chunk -- data for one file, ending with sep1.
59 Split the chunk in parts separated by sep2.
80 def digest_chunk(chunk
):
81 """Digest a chunk -- extrach working file name and revisions"""
86 if line
[:keylen
] == key
:
87 working_file
= string
.strip(line
[keylen
:])
92 for lines
in chunk
[1:]:
96 words
= string
.split(dateline
)
98 if len(words
) >= 3 and words
[0] == 'date:':
101 if timeword
[-1:] == ';':
102 timeword
= timeword
[:-1]
103 date
= dateword
+ ' ' + timeword
104 if len(words
) >= 5 and words
[3] == 'author:':
106 if author
[-1:] == ';':
110 text
.insert(0, revline
)
111 words
= string
.split(revline
)
112 if len(words
) >= 2 and words
[0] == 'revision':
116 text
.insert(0, revline
)
117 records
.append((date
, working_file
, rev
, author
, text
))
120 def format_output(database
):
123 database
.append((None, None, None, None, None)) # Sentinel
124 for (date
, working_file
, rev
, author
, text
) in database
:
128 for (p_date
, p_working_file
, p_rev
, p_author
) in prev
:
129 print p_date
, p_author
, p_working_file
, p_rev
130 sys
.stdout
.writelines(prevtext
)
132 prev
.append((date
, working_file
, rev
, author
))