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