/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to serialize_transform.py

  • Committer: Aaron Bentley
  • Date: 2008-10-06 12:40:15 UTC
  • mfrom: (0.12.18 prepare-shelf)
  • mto: This revision was merged to the branch mainline in revision 3823.
  • Revision ID: aaron@aaronbentley.com-20081006124015-9paiamk1br5j8rvg
Merge with prepare-shelf

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
 
3
 
from bzrlib import pack
4
3
from bzrlib.util import bencode
5
4
 
6
5
 
7
 
def serialize(tt):
 
6
def serialize(tt, serializer):
8
7
    new_name = dict((k, v.encode('utf-8')) for k, v in tt._new_name.items())
9
8
    new_executability = dict((k, int(v)) for k, v in
10
9
                             tt._new_executability.items())
21
20
        '_removed_contents': list(tt._removed_contents),
22
21
        '_non_present_ids': tt._non_present_ids,
23
22
        }
24
 
    serializer = pack.ContainerSerialiser()
25
 
    yield serializer.begin()
26
23
    yield serializer.bytes_record(bencode.bencode(attribs), (('attribs',),))
27
24
    for trans_id, kind in tt._new_contents.items():
28
25
        if kind == 'file':
36
33
        if kind == 'symlink':
37
34
            content = os.readlink(tt._limbo_name(trans_id))
38
35
        yield serializer.bytes_record(content, ((trans_id, kind),))
39
 
    yield serializer.end()
40
 
 
41
 
 
42
 
def deserialize(tt, input):
43
 
    parser = pack.ContainerPushParser()
44
 
    for bytes in input:
45
 
        parser.accept_bytes(bytes)
46
 
    iterator = iter(parser.read_pending_records())
47
 
    names, content = iterator.next()
 
36
 
 
37
 
 
38
def deserialize(tt, records):
 
39
    names, content = records.next()
48
40
    attribs = bencode.bdecode(content)
49
41
    tt._id_number = attribs['_id_number']
50
42
    tt._new_name = dict((k, v.decode('utf-8'))
63
55
    tt._removed_id = set(attribs['_removed_id'])
64
56
    tt._removed_contents = set(attribs['_removed_contents'])
65
57
    tt._non_present_ids = attribs['_non_present_ids']
66
 
    for ((trans_id, kind),), content in iterator:
 
58
    for ((trans_id, kind),), content in records:
67
59
        if kind == 'file':
68
60
            tt.create_file(content, trans_id)
69
61
        if kind == 'directory':