1997-08-14 19:04:00 -03:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
"""Consolidate a bunch of CVS or RCS logs read from stdin.
|
|
|
|
|
|
|
|
Input should be the output of a CVS or RCS logging command, e.g.
|
|
|
|
|
1997-10-06 18:09:32 -03:00
|
|
|
cvs log -rrelease14:
|
1997-08-14 19:04:00 -03:00
|
|
|
|
|
|
|
which dumps all log messages from release1.4 upwards (assuming that
|
1997-10-06 18:09:32 -03:00
|
|
|
release 1.4 was tagged with tag 'release14'). Note the trailing
|
|
|
|
colon!
|
1997-08-14 19:04:00 -03:00
|
|
|
|
|
|
|
This collects all the revision records and outputs them sorted by date
|
|
|
|
rather than by file, collapsing duplicate revision record, i.e.,
|
|
|
|
records with the same message for different files.
|
|
|
|
|
|
|
|
The -t option causes it to truncate (discard) the last revision log
|
|
|
|
entry; this is useful when using something like the above cvs log
|
|
|
|
command, which shows the revisions including the given tag, while you
|
|
|
|
probably want everything *since* that tag.
|
|
|
|
|
2002-09-29 01:37:36 -03:00
|
|
|
The -r option reverses the output (oldest first; the default is oldest
|
|
|
|
last).
|
|
|
|
|
|
|
|
The -b tag option restricts the output to *only* checkin messages
|
|
|
|
belonging to the given branch tag. The form -b HEAD restricts the
|
|
|
|
output to checkin messages belonging to the CVS head (trunk). (It
|
|
|
|
produces some output if tag is a non-branch tag, but this output is
|
|
|
|
not very useful.)
|
|
|
|
|
2003-04-19 21:59:24 -03:00
|
|
|
-h prints this message and exits.
|
|
|
|
|
1997-10-06 18:09:32 -03:00
|
|
|
XXX This code was created by reverse engineering CVS 1.9 and RCS 5.7
|
|
|
|
from their output.
|
1997-08-14 19:04:00 -03:00
|
|
|
"""
|
|
|
|
|
2008-02-23 14:30:17 -04:00
|
|
|
import sys, errno, getopt, re
|
1997-08-14 19:04:00 -03:00
|
|
|
|
1998-03-24 01:30:29 -04:00
|
|
|
sep1 = '='*77 + '\n' # file separator
|
|
|
|
sep2 = '-'*28 + '\n' # revision separator
|
1997-08-14 19:04:00 -03:00
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Main program"""
|
|
|
|
truncate_last = 0
|
2000-02-14 17:41:50 -04:00
|
|
|
reverse = 0
|
2002-09-29 01:37:36 -03:00
|
|
|
branch = None
|
2003-04-19 21:59:24 -03:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "trb:h")
|
1997-08-14 19:04:00 -03:00
|
|
|
for o, a in opts:
|
1998-03-24 01:30:29 -04:00
|
|
|
if o == '-t':
|
|
|
|
truncate_last = 1
|
2000-02-14 17:41:50 -04:00
|
|
|
elif o == '-r':
|
|
|
|
reverse = 1
|
2002-09-29 01:37:36 -03:00
|
|
|
elif o == '-b':
|
|
|
|
branch = a
|
2003-04-19 21:59:24 -03:00
|
|
|
elif o == '-h':
|
2007-08-03 14:06:41 -03:00
|
|
|
print(__doc__)
|
2003-04-19 21:59:24 -03:00
|
|
|
sys.exit(0)
|
1997-08-14 19:04:00 -03:00
|
|
|
database = []
|
|
|
|
while 1:
|
1998-03-24 01:30:29 -04:00
|
|
|
chunk = read_chunk(sys.stdin)
|
|
|
|
if not chunk:
|
|
|
|
break
|
2002-09-29 01:37:36 -03:00
|
|
|
records = digest_chunk(chunk, branch)
|
1998-03-24 01:30:29 -04:00
|
|
|
if truncate_last:
|
|
|
|
del records[-1]
|
|
|
|
database[len(database):] = records
|
1997-08-14 19:04:00 -03:00
|
|
|
database.sort()
|
2000-02-14 17:41:50 -04:00
|
|
|
if not reverse:
|
|
|
|
database.reverse()
|
1997-08-14 19:04:00 -03:00
|
|
|
format_output(database)
|
|
|
|
|
|
|
|
def read_chunk(fp):
|
|
|
|
"""Read a chunk -- data for one file, ending with sep1.
|
|
|
|
|
|
|
|
Split the chunk in parts separated by sep2.
|
|
|
|
|
|
|
|
"""
|
|
|
|
chunk = []
|
|
|
|
lines = []
|
|
|
|
while 1:
|
1998-03-24 01:30:29 -04:00
|
|
|
line = fp.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
if line == sep1:
|
|
|
|
if lines:
|
|
|
|
chunk.append(lines)
|
|
|
|
break
|
|
|
|
if line == sep2:
|
|
|
|
if lines:
|
|
|
|
chunk.append(lines)
|
|
|
|
lines = []
|
|
|
|
else:
|
|
|
|
lines.append(line)
|
1997-08-14 19:04:00 -03:00
|
|
|
return chunk
|
|
|
|
|
2002-09-29 01:37:36 -03:00
|
|
|
def digest_chunk(chunk, branch=None):
|
|
|
|
"""Digest a chunk -- extract working file name and revisions"""
|
1997-08-14 19:04:00 -03:00
|
|
|
lines = chunk[0]
|
|
|
|
key = 'Working file:'
|
|
|
|
keylen = len(key)
|
|
|
|
for line in lines:
|
1998-03-24 01:30:29 -04:00
|
|
|
if line[:keylen] == key:
|
2002-09-11 17:36:02 -03:00
|
|
|
working_file = line[keylen:].strip()
|
1998-03-24 01:30:29 -04:00
|
|
|
break
|
1997-08-14 19:04:00 -03:00
|
|
|
else:
|
1998-03-24 01:30:29 -04:00
|
|
|
working_file = None
|
2003-01-07 12:46:24 -04:00
|
|
|
if branch is None:
|
|
|
|
pass
|
|
|
|
elif branch == "HEAD":
|
|
|
|
branch = re.compile(r"^\d+\.\d+$")
|
|
|
|
else:
|
2002-09-29 01:37:36 -03:00
|
|
|
revisions = {}
|
|
|
|
key = 'symbolic names:\n'
|
|
|
|
found = 0
|
|
|
|
for line in lines:
|
|
|
|
if line == key:
|
|
|
|
found = 1
|
|
|
|
elif found:
|
|
|
|
if line[0] in '\t ':
|
|
|
|
tag, rev = line.split()
|
|
|
|
if tag[-1] == ':':
|
|
|
|
tag = tag[:-1]
|
|
|
|
revisions[tag] = rev
|
|
|
|
else:
|
|
|
|
found = 0
|
|
|
|
rev = revisions.get(branch)
|
2003-01-07 12:46:24 -04:00
|
|
|
branch = re.compile(r"^<>$") # <> to force a mismatch by default
|
2002-09-29 01:37:36 -03:00
|
|
|
if rev:
|
|
|
|
if rev.find('.0.') >= 0:
|
2003-01-07 12:46:24 -04:00
|
|
|
rev = rev.replace('.0.', '.')
|
|
|
|
branch = re.compile(r"^" + re.escape(rev) + r"\.\d+$")
|
1997-08-14 19:04:00 -03:00
|
|
|
records = []
|
|
|
|
for lines in chunk[1:]:
|
1998-03-24 01:30:29 -04:00
|
|
|
revline = lines[0]
|
|
|
|
dateline = lines[1]
|
|
|
|
text = lines[2:]
|
2002-09-11 17:36:02 -03:00
|
|
|
words = dateline.split()
|
1998-03-24 01:30:29 -04:00
|
|
|
author = None
|
|
|
|
if len(words) >= 3 and words[0] == 'date:':
|
|
|
|
dateword = words[1]
|
|
|
|
timeword = words[2]
|
|
|
|
if timeword[-1:] == ';':
|
|
|
|
timeword = timeword[:-1]
|
|
|
|
date = dateword + ' ' + timeword
|
|
|
|
if len(words) >= 5 and words[3] == 'author:':
|
|
|
|
author = words[4]
|
|
|
|
if author[-1:] == ';':
|
|
|
|
author = author[:-1]
|
|
|
|
else:
|
|
|
|
date = None
|
|
|
|
text.insert(0, revline)
|
2002-09-11 17:36:02 -03:00
|
|
|
words = revline.split()
|
1998-03-24 01:30:29 -04:00
|
|
|
if len(words) >= 2 and words[0] == 'revision':
|
|
|
|
rev = words[1]
|
|
|
|
else:
|
2003-01-07 12:46:24 -04:00
|
|
|
# No 'revision' line -- weird...
|
1998-03-24 01:30:29 -04:00
|
|
|
rev = None
|
|
|
|
text.insert(0, revline)
|
2002-09-29 01:37:36 -03:00
|
|
|
if branch:
|
2003-01-07 12:46:24 -04:00
|
|
|
if rev is None or not branch.match(rev):
|
2002-09-29 01:37:36 -03:00
|
|
|
continue
|
1998-03-24 01:30:29 -04:00
|
|
|
records.append((date, working_file, rev, author, text))
|
1997-08-14 19:04:00 -03:00
|
|
|
return records
|
2001-01-17 04:48:39 -04:00
|
|
|
|
1997-08-14 19:04:00 -03:00
|
|
|
def format_output(database):
|
|
|
|
prevtext = None
|
|
|
|
prev = []
|
1997-10-06 18:09:32 -03:00
|
|
|
database.append((None, None, None, None, None)) # Sentinel
|
|
|
|
for (date, working_file, rev, author, text) in database:
|
1998-03-24 01:30:29 -04:00
|
|
|
if text != prevtext:
|
|
|
|
if prev:
|
2007-08-03 14:06:41 -03:00
|
|
|
print(sep2, end=' ')
|
1998-03-24 01:30:29 -04:00
|
|
|
for (p_date, p_working_file, p_rev, p_author) in prev:
|
2007-08-03 14:06:41 -03:00
|
|
|
print(p_date, p_author, p_working_file, p_rev)
|
1998-03-24 01:30:29 -04:00
|
|
|
sys.stdout.writelines(prevtext)
|
|
|
|
prev = []
|
|
|
|
prev.append((date, working_file, rev, author))
|
|
|
|
prevtext = text
|
1997-08-14 19:04:00 -03:00
|
|
|
|
2004-08-09 14:27:55 -03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
main()
|
2007-01-10 12:19:56 -04:00
|
|
|
except IOError as e:
|
2004-08-09 14:27:55 -03:00
|
|
|
if e.errno != errno.EPIPE:
|
|
|
|
raise
|