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