# HG changeset patch # User Matt Mackall # Date 1120717407 28800 # Node ID 35f7adfefa69dad2c48d0988833179d472cb4a44 # Parent 31e090c34d3b7dbe0e92597d2fd2430d2ccb7329 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. diff -r 31e090c34d3b -r 35f7adfefa69 mercurial/commands.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(" ")) diff -r 31e090c34d3b -r 35f7adfefa69 mercurial/hg.py --- 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: