~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to serialize_transform.py

  • Committer: Aaron Bentley
  • Date: 2008-10-11 00:38:26 UTC
  • mfrom: (0.12.46 shelf-manager)
  • mto: This revision was merged to the branch mainline in revision 3823.
  • Revision ID: aaron@aaronbentley.com-20081011003826-az36x28h1izfb038
Merge shelf-manager into shelf-ui

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
 
 
3
from bzrlib import multiparent
3
4
from bzrlib.util import bencode
4
5
 
5
6
 
 
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
 
6
19
def serialize(tt, serializer):
7
20
    new_name = dict((k, v.encode('utf-8')) for k, v in tt._new_name.items())
8
21
    new_executability = dict((k, int(v)) for k, v in
25
38
        if kind == 'file':
26
39
            cur_file = open(tt._limbo_name(trans_id), 'rb')
27
40
            try:
28
 
                content = cur_file.read()
 
41
                lines = cur_file.readlines()
29
42
            finally:
30
43
                cur_file.close()
 
44
            parents = get_parents_lines(tt, trans_id)
 
45
            mpdiff = multiparent.MultiParent.from_lines(lines, parents)
 
46
            content = ''.join(mpdiff.to_patch())
31
47
        if kind == 'directory':
32
48
            content = ''
33
49
        if kind == 'symlink':
57
73
    tt._non_present_ids = attribs['_non_present_ids']
58
74
    for ((trans_id, kind),), content in records:
59
75
        if kind == 'file':
60
 
            tt.create_file(content, trans_id)
 
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)
61
79
        if kind == 'directory':
62
80
            tt.create_directory(trans_id)
63
81
        if kind == 'symlink':