Rev 3024: Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects. in http://people.ubuntu.com/~robertc/baz2.0/pack.read-locks

Robert Collins robertc at robertcollins.net
Mon Nov 26 02:11:31 GMT 2007


At http://people.ubuntu.com/~robertc/baz2.0/pack.read-locks

------------------------------------------------------------
revno: 3024
revision-id:robertc at robertcollins.net-20071126021110-bnc8ls8pjlbojj92
parent: robertc at robertcollins.net-20071126021007-sf06t361rmv8renw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pack.read-locks
timestamp: Mon 2007-11-26 13:11:10 +1100
message:
  Handle repositories that do not allow remote locking, like pack repositories, in the client side remote server proxy objects.
modified:
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2007-11-22 22:33:27 +0000
+++ b/bzrlib/remote.py	2007-11-26 02:11:10 +0000
@@ -465,7 +465,10 @@
     def lock_write(self, token=None):
         if not self._lock_mode:
             self._lock_token = self._remote_lock_write(token)
-            assert self._lock_token, 'Remote server did not return a token!'
+            # if self._lock_token is None, then this is something like packs or
+            # svn where we don't get to lock the repo, or a weave style repository
+            # where we cannot lock it over the wire and attempts to do so will
+            # fail.
             if self._real_repository is not None:
                 self._real_repository.lock_write(token=self._lock_token)
             if token is not None:
@@ -478,12 +481,16 @@
             raise errors.ReadOnlyError(self)
         else:
             self._lock_count += 1
-        return self._lock_token
+        return self._lock_token or None
 
     def leave_lock_in_place(self):
+        if not self._lock_token:
+            raise NotImplementedError(self.leave_lock_in_place)
         self._leave_lock = True
 
     def dont_leave_lock_in_place(self):
+        if not self._lock_token:
+            raise NotImplementedError(self.leave_lock_in_place)
         self._leave_lock = False
 
     def _set_real_repository(self, repository):
@@ -514,6 +521,9 @@
 
     def _unlock(self, token):
         path = self.bzrdir._path_for_remote_call(self._client)
+        if not token:
+            # with no token the remote repository is not persistently locked.
+            return
         response = self._client.call('Repository.unlock', path, token)
         if response == ('ok',):
             return
@@ -542,9 +552,6 @@
             if old_mode == 'w':
                 # Only write-locked repositories need to make a remote method
                 # call to perfom the unlock.
-                assert self._lock_token, \
-                    '%s is locked, but has no token' \
-                    % self
                 old_token = self._lock_token
                 self._lock_token = None
                 if not self._leave_lock:
@@ -604,8 +611,12 @@
         builder = self._real_repository.get_commit_builder(branch, parents,
                 config, timestamp=timestamp, timezone=timezone,
                 committer=committer, revprops=revprops, revision_id=revision_id)
-        # Make the builder use this RemoteRepository rather than the real one.
-        builder.repository = self
+        ## We used to do this for knits, so that invidual methods could be
+        ## accelerated, but actually this was in hindsight a bad idea. Because
+        ## really we do need the real repository to assemble the work it's own
+        ## way.
+        ## # Make the builder use this RemoteRepository rather than the real one.
+        ## builder.repository = self
         return builder
 
     @needs_write_lock
@@ -1055,7 +1066,7 @@
             self.repository.unlock()
         path = self.bzrdir._path_for_remote_call(self._client)
         response = self._client.call('Branch.lock_write', path, branch_token,
-                                     repo_token)
+                                     repo_token or '')
         if response[0] == 'ok':
             ok, branch_token, repo_token = response
             return branch_token, repo_token
@@ -1108,12 +1119,12 @@
                 if token != self._lock_token:
                     raise errors.TokenMismatch(token, self._lock_token)
             self._lock_count += 1
-        return self._lock_token
+        return self._lock_token or None
 
     def _unlock(self, branch_token, repo_token):
         path = self.bzrdir._path_for_remote_call(self._client)
         response = self._client.call('Branch.unlock', path, branch_token,
-                                     repo_token)
+                                     repo_token or '')
         if response == ('ok',):
             return
         elif response[0] == 'TokenMismatch':
@@ -1129,7 +1140,8 @@
             mode = self._lock_mode
             self._lock_mode = None
             if self._real_branch is not None:
-                if not self._leave_lock:
+                if (not self._leave_lock and mode == 'w' and
+                    self._repo_lock_token):
                     # If this RemoteBranch will remove the physical lock for the
                     # repository, make sure the _real_branch doesn't do it
                     # first.  (Because the _real_branch's repository is set to
@@ -1153,9 +1165,13 @@
         return self._real_branch.break_lock()
 
     def leave_lock_in_place(self):
+        if not self._lock_token:
+            raise NotImplementedError(self.leave_lock_in_place)
         self._leave_lock = True
 
     def dont_leave_lock_in_place(self):
+        if not self._lock_token:
+            raise NotImplementedError(self.leave_lock_in_place)
         self._leave_lock = False
 
     def last_revision_info(self):



More information about the bazaar-commits mailing list