/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.12.10 by Aaron Bentley
Implement symlink serialization
1
import os
2
0.12.1 by Aaron Bentley
Initial bencode-based encoding
3
from bzrlib.util import bencode
4
5
0.13.1 by Aaron Bentley
Serialization does not dictate contents of beginning of file.
6
def serialize(tt, serializer):
0.12.1 by Aaron Bentley
Initial bencode-based encoding
7
    new_name = dict((k, v.encode('utf-8')) for k, v in tt._new_name.items())
0.12.7 by Aaron Bentley
Get executability under test.
8
    new_executability = dict((k, int(v)) for k, v in
9
                             tt._new_executability.items())
0.12.8 by Aaron Bentley
Test deleting and unversioning
10
    tree_path_ids = dict((k.encode('utf-8'), v)
11
                         for k, v in tt._tree_path_ids.items())
0.12.1 by Aaron Bentley
Initial bencode-based encoding
12
    attribs = {
13
        '_id_number': tt._id_number,
14
        '_new_name': new_name,
0.12.2 by Aaron Bentley
Handle parents
15
        '_new_parent': tt._new_parent,
0.12.7 by Aaron Bentley
Get executability under test.
16
        '_new_executability': new_executability,
0.12.1 by Aaron Bentley
Initial bencode-based encoding
17
        '_new_id': tt._new_id,
0.12.8 by Aaron Bentley
Test deleting and unversioning
18
        '_tree_path_ids': tree_path_ids,
19
        '_removed_id': list(tt._removed_id),
20
        '_removed_contents': list(tt._removed_contents),
0.12.11 by Aaron Bentley
Some tweakage
21
        '_non_present_ids': tt._non_present_ids,
0.12.1 by Aaron Bentley
Initial bencode-based encoding
22
        }
0.12.3 by Aaron Bentley
Add pack serialization
23
    yield serializer.bytes_record(bencode.bencode(attribs), (('attribs',),))
0.12.4 by Aaron Bentley
Start deserializing files
24
    for trans_id, kind in tt._new_contents.items():
25
        if kind == 'file':
0.12.5 by Aaron Bentley
Test file content
26
            cur_file = open(tt._limbo_name(trans_id), 'rb')
27
            try:
28
                content = cur_file.read()
29
            finally:
30
                cur_file.close()
0.12.6 by Aaron Bentley
Support serializing/deserializing directories
31
        if kind == 'directory':
32
            content = ''
0.12.10 by Aaron Bentley
Implement symlink serialization
33
        if kind == 'symlink':
34
            content = os.readlink(tt._limbo_name(trans_id))
0.12.4 by Aaron Bentley
Start deserializing files
35
        yield serializer.bytes_record(content, ((trans_id, kind),))
0.13.1 by Aaron Bentley
Serialization does not dictate contents of beginning of file.
36
37
38
def deserialize(tt, records):
39
    names, content = records.next()
0.12.3 by Aaron Bentley
Add pack serialization
40
    attribs = bencode.bdecode(content)
0.12.1 by Aaron Bentley
Initial bencode-based encoding
41
    tt._id_number = attribs['_id_number']
42
    tt._new_name = dict((k, v.decode('utf-8'))
43
                        for k, v in attribs['_new_name'].items())
0.12.2 by Aaron Bentley
Handle parents
44
    tt._new_parent = attribs['_new_parent']
0.12.7 by Aaron Bentley
Get executability under test.
45
    tt._new_executability = dict((k, bool(v)) for k, v in
46
        attribs['_new_executability'].items())
0.12.1 by Aaron Bentley
Initial bencode-based encoding
47
    tt._new_id = attribs['_new_id']
48
    tt._r_new_id = dict((v, k) for k, v in tt._new_id.items())
0.12.8 by Aaron Bentley
Test deleting and unversioning
49
    tt._tree_path_ids = {}
50
    tt._tree_id_paths = {}
51
    for bytepath, trans_id in attribs['_tree_path_ids'].items():
52
        path = bytepath.decode('utf-8')
53
        tt._tree_path_ids[path] = trans_id
54
        tt._tree_id_paths[trans_id] = path
55
    tt._removed_id = set(attribs['_removed_id'])
56
    tt._removed_contents = set(attribs['_removed_contents'])
0.12.11 by Aaron Bentley
Some tweakage
57
    tt._non_present_ids = attribs['_non_present_ids']
0.13.1 by Aaron Bentley
Serialization does not dictate contents of beginning of file.
58
    for ((trans_id, kind),), content in records:
0.12.11 by Aaron Bentley
Some tweakage
59
        if kind == 'file':
60
            tt.create_file(content, trans_id)
61
        if kind == 'directory':
62
            tt.create_directory(trans_id)
63
        if kind == 'symlink':
64
            tt.create_symlink(content, trans_id)