~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-20 11:09:03 UTC
  • mto: This revision was merged to the branch mainline in revision 5952.
  • Revision ID: jelmer@samba.org-20110520110903-w9psynaamsl2kgfy
Add helper for converting to directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
591
591
            return self.tree.inventory[file_id]
592
592
        return None
593
593
 
 
594
    def _ensure_directory(self, this_ie, inv_path):
 
595
        """Convert an entry to a directory if it is not one already.
 
596
 
 
597
        :param this_ie: Inventory entry
 
598
        :param inv_path: Normalized path for the inventory entry
 
599
        :return: The new inventory entry
 
600
        """
 
601
        if this_ie.kind == 'directory':
 
602
            return this_ie
 
603
        # Same as in _add_one below, if the inventory doesn't
 
604
        # think this is a directory, update the inventory
 
605
        this_ie = _mod_inventory.make_entry('directory',
 
606
            this_ie.name, this_ie.parent_id, this_ie.file_id)
 
607
        self._invdelta[inv_path] = (inv_path, inv_path, this_ie.file_id,
 
608
            this_ie)
 
609
        return this_ie
 
610
 
594
611
    def _add_one_and_parent(self, parent_ie, path, kind, inv_path):
595
612
        """Add a new entry to the inventory and automatically add unversioned parents.
596
613
 
625
642
        if parent_ie.kind != 'directory':
626
643
            # nb: this relies on someone else checking that the path we're using
627
644
            # doesn't contain symlinks.
628
 
            new_parent_ie = _mod_inventory.make_entry('directory', parent_ie.name,
629
 
                parent_ie.parent_id, parent_ie.file_id)
630
 
            inv_delta_entry = (self.tree.id2path(parent_ie.file_id), osutils.dirname(inv_path),
631
 
                parent_ie.file_id, new_parent_ie)
632
 
            self._invdelta[inv_delta_entry[1]] = inv_delta_entry
633
 
            parent_ie = new_parent_ie
 
645
            parent_ie = self._ensure_directory(parent_ie, osutils.dirname(inv_path))
634
646
        file_id = self.action(self.tree.inventory, parent_ie, path, kind)
635
647
        entry = _mod_inventory.make_entry(kind, path.base_path, parent_ie.file_id,
636
648
            file_id=file_id)
785
797
                self.added.extend(extra)
786
798
 
787
799
            if kind == 'directory' and not sub_tree:
788
 
                if this_ie.kind != 'directory':
789
 
                    # Same as in _add_one below, if the inventory doesn't
790
 
                    # think this is a directory, update the inventory
791
 
                    this_ie = _mod_inventory.make_entry('directory',
792
 
                        this_ie.name, this_ie.parent_id, this_ie.file_id)
793
 
                    self._invdelta[inv_path] = (inv_path, inv_path, this_ie.file_id,
794
 
                        this_ie)
 
800
                this_ie = self._ensure_directory(this_ie, inv_path)
795
801
 
796
802
                for subf in sorted(os.listdir(abspath)):
797
803
                    inv_f, _ = osutils.normalized_filename(subf)