~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

Unified all file types as 'contents'

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
        self._id_number = 0
18
18
        self._new_name = {}
19
19
        self._new_parent = {}
20
 
        self._new_file = {}
 
20
        self._new_contents = {}
21
21
        self._new_id = {}
22
22
        self._new_root = self.get_id_tree(tree.get_root_id())
23
23
 
56
56
        Contents is an iterator of strings, all of which will be written
57
57
        to the target destination
58
58
        """
59
 
        unique_add(self._new_file, trans_id, contents)
 
59
        unique_add(self._new_contents, trans_id, ('file', contents))
60
60
 
61
61
    def version_file(self, file_id, trans_id):
62
62
        unique_add(self._new_id, trans_id, file_id)
64
64
    def new_paths(self):
65
65
        new_ids = set()
66
66
        fp = FinalPaths(self._new_root, self._new_name, self._new_parent)
67
 
        for id_set in (self._new_name, self._new_parent, self._new_file,
 
67
        for id_set in (self._new_name, self._new_parent, self._new_contents,
68
68
                       self._new_id):
69
69
            new_ids.update(id_set)
70
70
        new_paths = [(fp.get_path(t), t) for t in new_ids]
74
74
    def apply(self):
75
75
        inv = self._tree.inventory
76
76
        for path, trans_id in self.new_paths():
77
 
            kind = None
78
 
            if trans_id in self._new_file:
 
77
            try:
 
78
                kind, contents = self._new_contents[trans_id]
 
79
            except KeyError:
 
80
                kind = contents = None
 
81
            if kind == 'file':
79
82
                f = file(self._tree.abspath(path), 'wb')
80
 
                for segment in self._new_file[trans_id]:
 
83
                for segment in contents:
81
84
                    f.write(segment)
82
85
                f.close()
83
 
                kind = "file"
84
86
 
85
87
            if trans_id in self._new_id:
86
88
                if kind is None: