~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-09-05 10:17:04 UTC
  • mto: This revision was merged to the branch mainline in revision 3693.
  • Revision ID: andrew.bennetts@canonical.com-20080905101704-6g8iio31vb1wb2pf
Delete some cruft (like the _ensure_real call in RemoteBranch.lock_write), improve some comments, and wrap some long lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
356
356
 
357
357
        Used before calls to self._real_repository.
358
358
        """
359
 
        if not self._real_repository:
 
359
        if self._real_repository is None:
360
360
            self.bzrdir._ensure_real()
361
 
            #self._real_repository = self.bzrdir._real_bzrdir.open_repository()
362
 
            self._set_real_repository(self.bzrdir._real_bzrdir.open_repository())
 
361
            self._set_real_repository(
 
362
                self.bzrdir._real_bzrdir.open_repository())
363
363
 
364
364
    def _translate_error(self, err, **context):
365
365
        self.bzrdir._translate_error(err, repository=self, **context)
595
595
        :param repository: The repository to fallback to for non-hpss
596
596
            implemented operations.
597
597
        """
 
598
        if self._real_repository is not None:
 
599
            raise AssertionError('_real_repository is already set')
598
600
        if isinstance(repository, RemoteRepository):
599
601
            raise AssertionError()
600
602
        self._real_repository = repository
709
711
        # FIXME: It ought to be possible to call this without immediately
710
712
        # triggering _ensure_real.  For now it's the easiest thing to do.
711
713
        self._ensure_real()
712
 
        builder = self._real_repository.get_commit_builder(branch, parents,
 
714
        real_repo = self._real_repository
 
715
        builder = real_repo.get_commit_builder(branch, parents,
713
716
                config, timestamp=timestamp, timezone=timezone,
714
717
                committer=committer, revprops=revprops, revision_id=revision_id)
715
718
        return builder
1307
1310
                    'to use vfs implementation')
1308
1311
            self.bzrdir._ensure_real()
1309
1312
            self._real_branch = self.bzrdir._real_bzrdir.open_branch()
1310
 
            # Give the remote repository the matching real repo.
1311
 
            real_repo = self._real_branch.repository
1312
 
            if isinstance(real_repo, RemoteRepository):
1313
 
                real_repo._ensure_real()
1314
 
                real_repo = real_repo._real_repository
1315
 
            self.repository._set_real_repository(real_repo)
1316
 
            # Give the branch the remote repository to let fast-pathing happen.
 
1313
            if self.repository._real_repository is None:
 
1314
                # Give the remote repository the matching real repo.
 
1315
                real_repo = self._real_branch.repository
 
1316
                if isinstance(real_repo, RemoteRepository):
 
1317
                    real_repo._ensure_real()
 
1318
                    real_repo = real_repo._real_repository
 
1319
                self.repository._set_real_repository(real_repo)
 
1320
            # Give the real branch the remote repository to let fast-pathing
 
1321
            # happen.
1317
1322
            self._real_branch.repository = self.repository
1318
 
            # XXX: deal with _lock_mode == 'w'
1319
1323
            if self._lock_mode == 'r':
1320
1324
                self._real_branch.lock_read()
 
1325
            elif self._lock_mode == 'w':
 
1326
                self._real_branch.lock_write(token=self._lock_token)
1321
1327
 
1322
1328
    def _translate_error(self, err, **context):
1323
1329
        self.repository._translate_error(err, branch=self, **context)
1399
1405
        return branch_token, repo_token
1400
1406
            
1401
1407
    def lock_write(self, token=None):
1402
 
        #
1403
 
        # What BzrBranch.lock_write does:
1404
 
        #  - lock_write its repo (with no token)
1405
 
        #  - then lock_write itself (via self.control_files)
1406
 
        #
1407
 
        # But we don't want to do multiple round-trips to lock the branch +
1408
 
        # repo.  So, we:
1409
 
        #  - do Branch.lock_write RPC (which locks repo too)
1410
 
        #  - make sure self.repository's lock state is in sync with the results
1411
 
        #    of that RPC.
1412
 
 
1413
 
 
1414
1408
        if not self._lock_mode:
 
1409
            # Lock the branch and repo in one remote call.
1415
1410
            remote_tokens = self._remote_lock_write(token)
1416
1411
            self._lock_token, self._repo_lock_token = remote_tokens
1417
1412
            if not self._lock_token:
1418
1413
                raise SmartProtocolError('Remote server did not return a token!')
 
1414
            # Tell the self.repository object that it is locked.
1419
1415
            self.repository.lock_write(
1420
1416
                self._repo_lock_token, _skip_rpc=True)
1421
1417
 
1422
 
            # TODO: We really, really, really don't want to call _ensure_real
1423
 
            # here, but it's the easiest way to ensure coherency between the
1424
 
            # state of the RemoteBranch and RemoteRepository objects and the
1425
 
            # physical locks.  If we don't materialise the real objects here,
1426
 
            # then getting everything in the right state later is complex, so
1427
 
            # for now we just do it the lazy way.
1428
 
            #   -- Andrew Bennetts, 2007-02-22.
1429
 
            self._ensure_real()
1430
1418
            if self._real_branch is not None:
1431
 
                self._real_branch.repository.lock_write(
1432
 
                    token=self._repo_lock_token)
1433
 
                try:
1434
1419
                    self._real_branch.lock_write(token=self._lock_token)
1435
 
                finally:
1436
 
                    self._real_branch.repository.unlock()
1437
1420
            if token is not None:
1438
1421
                self._leave_lock = True
1439
1422
            else:
1440
 
                # XXX: this case seems to be unreachable; token cannot be None.
1441
1423
                self._leave_lock = False
1442
1424
            self._lock_mode = 'w'
1443
1425
            self._lock_count = 1
1445
1427
            raise errors.ReadOnlyTransaction
1446
1428
        else:
1447
1429
            if token is not None:
1448
 
                # A token was given to lock_write, and we're relocking, so check
1449
 
                # that the given token actually matches the one we already have.
 
1430
                # A token was given to lock_write, and we're relocking, so
 
1431
                # check that the given token actually matches the one we
 
1432
                # already have.
1450
1433
                if token != self._lock_token:
1451
1434
                    raise errors.TokenMismatch(token, self._lock_token)
1452
1435
            self._lock_count += 1
 
1436
            # Re-lock the repository too.
1453
1437
            self.repository.lock_write(self._repo_lock_token)
1454
1438
        return self._lock_token or None
1455
1439