~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-29 07:13:49 UTC
  • Revision ID: mbp@sourcefrog.net-20050329071349-fc116a83171fbb9a
simplified/faster Inventory.add

Show diffs side-by-side

added added

removed removed

Lines of Context:
335
335
 
336
336
        To add  a file to a branch ready to be committed, use Branch.add,
337
337
        which calls this."""
338
 
        if entry.file_id in self:
 
338
        if entry.file_id in self._byid:
339
339
            bailout("inventory already contains entry with id {%s}" % entry.file_id)
340
340
 
341
 
        if entry.parent_id != None:
342
 
            if entry.parent_id not in self:
343
 
                bailout("parent_id %s of new entry not found in inventory"
344
 
                        % entry.parent_id)
345
 
            # TODO: parent must be a directory
346
 
            
347
 
        if self[entry.parent_id].children.has_key(entry.name):
348
 
            bailout("%s is already versioned"
349
 
                    % appendpath(self.id2path(entry.parent_id), entry.name))
 
341
        parent = self._byid[entry.parent_id]
 
342
        if parent.kind != 'directory':
 
343
            bailout("attempt to add under non-directory {%s}" % parent.file_id)
 
344
 
 
345
        if parent.children.has_key(entry.name):
 
346
            bailout("{%s} already has child %r" % (parent.file_id, entry.name))
350
347
 
351
348
        self._byid[entry.file_id] = entry
352
 
        self[entry.parent_id].children[entry.name] = entry
 
349
        parent.children[entry.name] = entry
353
350
 
354
351
 
355
352
    def add_path(self, relpath, kind, file_id=None):