/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Aaron Bentley
  • Date: 2007-06-02 15:48:54 UTC
  • mto: (2502.1.10 fast-checkout)
  • mto: This revision was merged to the branch mainline in revision 2507.
  • Revision ID: aaron.bentley@utoronto.ca-20070602154854-dxx6c0hbjm2h1jel
Make the limited-renames functionality safer in the general case

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
        self._new_parent = {}
108
108
        self._new_contents = {}
109
109
        self._limbo_files = {}
 
110
        self._limbo_children = {}
110
111
        self._needs_rename = set()
111
112
        self._removed_contents = set()
112
113
        self._new_executability = {}
168
169
        """Change the path that is assigned to a transaction id."""
169
170
        if trans_id == self._new_root:
170
171
            raise CantMoveRoot
 
172
        previous_parent = self._new_parent.get(trans_id)
171
173
        self._new_name[trans_id] = name
172
174
        self._new_parent[trans_id] = parent
 
175
        if (trans_id in self._limbo_files and
 
176
            trans_id not in self._needs_rename):
 
177
            self._rename_in_limbo([trans_id])
 
178
            self._limbo_children[previous_parent].remove(trans_id)
 
179
 
 
180
    def _rename_in_limbo(self, trans_ids):
 
181
        """Fix a limbo name so that the right final path is produced.
 
182
 
 
183
        This means we outsmarted ourselves-- we tried to avoid renaming
 
184
        these file later by creating them with their final names in their
 
185
        final parent.  But now the previous name or parent is no longer
 
186
        suitable, so we have to rename them.
 
187
        """
 
188
        for trans_id in trans_ids:
 
189
            old_path = self._limbo_files[trans_id]
 
190
            new_path = self._limbo_name(trans_id, from_scratch=True)
 
191
            os.rename(old_path, new_path)
173
192
 
174
193
    def adjust_root_path(self, name, parent):
175
194
        """Emulate moving the root by moving all children, instead.
333
352
    def cancel_creation(self, trans_id):
334
353
        """Cancel the creation of new file contents."""
335
354
        del self._new_contents[trans_id]
 
355
        children = self._limbo_children.get(trans_id)
 
356
        # if this is a limbo directory with children, move them before removing
 
357
        # the directory
 
358
        if children is not None:
 
359
            self._rename_in_limbo(children)
 
360
            del self._limbo_children[trans_id]
336
361
        delete_any(self._limbo_name(trans_id))
337
362
 
338
363
    def delete_contents(self, trans_id):
756
781
        self.finalize()
757
782
        return _TransformResults(modified_paths)
758
783
 
759
 
    def _limbo_name(self, trans_id):
 
784
    def _limbo_name(self, trans_id, from_scratch=False):
760
785
        """Generate the limbo name of a file"""
761
 
        if trans_id in self._limbo_files:
 
786
        if trans_id in self._limbo_files and not from_scratch:
762
787
            return self._limbo_files[trans_id]
763
788
        parent = self.final_parent(trans_id)
764
 
        if parent in self._limbo_files:
 
789
        # if the parent directory is already in limbo (e.g. when building a
 
790
        # tree), choose a limbo name inside the parent, to reduce further
 
791
        # renames.
 
792
        if self._new_contents.get(parent) == 'directory':
765
793
            limbo_name = pathjoin(self._limbo_files[parent],
766
794
                                  self.final_name(trans_id))
 
795
            if parent not in self._limbo_children:
 
796
                self._limbo_children[parent] = set()
 
797
            self._limbo_children[parent].add(trans_id)
767
798
        else:
768
799
            limbo_name = pathjoin(self._limbodir, trans_id)
769
800
            self._needs_rename.add(trans_id)