17
17
"""Serializer object for CHK based inventory storage."""
19
from cStringIO import (
19
23
from bzrlib import (
28
revision as _mod_revision,
26
class CHKSerializerSubtree(xml6.Serializer_v6):
33
class BEncodeRevisionSerializer1(object):
34
"""Simple revision serializer based around bencode.
36
It tries to group entries together that are less likely
37
to change often, to make it easier to do compression.
40
def write_revision_to_string(self, rev):
41
encode_utf8 = cache_utf8.encode
43
"revision-id": rev.revision_id,
44
"timestamp": "%.3f" % rev.timestamp,
45
"parent-ids": rev.parent_ids,
46
"inventory-sha1": rev.inventory_sha1,
47
"committer": encode_utf8(rev.committer),
48
"message": encode_utf8(rev.message),
51
for key, value in rev.properties.iteritems():
52
revprops[key] = encode_utf8(value)
53
ret["properties"] = revprops
54
if rev.timezone is not None:
55
ret["timezone"] = str(rev.timezone)
56
return bencode.bencode(ret)
58
def write_revision(self, rev, f):
59
f.write(self.write_revision_to_string(rev))
61
def read_revision_from_string(self, text):
62
decode_utf8 = cache_utf8.decode
63
ret = bencode.bdecode(text)
64
rev = _mod_revision.Revision(
65
committer=decode_utf8(ret["committer"]),
66
revision_id=ret["revision-id"],
67
parent_ids=ret["parent-ids"],
68
inventory_sha1=ret["inventory-sha1"],
69
timestamp=float(ret["timestamp"]),
70
message=decode_utf8(ret["message"]),
73
rev.timezone = int(ret["timezone"])
76
for key, value in ret["properties"].iteritems():
77
rev.properties[key] = decode_utf8(value)
80
def read_revision(self, f):
81
return self.read_revision_from_string(f.read())
84
class CHKSerializerSubtree(BEncodeRevisionSerializer1, xml6.Serializer_v6):
27
85
"""A CHKInventory based serializer that supports tree references"""
29
87
supported_kinds = set(['file', 'directory', 'symlink', 'tree-reference'])