~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

Rearrange log opening helper function and fix a couple of bugs

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    lock,
28
28
    lockdir,
29
29
    repository,
30
 
    repository as _mod_repository,
31
30
    revision,
32
31
    revision as _mod_revision,
33
 
    static_tuple,
34
32
    symbol_versioning,
35
33
)
36
 
from bzrlib.branch import BranchReferenceFormat, BranchWriteLockResult
 
34
from bzrlib.branch import BranchReferenceFormat
37
35
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
38
36
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
39
37
from bzrlib.errors import (
43
41
from bzrlib.lockable_files import LockableFiles
44
42
from bzrlib.smart import client, vfs, repository as smart_repo
45
43
from bzrlib.revision import ensure_null, NULL_REVISION
46
 
from bzrlib.repository import RepositoryWriteLockResult
47
44
from bzrlib.trace import mutter, note, warning
48
45
 
49
46
 
644
641
        return self._custom_format._serializer
645
642
 
646
643
 
647
 
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin,
648
 
    bzrdir.ControlComponent):
 
644
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin):
649
645
    """Repository accessed over rpc.
650
646
 
651
647
    For the moment most operations are performed using local transport-backed
694
690
        # Additional places to query for data.
695
691
        self._fallback_repositories = []
696
692
 
697
 
    @property
698
 
    def user_transport(self):
699
 
        return self.bzrdir.user_transport
700
 
 
701
 
    @property
702
 
    def control_transport(self):
703
 
        # XXX: Normally you shouldn't directly get at the remote repository
704
 
        # transport, but I'm not sure it's worth making this method
705
 
        # optional -- mbp 2010-04-21
706
 
        return self.bzrdir.get_repository_transport(None)
707
 
        
708
693
    def __str__(self):
709
694
        return "%s(%s)" % (self.__class__.__name__, self.base)
710
695
 
918
903
        parents_provider = self._make_parents_provider(other_repository)
919
904
        return graph.Graph(parents_provider)
920
905
 
921
 
    @needs_read_lock
922
 
    def get_known_graph_ancestry(self, revision_ids):
923
 
        """Return the known graph for a set of revision ids and their ancestors.
924
 
        """
925
 
        st = static_tuple.StaticTuple
926
 
        revision_keys = [st(r_id).intern() for r_id in revision_ids]
927
 
        known_graph = self.revisions.get_known_graph_ancestry(revision_keys)
928
 
        return graph.GraphThunkIdsToKeys(known_graph)
929
 
 
930
906
    def gather_stats(self, revid=None, committers=None):
931
907
        """See Repository.gather_stats()."""
932
908
        path = self.bzrdir._path_for_remote_call(self._client)
998
974
        pass
999
975
 
1000
976
    def lock_read(self):
1001
 
        """Lock the repository for read operations.
1002
 
 
1003
 
        :return: An object with an unlock method which will release the lock
1004
 
            obtained.
1005
 
        """
1006
977
        # wrong eventually - want a local lock cache context
1007
978
        if not self._lock_mode:
1008
979
            self._note_lock('r')
1015
986
                repo.lock_read()
1016
987
        else:
1017
988
            self._lock_count += 1
1018
 
        return self
1019
989
 
1020
990
    def _remote_lock_write(self, token):
1021
991
        path = self.bzrdir._path_for_remote_call(self._client)
1061
1031
            raise errors.ReadOnlyError(self)
1062
1032
        else:
1063
1033
            self._lock_count += 1
1064
 
        return RepositoryWriteLockResult(self.unlock, self._lock_token or None)
 
1034
        return self._lock_token or None
1065
1035
 
1066
1036
    def leave_lock_in_place(self):
1067
1037
        if not self._lock_token:
1247
1217
            # state, so always add a lock here. If a caller passes us a locked
1248
1218
            # repository, they are responsible for unlocking it later.
1249
1219
            repository.lock_read()
1250
 
        self._check_fallback_repository(repository)
1251
1220
        self._fallback_repositories.append(repository)
1252
1221
        # If self._real_repository was parameterised already (e.g. because a
1253
1222
        # _real_branch had its get_stacked_on_url method called), then the
1254
1223
        # repository to be added may already be in the _real_repositories list.
1255
1224
        if self._real_repository is not None:
1256
 
            fallback_locations = [repo.user_url for repo in
 
1225
            fallback_locations = [repo.bzrdir.root_transport.base for repo in
1257
1226
                self._real_repository._fallback_repositories]
1258
 
            if repository.user_url not in fallback_locations:
 
1227
            if repository.bzrdir.root_transport.base not in fallback_locations:
1259
1228
                self._real_repository.add_fallback_repository(repository)
1260
1229
 
1261
 
    def _check_fallback_repository(self, repository):
1262
 
        """Check that this repository can fallback to repository safely.
1263
 
 
1264
 
        Raise an error if not.
1265
 
 
1266
 
        :param repository: A repository to fallback to.
1267
 
        """
1268
 
        return _mod_repository.InterRepository._assert_same_model(
1269
 
            self, repository)
1270
 
 
1271
1230
    def add_inventory(self, revid, inv, parents):
1272
1231
        self._ensure_real()
1273
1232
        return self._real_repository.add_inventory(revid, inv, parents)
1626
1585
        return self._real_repository.inventories
1627
1586
 
1628
1587
    @needs_write_lock
1629
 
    def pack(self, hint=None, clean_obsolete_packs=False):
 
1588
    def pack(self, hint=None):
1630
1589
        """Compress the data within the repository.
1631
1590
 
1632
1591
        This is not currently implemented within the smart server.
1633
1592
        """
1634
1593
        self._ensure_real()
1635
 
        return self._real_repository.pack(hint=hint, clean_obsolete_packs=clean_obsolete_packs)
 
1594
        return self._real_repository.pack(hint=hint)
1636
1595
 
1637
1596
    @property
1638
1597
    def revisions(self):
2200
2159
            self._real_branch = None
2201
2160
        # Fill out expected attributes of branch for bzrlib API users.
2202
2161
        self._clear_cached_state()
2203
 
        # TODO: deprecate self.base in favor of user_url
2204
 
        self.base = self.bzrdir.user_url
 
2162
        self.base = self.bzrdir.root_transport.base
2205
2163
        self._name = name
2206
2164
        self._control_files = None
2207
2165
        self._lock_mode = None
2394
2352
            self._vfs_set_tags_bytes(bytes)
2395
2353
 
2396
2354
    def lock_read(self):
2397
 
        """Lock the branch for read operations.
2398
 
 
2399
 
        :return: An object with an unlock method which will release the lock
2400
 
            obtained.
2401
 
        """
2402
2355
        self.repository.lock_read()
2403
2356
        if not self._lock_mode:
2404
2357
            self._note_lock('r')
2408
2361
                self._real_branch.lock_read()
2409
2362
        else:
2410
2363
            self._lock_count += 1
2411
 
        return self
2412
2364
 
2413
2365
    def _remote_lock_write(self, token):
2414
2366
        if token is None:
2415
2367
            branch_token = repo_token = ''
2416
2368
        else:
2417
2369
            branch_token = token
2418
 
            repo_token = self.repository.lock_write().repository_token
 
2370
            repo_token = self.repository.lock_write()
2419
2371
            self.repository.unlock()
2420
2372
        err_context = {'token': token}
2421
2373
        response = self._call(
2458
2410
            self._lock_count += 1
2459
2411
            # Re-lock the repository too.
2460
2412
            self.repository.lock_write(self._repo_lock_token)
2461
 
        return BranchWriteLockResult(self.unlock, self._lock_token or None)
 
2413
        return self._lock_token or None
2462
2414
 
2463
2415
    def _unlock(self, branch_token, repo_token):
2464
2416
        err_context = {'token': str((branch_token, repo_token))}