/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/bzrdir.py

  • Committer: Aaron Bentley
  • Date: 2007-04-01 04:06:14 UTC
  • mfrom: (2388 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2389.
  • Revision ID: aaron.bentley@utoronto.ca-20070401040614-3f0tytdrc2jtv8f6
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
            # see open_downlevel to open legacy branches.
119
119
            raise errors.UnsupportedFormatError(format=format)
120
120
 
121
 
    def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
 
121
    def clone(self, url, revision_id=None, force_new_repo=False):
122
122
        """Clone this bzrdir and its contents to url verbatim.
123
123
 
124
124
        If urls last component does not exist, it will be created.
129
129
                               even if one is available.
130
130
        """
131
131
        self._make_tail(url)
132
 
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
133
132
        result = self._format.initialize(url)
134
133
        try:
135
134
            local_repo = self.find_repository()
140
139
            if force_new_repo:
141
140
                result_repo = local_repo.clone(
142
141
                    result,
143
 
                    revision_id=revision_id,
144
 
                    basis=basis_repo)
 
142
                    revision_id=revision_id)
145
143
                result_repo.set_make_working_trees(local_repo.make_working_trees())
146
144
            else:
147
145
                try:
148
146
                    result_repo = result.find_repository()
149
147
                    # fetch content this dir needs.
150
 
                    if basis_repo:
151
 
                        # XXX FIXME RBC 20060214 need tests for this when the basis
152
 
                        # is incomplete
153
 
                        result_repo.fetch(basis_repo, revision_id=revision_id)
154
148
                    result_repo.fetch(local_repo, revision_id=revision_id)
155
149
                except errors.NoRepositoryPresent:
156
150
                    # needed to make one anyway.
157
151
                    result_repo = local_repo.clone(
158
152
                        result,
159
 
                        revision_id=revision_id,
160
 
                        basis=basis_repo)
 
153
                        revision_id=revision_id)
161
154
                    result_repo.set_make_working_trees(local_repo.make_working_trees())
162
155
        # 1 if there is a branch present
163
156
        #   make sure its content is available in the target repository
167
160
        except errors.NotBranchError:
168
161
            pass
169
162
        try:
170
 
            self.open_workingtree().clone(result, basis=basis_tree)
 
163
            self.open_workingtree().clone(result)
171
164
        except (errors.NoWorkingTree, errors.NotLocalUrl):
172
165
            pass
173
166
        return result
174
167
 
175
 
    def _get_basis_components(self, basis):
176
 
        """Retrieve the basis components that are available at basis."""
177
 
        if basis is None:
178
 
            return None, None, None
179
 
        try:
180
 
            basis_tree = basis.open_workingtree()
181
 
            basis_branch = basis_tree.branch
182
 
            basis_repo = basis_branch.repository
183
 
        except (errors.NoWorkingTree, errors.NotLocalUrl):
184
 
            basis_tree = None
185
 
            try:
186
 
                basis_branch = basis.open_branch()
187
 
                basis_repo = basis_branch.repository
188
 
            except errors.NotBranchError:
189
 
                basis_branch = None
190
 
                try:
191
 
                    basis_repo = basis.open_repository()
192
 
                except errors.NoRepositoryPresent:
193
 
                    basis_repo = None
194
 
        return basis_repo, basis_branch, basis_tree
195
 
 
196
168
    # TODO: This should be given a Transport, and should chdir up; otherwise
197
169
    # this will open a new connection.
198
170
    def _make_tail(self, url):
646
618
        except errors.NoWorkingTree:
647
619
            return False
648
620
 
649
 
    def _cloning_metadir(self, basis=None):
650
 
        def related_repository(bzrdir):
 
621
    def _cloning_metadir(self):
 
622
        result_format = self._format.__class__()
 
623
        try:
651
624
            try:
652
 
                branch = bzrdir.open_branch()
653
 
                return branch.repository
 
625
                branch = self.open_branch()
 
626
                source_repository = branch.repository
654
627
            except errors.NotBranchError:
655
628
                source_branch = None
656
 
                return bzrdir.open_repository()
657
 
        result_format = self._format.__class__()
658
 
        try:
659
 
            try:
660
 
                source_repository = related_repository(self)
661
 
            except errors.NoRepositoryPresent:
662
 
                if basis is None:
663
 
                    raise
664
 
                source_repository = related_repository(self)
 
629
                source_repository = self.open_repository()
665
630
            result_format.repository_format = source_repository._format
666
631
        except errors.NoRepositoryPresent:
667
632
            source_repository = None
673
638
            result_format.workingtree_format = tree._format.__class__()
674
639
        return result_format, source_repository
675
640
 
676
 
    def cloning_metadir(self, basis=None):
 
641
    def cloning_metadir(self):
677
642
        """Produce a metadir suitable for cloning or sprouting with.
678
643
 
679
644
        These operations may produce workingtrees (yes, even though they're
691
656
    def checkout_metadir(self):
692
657
        return self.cloning_metadir()
693
658
 
694
 
    def sprout(self, url, revision_id=None, basis=None, force_new_repo=False,
 
659
    def sprout(self, url, revision_id=None, force_new_repo=False,
695
660
               recurse='down'):
696
661
        """Create a copy of this bzrdir prepared for use as a new line of
697
662
        development.
707
672
            itself to download less data.
708
673
        """
709
674
        self._make_tail(url)
710
 
        cloning_format = self.cloning_metadir(basis)
 
675
        cloning_format = self.cloning_metadir()
711
676
        result = cloning_format.initialize(url)
712
 
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
713
677
        try:
714
678
            source_branch = self.open_branch()
715
679
            source_repository = source_branch.repository
718
682
            try:
719
683
                source_repository = self.open_repository()
720
684
            except errors.NoRepositoryPresent:
721
 
                # copy the entire basis one if there is one
722
 
                # but there is no repository.
723
 
                source_repository = basis_repo
 
685
                source_repository = None
724
686
        if force_new_repo:
725
687
            result_repo = None
726
688
        else:
741
703
            result_repo = result.create_repository()
742
704
        if result_repo is not None:
743
705
            # fetch needed content into target.
744
 
            if basis_repo:
745
 
                # XXX FIXME RBC 20060214 need tests for this when the basis
746
 
                # is incomplete
747
 
                result_repo.fetch(basis_repo, revision_id=revision_id)
748
706
            if source_repository is not None:
749
707
                result_repo.fetch(source_repository, revision_id=revision_id)
750
708
        if source_branch is not None:
810
768
        """Pre-splitout bzrdirs do not suffer from stale locks."""
811
769
        raise NotImplementedError(self.break_lock)
812
770
 
813
 
    def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
 
771
    def clone(self, url, revision_id=None, force_new_repo=False):
814
772
        """See BzrDir.clone()."""
815
773
        from bzrlib.workingtree import WorkingTreeFormat2
816
774
        self._make_tail(url)
817
775
        result = self._format._initialize_for_clone(url)
818
 
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
819
 
        self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
 
776
        self.open_repository().clone(result, revision_id=revision_id)
820
777
        from_branch = self.open_branch()
821
778
        from_branch.clone(result, revision_id=revision_id)
822
779
        try:
823
 
            self.open_workingtree().clone(result, basis=basis_tree)
 
780
            self.open_workingtree().clone(result)
824
781
        except errors.NotLocalUrl:
825
782
            # make a new one, this format always has to have one.
826
783
            try:
912
869
        self._check_supported(format, unsupported)
913
870
        return format.open(self, _found=True)
914
871
 
915
 
    def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
 
872
    def sprout(self, url, revision_id=None, force_new_repo=False):
916
873
        """See BzrDir.sprout()."""
917
874
        from bzrlib.workingtree import WorkingTreeFormat2
918
875
        self._make_tail(url)
919
876
        result = self._format._initialize_for_clone(url)
920
 
        basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
921
877
        try:
922
 
            self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
 
878
            self.open_repository().clone(result, revision_id=revision_id)
923
879
        except errors.NoRepositoryPresent:
924
880
            pass
925
881
        try: