~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Vincent Ladeuil
  • Date: 2010-08-20 09:52:25 UTC
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: v.ladeuil+lp@free.fr-20100820095225-wijo4emfgvtmu2ku
BzrRemoveChangedFilesError is deprecated in 2.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
375
375
            recurse = True
376
376
            try:
377
377
                bzrdir = BzrDir.open_from_transport(current_transport)
378
 
            except errors.NotBranchError:
 
378
            except (errors.NotBranchError, errors.PermissionDenied):
379
379
                pass
380
380
            else:
381
381
                recurse, value = evaluate(bzrdir)
382
382
                yield value
383
383
            try:
384
384
                subdirs = list_current(current_transport)
385
 
            except errors.NoSuchFile:
 
385
            except (errors.NoSuchFile, errors.PermissionDenied):
386
386
                continue
387
387
            if recurse:
388
388
                for subdir in sorted(subdirs, reverse=True):
394
394
        """
395
395
        try:
396
396
            return [self.open_branch()]
397
 
        except errors.NotBranchError:
 
397
        except (errors.NotBranchError, errors.NoRepositoryPresent):
398
398
            return []
399
399
 
400
400
    @staticmethod
615
615
        """
616
616
        raise NotImplementedError(self.create_workingtree)
617
617
 
 
618
    def generate_backup_name(self, base):
 
619
        """Generate a non-existing backup file name based on base."""
 
620
        counter = 1
 
621
        name = "%s.~%d~" % (base, counter)
 
622
        while self.root_transport.has(name):
 
623
            counter += 1
 
624
            name = "%s.~%d~" % (base, counter)
 
625
        return name
 
626
 
618
627
    def backup_bzrdir(self):
619
628
        """Backup this bzr control directory.
620
629
 
621
630
        :return: Tuple with old path name and new path name
622
631
        """
623
 
        def name_gen(base='backup.bzr'):
624
 
            counter = 1
625
 
            name = "%s.~%d~" % (base, counter)
626
 
            while self.root_transport.has(name):
627
 
                counter += 1
628
 
                name = "%s.~%d~" % (base, counter)
629
 
            return name
630
632
 
631
 
        backup_dir=name_gen()
 
633
        backup_dir=self.generate_backup_name('backup.bzr')
632
634
        pb = ui.ui_factory.nested_progress_bar()
633
635
        try:
634
636
            # FIXME: bug 300001 -- the backup fails if the backup directory
737
739
            raise errors.NoRepositoryPresent(self)
738
740
        return found_repo
739
741
 
740
 
    def get_branch_reference(self):
 
742
    def get_branch_reference(self, name=None):
741
743
        """Return the referenced URL for the branch in this bzrdir.
742
744
 
 
745
        :param name: Optional colocated branch name
743
746
        :raises NotBranchError: If there is no Branch.
 
747
        :raises NoColocatedBranchSupport: If a branch name was specified
 
748
            but colocated branches are not supported.
744
749
        :return: The URL the branch in this bzrdir references if it is a
745
750
            reference branch, or None for regular branches.
746
751
        """
 
752
        if name is not None:
 
753
            raise errors.NoColocatedBranchSupport(self)
747
754
        return None
748
755
 
749
756
    def get_branch_transport(self, branch_format, name=None):
994
1001
                raise errors.NotBranchError(path=url)
995
1002
            a_transport = new_t
996
1003
 
997
 
    def _get_tree_branch(self):
 
1004
    def _get_tree_branch(self, name=None):
998
1005
        """Return the branch and tree, if any, for this bzrdir.
999
1006
 
 
1007
        :param name: Name of colocated branch to open.
 
1008
 
1000
1009
        Return None for tree if not present or inaccessible.
1001
1010
        Raise NotBranchError if no branch is present.
1002
1011
        :return: (tree, branch)
1005
1014
            tree = self.open_workingtree()
1006
1015
        except (errors.NoWorkingTree, errors.NotLocalUrl):
1007
1016
            tree = None
1008
 
            branch = self.open_branch()
 
1017
            branch = self.open_branch(name=name)
1009
1018
        else:
1010
 
            branch = tree.branch
 
1019
            if name is not None:
 
1020
                branch = self.open_branch(name=name)
 
1021
            else:
 
1022
                branch = tree.branch
1011
1023
        return tree, branch
1012
1024
 
1013
1025
    @classmethod
1234
1246
        repository_policy = result.determine_repository_policy(
1235
1247
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1236
1248
        result_repo, is_new_repo = repository_policy.acquire_repository()
1237
 
        if is_new_repo and revision_id is not None and not stacked:
 
1249
        is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
 
1250
        if is_new_repo and revision_id is not None and not is_stacked:
1238
1251
            fetch_spec = graph.PendingAncestryResult(
1239
1252
                [revision_id], source_repository)
1240
1253
        else:
1736
1749
    def destroy_workingtree_metadata(self):
1737
1750
        self.transport.delete_tree('checkout')
1738
1751
 
1739
 
    def find_branch_format(self):
 
1752
    def find_branch_format(self, name=None):
1740
1753
        """Find the branch 'format' for this bzrdir.
1741
1754
 
1742
1755
        This might be a synthetic object for e.g. RemoteBranch and SVN.
1743
1756
        """
1744
1757
        from bzrlib.branch import BranchFormat
1745
 
        return BranchFormat.find_format(self)
 
1758
        return BranchFormat.find_format(self, name=name)
1746
1759
 
1747
1760
    def _get_mkdir_mode(self):
1748
1761
        """Figure out the mode to use when creating a bzrdir subdir."""
1750
1763
                                     lockable_files.TransportLock)
1751
1764
        return temp_control._dir_mode
1752
1765
 
1753
 
    def get_branch_reference(self):
 
1766
    def get_branch_reference(self, name=None):
1754
1767
        """See BzrDir.get_branch_reference()."""
1755
1768
        from bzrlib.branch import BranchFormat
1756
 
        format = BranchFormat.find_format(self)
1757
 
        return format.get_reference(self)
 
1769
        format = BranchFormat.find_format(self, name=name)
 
1770
        return format.get_reference(self, name=name)
1758
1771
 
1759
1772
    def get_branch_transport(self, branch_format, name=None):
1760
1773
        """See BzrDir.get_branch_transport()."""
1854
1867
    def open_branch(self, name=None, unsupported=False,
1855
1868
                    ignore_fallbacks=False):
1856
1869
        """See BzrDir.open_branch."""
1857
 
        format = self.find_branch_format()
 
1870
        format = self.find_branch_format(name=name)
1858
1871
        self._check_supported(format, unsupported)
1859
1872
        return format.open(self, name=name,
1860
1873
            _found=True, ignore_fallbacks=ignore_fallbacks)
1948
1961
            format_string = transport.get_bytes(".bzr/branch-format")
1949
1962
        except errors.NoSuchFile:
1950
1963
            raise errors.NotBranchError(path=transport.base)
1951
 
 
1952
1964
        try:
1953
1965
            return klass._formats[format_string]
1954
1966
        except KeyError:
2863
2875
            self.revisions[rev_id] = rev
2864
2876
 
2865
2877
    def _load_old_inventory(self, rev_id):
2866
 
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
 
2878
        f = self.branch.repository.inventory_store.get(rev_id)
 
2879
        try:
 
2880
            old_inv_xml = f.read()
 
2881
        finally:
 
2882
            f.close()
2867
2883
        inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
2868
2884
        inv.revision_id = rev_id
2869
2885
        rev = self.revisions[rev_id]
2925
2941
        previous_entries = dict((head, parent_candiate_entries[head]) for head
2926
2942
            in heads)
2927
2943
        self.snapshot_ie(previous_entries, ie, w, rev_id)
2928
 
        del ie.text_id
2929
2944
 
2930
2945
    def get_parent_map(self, revision_ids):
2931
2946
        """See graph.StackedParentsProvider.get_parent_map"""
2947
2962
                ie.revision = previous_ie.revision
2948
2963
                return
2949
2964
        if ie.has_text():
2950
 
            text = self.branch.repository._text_store.get(ie.text_id)
2951
 
            file_lines = text.readlines()
 
2965
            f = self.branch.repository._text_store.get(ie.text_id)
 
2966
            try:
 
2967
                file_lines = f.readlines()
 
2968
            finally:
 
2969
                f.close()
2952
2970
            w.add_lines(rev_id, previous_revisions, file_lines)
2953
2971
            self.text_count += 1
2954
2972
        else:
3235
3253
        # XXX: It's a bit ugly that the network name is here, because we'd
3236
3254
        # like to believe that format objects are stateless or at least
3237
3255
        # immutable,  However, we do at least avoid mutating the name after
3238
 
        # it's returned.  See <https://bugs.edge.launchpad.net/bzr/+bug/504102>
 
3256
        # it's returned.  See <https://bugs.launchpad.net/bzr/+bug/504102>
3239
3257
        self._network_name = None
3240
3258
 
3241
3259
    def __repr__(self):