| 1 |
# Read the output of a "svn log --xml" command on stdin, parse it and |
| 2 |
# print a subset of attributes common to all svn versions tested by |
| 3 |
# hg. |
| 4 |
import sys |
| 5 |
import xml.dom.minidom |
| 6 |
|
| 7 |
|
| 8 |
def xmltext(e): |
| 9 |
return ''.join(c.data for c in e.childNodes if c.nodeType == c.TEXT_NODE) |
| 10 |
|
| 11 |
|
| 12 |
def parseentry(entry): |
| 13 |
e = {} |
| 14 |
e['revision'] = entry.getAttribute('revision') |
| 15 |
e['author'] = xmltext(entry.getElementsByTagName('author')[0]) |
| 16 |
e['msg'] = xmltext(entry.getElementsByTagName('msg')[0]) |
| 17 |
e['date'] = xmltext(entry.getElementsByTagName('date')[0]) |
| 18 |
e['paths'] = [] |
| 19 |
paths = entry.getElementsByTagName('paths') |
| 20 |
if paths: |
| 21 |
paths = paths[0] |
| 22 |
for p in paths.getElementsByTagName('path'): |
| 23 |
action = p.getAttribute('action').encode('utf-8') |
| 24 |
path = xmltext(p).encode('utf-8') |
| 25 |
frompath = p.getAttribute('copyfrom-path').encode('utf-8') |
| 26 |
fromrev = p.getAttribute('copyfrom-rev').encode('utf-8') |
| 27 |
e['paths'].append((path, action, frompath, fromrev)) |
| 28 |
return e |
| 29 |
|
| 30 |
|
| 31 |
def parselog(data): |
| 32 |
entries = [] |
| 33 |
doc = xml.dom.minidom.parseString(data) |
| 34 |
for e in doc.getElementsByTagName('logentry'): |
| 35 |
entries.append(parseentry(e)) |
| 36 |
return entries |
| 37 |
|
| 38 |
|
| 39 |
def printentries(entries): |
| 40 |
try: |
| 41 |
fp = sys.stdout.buffer |
| 42 |
except AttributeError: |
| 43 |
fp = sys.stdout |
| 44 |
for e in entries: |
| 45 |
for k in ('revision', 'author', 'date', 'msg'): |
| 46 |
fp.write(('%s: %s\n' % (k, e[k])).encode('utf-8')) |
| 47 |
for path, action, fpath, frev in sorted(e['paths']): |
| 48 |
frominfo = b'' |
| 49 |
if frev: |
| 50 |
frominfo = b' (from %s@%s)' % (fpath, frev) |
| 51 |
p = b' %s %s%s\n' % (action, path, frominfo) |
| 52 |
fp.write(p) |
| 53 |
|
| 54 |
|
| 55 |
if __name__ == '__main__': |
| 56 |
data = sys.stdin.read() |
| 57 |
entries = parselog(data) |
| 58 |
printentries(entries) |