/
parserevlog.py
59 lines (52 loc) · 1.49 KB
/
parserevlog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
import string
import re
seen = {}
heads = []
current = None
parents = []
branch = 'null'
summary = ''
print """// Autogenerated
load("diff.js");
load("graph.js");
load("fs.js");
load("draw.js");
var repoExt = {
revisions: {},
bodies: {}
};
"""
for line in sys.stdin.readlines():
line = line.strip()
if line:
(keyword, value) = line.split(':', 1)
if keyword == "changeset":
current = value.strip().split(':')[0]
elif keyword == 'parent':
p = value.strip().split(':')[0]
parents.append(p)
elif keyword == 'summary':
summary = value.strip()
elif keyword == 'branch':
branch = repr(value.strip())
else:
if not parents:
p = int(current) - 1
if p >= 0:
parents.append(str(p))
for p in parents:
seen[p] = 1
if not seen.has_key(current):
heads.append(current)
if len(parents) > 2:
raise 'Too many parents in revision %s' % current
print """repoExt.revisions["%s"] = { alive: {}, dead: {}, changed: [], branch: %s, metadata: {summary: %s}, timestamp: 0, directParent: %s, additionalParent: %s };""" % tuple([current, branch, repr(summary)] + ([repr(x) for x in parents] + ["null", "null"])[:2])
current = None
parents = []
branch = 'null'
print """
var repo = new Dvcs.Repository();
repo.importRevisions(repoExt);
print(DrawDvcs.simpleRenderRepository(repo));
"""