~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-10-15 16:41:48 UTC
  • mfrom: (5502.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20101015164148-k10lo687r72nzbtl
(vila) Provides a ``bzr.transform.orphan_policy`` option to control
        orphan handling when merging directory deletion (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
    registry,
88
88
    symbol_versioning,
89
89
    )
 
90
from bzrlib.symbol_versioning import (
 
91
    deprecated_in,
 
92
    deprecated_method,
 
93
    )
90
94
 
91
95
 
92
96
class BzrDir(controldir.ControlDir):
497
501
                                               format=format).bzrdir
498
502
        return bzrdir.create_workingtree()
499
503
 
 
504
    @deprecated_method(deprecated_in((2, 3, 0)))
500
505
    def generate_backup_name(self, base):
501
 
        """Generate a non-existing backup file name based on base."""
502
 
        counter = 1
503
 
        name = "%s.~%d~" % (base, counter)
504
 
        while self.root_transport.has(name):
505
 
            counter += 1
506
 
            name = "%s.~%d~" % (base, counter)
507
 
        return name
 
506
        return self._available_backup_name(base)
 
507
 
 
508
    def _available_backup_name(self, base):
 
509
        """Find a non-existing backup file name based on base.
 
510
 
 
511
        See bzrlib.osutils.available_backup_name about race conditions.
 
512
        """
 
513
        return osutils.available_backup_name(base, self.root_transport.has)
508
514
 
509
515
    def backup_bzrdir(self):
510
516
        """Backup this bzr control directory.
512
518
        :return: Tuple with old path name and new path name
513
519
        """
514
520
 
515
 
        backup_dir=self.generate_backup_name('backup.bzr')
516
521
        pb = ui.ui_factory.nested_progress_bar()
517
522
        try:
518
 
            # FIXME: bug 300001 -- the backup fails if the backup directory
519
 
            # already exists, but it should instead either remove it or make
520
 
            # a new backup directory.
521
 
            #
522
523
            old_path = self.root_transport.abspath('.bzr')
 
524
            backup_dir = self._available_backup_name('backup.bzr')
523
525
            new_path = self.root_transport.abspath(backup_dir)
524
 
            ui.ui_factory.note('making backup of %s\n  to %s' % (old_path, new_path,))
 
526
            ui.ui_factory.note('making backup of %s\n  to %s'
 
527
                               % (old_path, new_path,))
525
528
            self.root_transport.copy_tree('.bzr', backup_dir)
526
529
            return (old_path, new_path)
527
530
        finally:
1291
1294
        wt = self.open_workingtree(recommend_upgrade=False)
1292
1295
        repository = wt.branch.repository
1293
1296
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
1294
 
        wt.revert(old_tree=empty)
 
1297
        # We ignore the conflicts returned by wt.revert since we're about to
 
1298
        # delete the wt metadata anyway, all that should be left here are
 
1299
        # detritus. But see bug #634470 about subtree .bzr dirs.
 
1300
        conflicts = wt.revert(old_tree=empty)
1295
1301
        self.destroy_workingtree_metadata()
1296
1302
 
1297
1303
    def destroy_workingtree_metadata(self):