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));
"""
