~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

Added directory handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
        """
89
89
        unique_add(self._new_contents, trans_id, ('file', contents))
90
90
 
 
91
    def create_directory(self, trans_id):
 
92
        unique_add(self._new_contents, trans_id, ('directory',))
 
93
 
91
94
    def version_file(self, file_id, trans_id):
92
95
        unique_add(self._new_id, trans_id, file_id)
93
96
 
198
201
                conflicts.append(('versioning no contents', trans_id))
199
202
                continue
200
203
            if not InventoryEntry.versionable_kind(kind):
201
 
                conflicts.append(('versioning bad kind', trans_id))
 
204
                conflicts.append(('versioning bad kind', trans_id, kind))
202
205
        return conflicts
203
206
 
204
207
    def _duplicate_entries(self, by_parent):
236
239
        inv = self._tree.inventory
237
240
        for path, trans_id in self.new_paths():
238
241
            try:
239
 
                kind, contents = self._new_contents[trans_id]
 
242
                kind = self._new_contents[trans_id][0]
240
243
            except KeyError:
241
244
                kind = contents = None
242
245
            if kind == 'file':
 
246
                contents = self._new_contents[trans_id][1]
243
247
                f = file(self._tree.abspath(path), 'wb')
244
248
                for segment in contents:
245
249
                    f.write(segment)
246
250
                f.close()
 
251
            elif kind == 'directory':
 
252
                os.mkdir(self._tree.abspath(path))
247
253
 
248
254
            if trans_id in self._new_id:
249
255
                if kind is None:
251
257
                inv.add_path(path, kind, self._new_id[trans_id])
252
258
        self._tree._write_inventory(inv)
253
259
 
254
 
    def new_file(self, name, parent_id, contents, file_id=None):
255
 
        """Convenience method to create files""" 
 
260
    def new_entry(self, name, parent_id, file_id):
256
261
        trans_id = self.create_path(name, parent_id)
257
 
        self.create_file(contents, trans_id)
258
262
        if file_id is not None:
259
263
            self.version_file(file_id, trans_id)
260
264
        return trans_id
261
265
 
 
266
    def new_file(self, name, parent_id, contents, file_id=None):
 
267
        """Convenience method to create files"""
 
268
        trans_id = self.new_entry(name, parent_id, file_id)
 
269
        self.create_file(contents, trans_id)
 
270
        return trans_id
 
271
 
 
272
    def new_directory(self, name, parent_id, file_id=None):
 
273
        trans_id = self.new_entry(name, parent_id, file_id)
 
274
        self.create_directory(trans_id)
 
275
        return trans_id 
 
276
 
262
277
 
263
278
class FinalPaths(object):
264
279
    def __init__(self, root, names, tree):