~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

Merge cleanup into texinfo

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
737
737
            raise errors.NoRepositoryPresent(self)
738
738
        return found_repo
739
739
 
740
 
    def get_branch_reference(self):
 
740
    def get_branch_reference(self, name=None):
741
741
        """Return the referenced URL for the branch in this bzrdir.
742
742
 
 
743
        :param name: Optional colocated branch name
743
744
        :raises NotBranchError: If there is no Branch.
 
745
        :raises NoColocatedBranchSupport: If a branch name was specified
 
746
            but colocated branches are not supported.
744
747
        :return: The URL the branch in this bzrdir references if it is a
745
748
            reference branch, or None for regular branches.
746
749
        """
 
750
        if name is not None:
 
751
            raise errors.NoColocatedBranchSupport(self)
747
752
        return None
748
753
 
749
754
    def get_branch_transport(self, branch_format, name=None):
994
999
                raise errors.NotBranchError(path=url)
995
1000
            a_transport = new_t
996
1001
 
997
 
    def _get_tree_branch(self):
 
1002
    def _get_tree_branch(self, name=None):
998
1003
        """Return the branch and tree, if any, for this bzrdir.
999
1004
 
 
1005
        :param name: Name of colocated branch to open.
 
1006
 
1000
1007
        Return None for tree if not present or inaccessible.
1001
1008
        Raise NotBranchError if no branch is present.
1002
1009
        :return: (tree, branch)
1005
1012
            tree = self.open_workingtree()
1006
1013
        except (errors.NoWorkingTree, errors.NotLocalUrl):
1007
1014
            tree = None
1008
 
            branch = self.open_branch()
 
1015
            branch = self.open_branch(name=name)
1009
1016
        else:
1010
 
            branch = tree.branch
 
1017
            if name is not None:
 
1018
                branch = self.open_branch(name=name)
 
1019
            else:
 
1020
                branch = tree.branch
1011
1021
        return tree, branch
1012
1022
 
1013
1023
    @classmethod
1234
1244
        repository_policy = result.determine_repository_policy(
1235
1245
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1236
1246
        result_repo, is_new_repo = repository_policy.acquire_repository()
1237
 
        if is_new_repo and revision_id is not None and not stacked:
 
1247
        is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
 
1248
        if is_new_repo and revision_id is not None and not is_stacked:
1238
1249
            fetch_spec = graph.PendingAncestryResult(
1239
1250
                [revision_id], source_repository)
1240
1251
        else:
1736
1747
    def destroy_workingtree_metadata(self):
1737
1748
        self.transport.delete_tree('checkout')
1738
1749
 
1739
 
    def find_branch_format(self):
 
1750
    def find_branch_format(self, name=None):
1740
1751
        """Find the branch 'format' for this bzrdir.
1741
1752
 
1742
1753
        This might be a synthetic object for e.g. RemoteBranch and SVN.
1743
1754
        """
1744
1755
        from bzrlib.branch import BranchFormat
1745
 
        return BranchFormat.find_format(self)
 
1756
        return BranchFormat.find_format(self, name=name)
1746
1757
 
1747
1758
    def _get_mkdir_mode(self):
1748
1759
        """Figure out the mode to use when creating a bzrdir subdir."""
1750
1761
                                     lockable_files.TransportLock)
1751
1762
        return temp_control._dir_mode
1752
1763
 
1753
 
    def get_branch_reference(self):
 
1764
    def get_branch_reference(self, name=None):
1754
1765
        """See BzrDir.get_branch_reference()."""
1755
1766
        from bzrlib.branch import BranchFormat
1756
 
        format = BranchFormat.find_format(self)
1757
 
        return format.get_reference(self)
 
1767
        format = BranchFormat.find_format(self, name=name)
 
1768
        return format.get_reference(self, name=name)
1758
1769
 
1759
1770
    def get_branch_transport(self, branch_format, name=None):
1760
1771
        """See BzrDir.get_branch_transport()."""
1854
1865
    def open_branch(self, name=None, unsupported=False,
1855
1866
                    ignore_fallbacks=False):
1856
1867
        """See BzrDir.open_branch."""
1857
 
        format = self.find_branch_format()
 
1868
        format = self.find_branch_format(name=name)
1858
1869
        self._check_supported(format, unsupported)
1859
1870
        return format.open(self, name=name,
1860
1871
            _found=True, ignore_fallbacks=ignore_fallbacks)
1948
1959
            format_string = transport.get_bytes(".bzr/branch-format")
1949
1960
        except errors.NoSuchFile:
1950
1961
            raise errors.NotBranchError(path=transport.base)
1951
 
 
1952
1962
        try:
1953
1963
            return klass._formats[format_string]
1954
1964
        except KeyError:
2863
2873
            self.revisions[rev_id] = rev
2864
2874
 
2865
2875
    def _load_old_inventory(self, rev_id):
2866
 
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
 
2876
        f = self.branch.repository.inventory_store.get(rev_id)
 
2877
        try:
 
2878
            old_inv_xml = f.read()
 
2879
        finally:
 
2880
            f.close()
2867
2881
        inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
2868
2882
        inv.revision_id = rev_id
2869
2883
        rev = self.revisions[rev_id]
2947
2961
                ie.revision = previous_ie.revision
2948
2962
                return
2949
2963
        if ie.has_text():
2950
 
            text = self.branch.repository._text_store.get(ie.text_id)
2951
 
            file_lines = text.readlines()
 
2964
            f = self.branch.repository._text_store.get(ie.text_id)
 
2965
            try:
 
2966
                file_lines = f.readlines()
 
2967
            finally:
 
2968
                f.close()
2952
2969
            w.add_lines(rev_id, previous_revisions, file_lines)
2953
2970
            self.text_count += 1
2954
2971
        else:
3235
3252
        # XXX: It's a bit ugly that the network name is here, because we'd
3236
3253
        # like to believe that format objects are stateless or at least
3237
3254
        # immutable,  However, we do at least avoid mutating the name after
3238
 
        # it's returned.  See <https://bugs.edge.launchpad.net/bzr/+bug/504102>
 
3255
        # it's returned.  See <https://bugs.launchpad.net/bzr/+bug/504102>
3239
3256
        self._network_name = None
3240
3257
 
3241
3258
    def __repr__(self):