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

  • Committer: John Arbash Meinel
  • Date: 2009-10-15 20:04:37 UTC
  • mfrom: (4748 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4752.
  • Revision ID: john@arbash-meinel.com-20091015200437-4wweb0t6uzspvv84
Bring in bzr.dev 4748, resolve conflict, update NEWS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
)
34
34
from bzrlib.branch import BranchReferenceFormat
35
35
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
36
 
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
36
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
37
37
from bzrlib.errors import (
38
38
    NoSuchRevision,
39
39
    SmartProtocolError,
89
89
class RemoteBzrDir(BzrDir, _RpcHelper):
90
90
    """Control directory on a remote server, accessed via bzr:// or similar."""
91
91
 
92
 
    def __init__(self, transport, format, _client=None):
 
92
    def __init__(self, transport, format, _client=None, _force_probe=False):
93
93
        """Construct a RemoteBzrDir.
94
94
 
95
95
        :param _client: Private parameter for testing. Disables probing and the
99
99
        # this object holds a delegated bzrdir that uses file-level operations
100
100
        # to talk to the other side
101
101
        self._real_bzrdir = None
 
102
        self._has_working_tree = None
102
103
        # 1-shot cache for the call pattern 'create_branch; open_branch' - see
103
104
        # create_branch for details.
104
105
        self._next_open_branch_result = None
108
109
            self._client = client._SmartClient(medium)
109
110
        else:
110
111
            self._client = _client
111
 
            return
112
 
 
 
112
            if not _force_probe:
 
113
                return
 
114
 
 
115
        self._probe_bzrdir()
 
116
 
 
117
    def _probe_bzrdir(self):
 
118
        medium = self._client._medium
113
119
        path = self._path_for_remote_call(self._client)
 
120
        if medium._is_remote_before((2, 1)):
 
121
            self._rpc_open(path)
 
122
            return
 
123
        try:
 
124
            self._rpc_open_2_1(path)
 
125
            return
 
126
        except errors.UnknownSmartMethod:
 
127
            medium._remember_remote_is_before((2, 1))
 
128
            self._rpc_open(path)
 
129
 
 
130
    def _rpc_open_2_1(self, path):
 
131
        response = self._call('BzrDir.open_2.1', path)
 
132
        if response == ('no',):
 
133
            raise errors.NotBranchError(path=self.root_transport.base)
 
134
        elif response[0] == 'yes':
 
135
            if response[1] == 'yes':
 
136
                self._has_working_tree = True
 
137
            elif response[1] == 'no':
 
138
                self._has_working_tree = False
 
139
            else:
 
140
                raise errors.UnexpectedSmartServerResponse(response)
 
141
        else:
 
142
            raise errors.UnexpectedSmartServerResponse(response)
 
143
 
 
144
    def _rpc_open(self, path):
114
145
        response = self._call('BzrDir.open', path)
115
146
        if response not in [('yes',), ('no',)]:
116
147
            raise errors.UnexpectedSmartServerResponse(response)
117
148
        if response == ('no',):
118
 
            raise errors.NotBranchError(path=transport.base)
 
149
            raise errors.NotBranchError(path=self.root_transport.base)
119
150
 
120
151
    def _ensure_real(self):
121
152
        """Ensure that there is a _real_bzrdir set.
355
386
        else:
356
387
            raise errors.NoRepositoryPresent(self)
357
388
 
 
389
    def has_workingtree(self):
 
390
        if self._has_working_tree is None:
 
391
            self._ensure_real()
 
392
            self._has_working_tree = self._real_bzrdir.has_workingtree()
 
393
        return self._has_working_tree
 
394
 
358
395
    def open_workingtree(self, recommend_upgrade=True):
359
 
        self._ensure_real()
360
 
        if self._real_bzrdir.has_workingtree():
 
396
        if self.has_workingtree():
361
397
            raise errors.NotLocalUrl(self.root_transport)
362
398
        else:
363
399
            raise errors.NoWorkingTree(self.root_transport.base)
583
619
        return self._custom_format._serializer
584
620
 
585
621
 
586
 
class RemoteRepository(_RpcHelper):
 
622
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin):
587
623
    """Repository accessed over rpc.
588
624
 
589
625
    For the moment most operations are performed using local transport-backed
913
949
    def lock_read(self):
914
950
        # wrong eventually - want a local lock cache context
915
951
        if not self._lock_mode:
 
952
            self._note_lock('r')
916
953
            self._lock_mode = 'r'
917
954
            self._lock_count = 1
918
955
            self._unstacked_provider.enable_cache(cache_misses=True)
938
975
 
939
976
    def lock_write(self, token=None, _skip_rpc=False):
940
977
        if not self._lock_mode:
 
978
            self._note_lock('w')
941
979
            if _skip_rpc:
942
980
                if self._lock_token is not None:
943
981
                    if token != self._lock_token:
1046
1084
        else:
1047
1085
            raise errors.UnexpectedSmartServerResponse(response)
1048
1086
 
 
1087
    @only_raises(errors.LockNotHeld, errors.LockBroken)
1049
1088
    def unlock(self):
1050
1089
        if not self._lock_count:
1051
1090
            return lock.cant_unlock_not_held(self)
1887
1926
        :param search: The overall search to satisfy with streams.
1888
1927
        :param sources: A list of Repository objects to query.
1889
1928
        """
1890
 
        self.serialiser = self.to_format._serializer
 
1929
        self.from_serialiser = self.from_repository._format._serializer
1891
1930
        self.seen_revs = set()
1892
1931
        self.referenced_revs = set()
1893
1932
        # If there are heads in the search, or the key count is > 0, we are not
1910
1949
    def missing_parents_rev_handler(self, substream):
1911
1950
        for content in substream:
1912
1951
            revision_bytes = content.get_bytes_as('fulltext')
1913
 
            revision = self.serialiser.read_revision_from_string(revision_bytes)
 
1952
            revision = self.from_serialiser.read_revision_from_string(
 
1953
                revision_bytes)
1914
1954
            self.seen_revs.add(content.key[-1])
1915
1955
            self.referenced_revs.update(revision.parent_ids)
1916
1956
            yield content
2044
2084
        return self._custom_format.supports_set_append_revisions_only()
2045
2085
 
2046
2086
 
2047
 
class RemoteBranch(branch.Branch, _RpcHelper):
 
2087
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2048
2088
    """Branch stored on a server accessed by HPSS RPC.
2049
2089
 
2050
2090
    At the moment most operations are mapped down to simple file operations.
2281
2321
    def lock_read(self):
2282
2322
        self.repository.lock_read()
2283
2323
        if not self._lock_mode:
 
2324
            self._note_lock('r')
2284
2325
            self._lock_mode = 'r'
2285
2326
            self._lock_count = 1
2286
2327
            if self._real_branch is not None:
2306
2347
 
2307
2348
    def lock_write(self, token=None):
2308
2349
        if not self._lock_mode:
 
2350
            self._note_lock('w')
2309
2351
            # Lock the branch and repo in one remote call.
2310
2352
            remote_tokens = self._remote_lock_write(token)
2311
2353
            self._lock_token, self._repo_lock_token = remote_tokens
2346
2388
            return
2347
2389
        raise errors.UnexpectedSmartServerResponse(response)
2348
2390
 
 
2391
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2349
2392
    def unlock(self):
2350
2393
        try:
2351
2394
            self._lock_count -= 1
2391
2434
            raise NotImplementedError(self.dont_leave_lock_in_place)
2392
2435
        self._leave_lock = False
2393
2436
 
 
2437
    @needs_read_lock
2394
2438
    def get_rev_id(self, revno, history=None):
2395
2439
        if revno == 0:
2396
2440
            return _mod_revision.NULL_REVISION