/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.13.3 by Aaron Bentley
Implement MPDiff compression of shelves
3
from bzrlib import multiparent
0.12.1 by Aaron Bentley
Initial bencode-based encoding
4
from bzrlib.util import bencode
5
6
0.13.3 by Aaron Bentley
Implement MPDiff compression of shelves
7
def get_parents_texts(tt, trans_id):
8
    return tuple(''.join(p) for p in get_parents_lines(tt, trans_id))
9
10
11
def get_parents_lines(tt, trans_id):
12
    file_id = tt.tree_file_id(trans_id)
13
    if file_id is None:
14
        return ()
15
    else:
16
        return (tt._tree.get_file(file_id).readlines(),)
17
18
0.13.1 by Aaron Bentley
Serialization does not dictate contents of beginning of file.
19
def serialize(tt, serializer):
0.12.1 by Aaron Bentley
Initial bencode-based encoding
20
    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.
21
    new_executability = dict((k, int(v)) for k, v in
22
                             tt._new_executability.items())
0.12.8 by Aaron Bentley
Test deleting and unversioning
23
    tree_path_ids = dict((k.encode('utf-8'), v)
24
                         for k, v in tt._tree_path_ids.items())
0.12.1 by Aaron Bentley
Initial bencode-based encoding
25
    attribs = {
26
        '_id_number': tt._id_number,
27
        '_new_name': new_name,
0.12.2 by Aaron Bentley
Handle parents
28
        '_new_parent': tt._new_parent,
0.12.7 by Aaron Bentley
Get executability under test.
29
        '_new_executability': new_executability,
0.12.1 by Aaron Bentley
Initial bencode-based encoding
30
        '_new_id': tt._new_id,
0.12.8 by Aaron Bentley
Test deleting and unversioning
31
        '_tree_path_ids': tree_path_ids,
32
        '_removed_id': list(tt._removed_id),
33
        '_removed_contents': list(tt._removed_contents),
0.12.11 by Aaron Bentley
Some tweakage
34
        '_non_present_ids': tt._non_present_ids,
0.12.1 by Aaron Bentley
Initial bencode-based encoding
35
        }
0.12.3 by Aaron Bentley
Add pack serialization
36
    yield serializer.bytes_record(bencode.bencode(attribs), (('attribs',),))
0.12.4 by Aaron Bentley
Start deserializing files
37
    for trans_id, kind in tt._new_contents.items():
38
        if kind == 'file':
0.12.5 by Aaron Bentley
Test file content
39
            cur_file = open(tt._limbo_name(trans_id), 'rb')
40
            try:
0.13.3 by Aaron Bentley
Implement MPDiff compression of shelves
41
                lines = cur_file.readlines()
0.12.5 by Aaron Bentley
Test file content
42
            finally:
43
                cur_file.close()
0.13.3 by Aaron Bentley
Implement MPDiff compression of shelves
44
            parents = get_parents_lines(tt, trans_id)
45
            mpdiff = multiparent.MultiParent.from_lines(lines, parents)
46
            content = ''.join(mpdiff.to_patch())
0.12.6 by Aaron Bentley
Support serializing/deserializing directories
47
        if kind == 'directory':
48
            content = ''
0.12.10 by Aaron Bentley
Implement symlink serialization
49
        if kind == 'symlink':
50
            content = os.readlink(tt._limbo_name(trans_id))
0.12.4 by Aaron Bentley
Start deserializing files
51
        yield serializer.bytes_record(content, ((trans_id, kind),))
0.13.1 by Aaron Bentley
Serialization does not dictate contents of beginning of file.
52
53
54
def deserialize(tt, records):
55
    names, content = records.next()
0.12.3 by Aaron Bentley
Add pack serialization
56
    attribs = bencode.bdecode(content)
0.12.1 by Aaron Bentley
Initial bencode-based encoding
57
    tt._id_number = attribs['_id_number']
58
    tt._new_name = dict((k, v.decode('utf-8'))
59
                        for k, v in attribs['_new_name'].items())
0.12.2 by Aaron Bentley
Handle parents
60
    tt._new_parent = attribs['_new_parent']
0.12.7 by Aaron Bentley
Get executability under test.
61
    tt._new_executability = dict((k, bool(v)) for k, v in
62
        attribs['_new_executability'].items())
0.12.1 by Aaron Bentley
Initial bencode-based encoding
63
    tt._new_id = attribs['_new_id']
64
    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
65
    tt._tree_path_ids = {}
66
    tt._tree_id_paths = {}
67
    for bytepath, trans_id in attribs['_tree_path_ids'].items():
68
        path = bytepath.decode('utf-8')
69
        tt._tree_path_ids[path] = trans_id
70
        tt._tree_id_paths[trans_id] = path
71
    tt._removed_id = set(attribs['_removed_id'])
72
    tt._removed_contents = set(attribs['_removed_contents'])
0.12.11 by Aaron Bentley
Some tweakage
73
    tt._non_present_ids = attribs['_non_present_ids']
0.13.1 by Aaron Bentley
Serialization does not dictate contents of beginning of file.
74
    for ((trans_id, kind),), content in records:
0.12.11 by Aaron Bentley
Some tweakage
75
        if kind == 'file':
0.13.3 by Aaron Bentley
Implement MPDiff compression of shelves
76
            mpdiff = multiparent.MultiParent.from_patch(content)
77
            lines = mpdiff.to_lines(get_parents_texts(tt, trans_id))
78
            tt.create_file(lines, trans_id)
0.12.11 by Aaron Bentley
Some tweakage
79
        if kind == 'directory':
80
            tt.create_directory(trans_id)
81
        if kind == 'symlink':
82
            tt.create_symlink(content, trans_id)