Add a scheme for handling remote locking
authorMatt Mackall <mpm@selenic.com>
Wed, 06 Jul 2005 22:23:27 -0800
changeset 638 35f7adfefa69
parent 637 31e090c34d3b
child 639 31cebba881a0
Add a scheme for handling remote locking This adds an object that remembers to unlock the remote repo on destruction and lock/unlock functions for the ssh protocol. The remote repository should also unlock itself when the connection goes down.
mercurial/commands.py
mercurial/hg.py
--- a/mercurial/commands.py	Wed Jul 06 22:21:23 2005 -0800
+++ b/mercurial/commands.py	Wed Jul 06 22:23:27 2005 -0800
@@ -880,6 +880,8 @@
             fout.write(v)
             fout.flush()
 
+        lock = None
+
         while 1:
             cmd = fin.readline()[:-1]
             if cmd == '':
@@ -887,6 +889,13 @@
             if cmd == "heads":
                 h = repo.heads()
                 respond(" ".join(map(hg.hex, h)) + "\n")
+            if cmd == "lock":
+                lock = repo.lock()
+                respond("")
+            if cmd == "unlock":
+                if lock: lock.release()
+                lock = None
+                respond("")
             elif cmd == "branches":
                 arg, nodes = getarg()
                 nodes = map(hg.bin, nodes.split(" "))
--- a/mercurial/hg.py	Wed Jul 06 22:21:23 2005 -0800
+++ b/mercurial/hg.py	Wed Jul 06 22:23:27 2005 -0800
@@ -1620,6 +1620,15 @@
 
         return zread(f)
 
+class remotelock:
+    def __init__(self, repo):
+        self.repo = repo
+    def release(self):
+        self.repo.unlock()
+        self.repo = None
+    def __del__(self):
+        if self.repo:
+            self.release()
 
 class sshrepository:
     def __init__(self, ui, path):
@@ -1666,6 +1675,13 @@
         l = int(r.readline())
         return r.read(l)
 
+    def lock(self):
+        self.call("lock")
+        return remotelock(self)
+
+    def unlock(self):
+        self.call("unlock")
+
     def heads(self):
         d = self.call("heads")
         try: