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