~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Robert Collins
  • Date: 2007-11-26 02:11:10 UTC
  • mto: This revision was merged to the branch mainline in revision 3029.
  • Revision ID: robertc@robertcollins.net-20071126021110-bnc8ls8pjlbojj92
Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
465
465
    def lock_write(self, token=None):
466
466
        if not self._lock_mode:
467
467
            self._lock_token = self._remote_lock_write(token)
468
 
            assert self._lock_token, 'Remote server did not return a token!'
 
468
            # if self._lock_token is None, then this is something like packs or
 
469
            # svn where we don't get to lock the repo, or a weave style repository
 
470
            # where we cannot lock it over the wire and attempts to do so will
 
471
            # fail.
469
472
            if self._real_repository is not None:
470
473
                self._real_repository.lock_write(token=self._lock_token)
471
474
            if token is not None:
478
481
            raise errors.ReadOnlyError(self)
479
482
        else:
480
483
            self._lock_count += 1
481
 
        return self._lock_token
 
484
        return self._lock_token or None
482
485
 
483
486
    def leave_lock_in_place(self):
 
487
        if not self._lock_token:
 
488
            raise NotImplementedError(self.leave_lock_in_place)
484
489
        self._leave_lock = True
485
490
 
486
491
    def dont_leave_lock_in_place(self):
 
492
        if not self._lock_token:
 
493
            raise NotImplementedError(self.leave_lock_in_place)
487
494
        self._leave_lock = False
488
495
 
489
496
    def _set_real_repository(self, repository):
514
521
 
515
522
    def _unlock(self, token):
516
523
        path = self.bzrdir._path_for_remote_call(self._client)
 
524
        if not token:
 
525
            # with no token the remote repository is not persistently locked.
 
526
            return
517
527
        response = self._client.call('Repository.unlock', path, token)
518
528
        if response == ('ok',):
519
529
            return
542
552
            if old_mode == 'w':
543
553
                # Only write-locked repositories need to make a remote method
544
554
                # call to perfom the unlock.
545
 
                assert self._lock_token, \
546
 
                    '%s is locked, but has no token' \
547
 
                    % self
548
555
                old_token = self._lock_token
549
556
                self._lock_token = None
550
557
                if not self._leave_lock:
604
611
        builder = self._real_repository.get_commit_builder(branch, parents,
605
612
                config, timestamp=timestamp, timezone=timezone,
606
613
                committer=committer, revprops=revprops, revision_id=revision_id)
607
 
        # Make the builder use this RemoteRepository rather than the real one.
608
 
        builder.repository = self
 
614
        ## We used to do this for knits, so that invidual methods could be
 
615
        ## accelerated, but actually this was in hindsight a bad idea. Because
 
616
        ## really we do need the real repository to assemble the work it's own
 
617
        ## way.
 
618
        ## # Make the builder use this RemoteRepository rather than the real one.
 
619
        ## builder.repository = self
609
620
        return builder
610
621
 
611
622
    @needs_write_lock
1055
1066
            self.repository.unlock()
1056
1067
        path = self.bzrdir._path_for_remote_call(self._client)
1057
1068
        response = self._client.call('Branch.lock_write', path, branch_token,
1058
 
                                     repo_token)
 
1069
                                     repo_token or '')
1059
1070
        if response[0] == 'ok':
1060
1071
            ok, branch_token, repo_token = response
1061
1072
            return branch_token, repo_token
1108
1119
                if token != self._lock_token:
1109
1120
                    raise errors.TokenMismatch(token, self._lock_token)
1110
1121
            self._lock_count += 1
1111
 
        return self._lock_token
 
1122
        return self._lock_token or None
1112
1123
 
1113
1124
    def _unlock(self, branch_token, repo_token):
1114
1125
        path = self.bzrdir._path_for_remote_call(self._client)
1115
1126
        response = self._client.call('Branch.unlock', path, branch_token,
1116
 
                                     repo_token)
 
1127
                                     repo_token or '')
1117
1128
        if response == ('ok',):
1118
1129
            return
1119
1130
        elif response[0] == 'TokenMismatch':
1129
1140
            mode = self._lock_mode
1130
1141
            self._lock_mode = None
1131
1142
            if self._real_branch is not None:
1132
 
                if not self._leave_lock:
 
1143
                if (not self._leave_lock and mode == 'w' and
 
1144
                    self._repo_lock_token):
1133
1145
                    # If this RemoteBranch will remove the physical lock for the
1134
1146
                    # repository, make sure the _real_branch doesn't do it
1135
1147
                    # first.  (Because the _real_branch's repository is set to
1153
1165
        return self._real_branch.break_lock()
1154
1166
 
1155
1167
    def leave_lock_in_place(self):
 
1168
        if not self._lock_token:
 
1169
            raise NotImplementedError(self.leave_lock_in_place)
1156
1170
        self._leave_lock = True
1157
1171
 
1158
1172
    def dont_leave_lock_in_place(self):
 
1173
        if not self._lock_token:
 
1174
            raise NotImplementedError(self.leave_lock_in_place)
1159
1175
        self._leave_lock = False
1160
1176
 
1161
1177
    def last_revision_info(self):