~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2010-06-25 06:23:08 UTC
  • mto: This revision was merged to the branch mainline in revision 5324.
  • Revision ID: robertc@robertcollins.net-20100625062308-qx287gzfrehs1d21
Restore the original ui_factory when existing BzrLibraryState.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
        bzrdir,
26
26
        cache_utf8,
27
27
        config as _mod_config,
28
 
        controldir,
29
28
        debug,
30
29
        errors,
31
30
        lockdir,
65
64
BZR_BRANCH_FORMAT_6 = "Bazaar Branch Format 6 (bzr 0.15)\n"
66
65
 
67
66
 
68
 
class Branch(controldir.ControlComponent):
 
67
class Branch(bzrdir.ControlComponent):
69
68
    """Branch holding a history of revisions.
70
69
 
71
70
    :ivar base:
247
246
        if not local and not config.has_explicit_nickname():
248
247
            try:
249
248
                master = self.get_master_branch(possible_transports)
250
 
                if master and self.user_url == master.user_url:
251
 
                    raise errors.RecursiveBind(self.user_url)
252
249
                if master is not None:
253
250
                    # return the master branch value
254
251
                    return master.nick
255
 
            except errors.RecursiveBind, e:
256
 
                raise e
257
252
            except errors.BzrError, e:
258
253
                # Silently fall back to local implicit nick if the master is
259
254
                # unavailable
806
801
            if len(old_repository._fallback_repositories) != 1:
807
802
                raise AssertionError("can't cope with fallback repositories "
808
803
                    "of %r" % (self.repository,))
809
 
            # Open the new repository object.
810
 
            # Repositories don't offer an interface to remove fallback
811
 
            # repositories today; take the conceptually simpler option and just
812
 
            # reopen it.  We reopen it starting from the URL so that we
813
 
            # get a separate connection for RemoteRepositories and can
814
 
            # stream from one of them to the other.  This does mean doing
815
 
            # separate SSH connection setup, but unstacking is not a
816
 
            # common operation so it's tolerable.
817
 
            new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
818
 
            new_repository = new_bzrdir.find_repository()
819
 
            if new_repository._fallback_repositories:
820
 
                raise AssertionError("didn't expect %r to have "
821
 
                    "fallback_repositories"
822
 
                    % (self.repository,))
823
 
            # Replace self.repository with the new repository.
824
 
            # Do our best to transfer the lock state (i.e. lock-tokens and
825
 
            # lock count) of self.repository to the new repository.
826
 
            lock_token = old_repository.lock_write().repository_token
827
 
            self.repository = new_repository
828
 
            if isinstance(self, remote.RemoteBranch):
829
 
                # Remote branches can have a second reference to the old
830
 
                # repository that need to be replaced.
831
 
                if self._real_branch is not None:
832
 
                    self._real_branch.repository = new_repository
833
 
            self.repository.lock_write(token=lock_token)
834
 
            if lock_token is not None:
835
 
                old_repository.leave_lock_in_place()
 
804
            # unlock it, including unlocking the fallback
836
805
            old_repository.unlock()
837
 
            if lock_token is not None:
838
 
                # XXX: self.repository.leave_lock_in_place() before this
839
 
                # function will not be preserved.  Fortunately that doesn't
840
 
                # affect the current default format (2a), and would be a
841
 
                # corner-case anyway.
842
 
                #  - Andrew Bennetts, 2010/06/30
843
 
                self.repository.dont_leave_lock_in_place()
844
 
            old_lock_count = 0
845
 
            while True:
846
 
                try:
847
 
                    old_repository.unlock()
848
 
                except errors.LockNotHeld:
849
 
                    break
850
 
                old_lock_count += 1
851
 
            if old_lock_count == 0:
852
 
                raise AssertionError(
853
 
                    'old_repository should have been locked at least once.')
854
 
            for i in range(old_lock_count-1):
 
806
            old_repository.lock_read()
 
807
            try:
 
808
                # Repositories don't offer an interface to remove fallback
 
809
                # repositories today; take the conceptually simpler option and just
 
810
                # reopen it.  We reopen it starting from the URL so that we
 
811
                # get a separate connection for RemoteRepositories and can
 
812
                # stream from one of them to the other.  This does mean doing
 
813
                # separate SSH connection setup, but unstacking is not a
 
814
                # common operation so it's tolerable.
 
815
                new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
 
816
                new_repository = new_bzrdir.find_repository()
 
817
                self.repository = new_repository
 
818
                if self.repository._fallback_repositories:
 
819
                    raise AssertionError("didn't expect %r to have "
 
820
                        "fallback_repositories"
 
821
                        % (self.repository,))
 
822
                # this is not paired with an unlock because it's just restoring
 
823
                # the previous state; the lock's released when set_stacked_on_url
 
824
                # returns
855
825
                self.repository.lock_write()
856
 
            # Fetch from the old repository into the new.
857
 
            old_repository.lock_read()
858
 
            try:
859
826
                # XXX: If you unstack a branch while it has a working tree
860
827
                # with a pending merge, the pending-merged revisions will no
861
828
                # longer be present.  You can (probably) revert and remerge.
1862
1829
            "all are called with the url returned from the previous hook."
1863
1830
            "The order is however undefined.", (1, 9), None))
1864
1831
        self.create_hook(HookPoint('automatic_tag_name',
1865
 
            "Called to determine an automatic tag name for a revision. "
 
1832
            "Called to determine an automatic tag name for a revision."
1866
1833
            "automatic_tag_name is called with (branch, revision_id) and "
1867
1834
            "should return a tag name or None if no tag name could be "
1868
1835
            "determined. The first non-None tag name returned will be used.",
1959
1926
        return self.__dict__ == other.__dict__
1960
1927
 
1961
1928
    def __repr__(self):
1962
 
        return "<%s of %s>" % (self.__class__.__name__, self.branch)
 
1929
        if self.branch:
 
1930
            return "<%s of %s>" % (self.__class__.__name__, self.branch)
 
1931
        else:
 
1932
            return "<%s of format:%s bzrdir:%s>" % (
 
1933
                self.__class__.__name__, self.branch,
 
1934
                self.format, self.bzrdir)
1963
1935
 
1964
1936
 
1965
1937
class SwitchHookParams(object):
3309
3281
        """
3310
3282
        raise NotImplementedError(self.push)
3311
3283
 
3312
 
    @needs_write_lock
3313
 
    def copy_content_into(self, revision_id=None):
3314
 
        """Copy the content of source into target
3315
 
 
3316
 
        revision_id: if not None, the revision history in the new branch will
3317
 
                     be truncated to end with revision_id.
3318
 
        """
3319
 
        raise NotImplementedError(self.copy_content_into)
3320
 
 
3321
3284
 
3322
3285
class GenericInterBranch(InterBranch):
3323
3286
    """InterBranch implementation that uses public Branch functions."""