Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/hg.py @ 638:35f7adfefa69
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.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 06 Jul 2005 22:23:27 -0800 |
parents | 31e090c34d3b |
children | 31cebba881a0 |
comparison
equal
deleted
inserted
replaced
637:31e090c34d3b | 638:35f7adfefa69 |
---|---|
1618 d, self.buf = self.buf[:l], self.buf[l:] | 1618 d, self.buf = self.buf[:l], self.buf[l:] |
1619 return d | 1619 return d |
1620 | 1620 |
1621 return zread(f) | 1621 return zread(f) |
1622 | 1622 |
1623 class remotelock: | |
1624 def __init__(self, repo): | |
1625 self.repo = repo | |
1626 def release(self): | |
1627 self.repo.unlock() | |
1628 self.repo = None | |
1629 def __del__(self): | |
1630 if self.repo: | |
1631 self.release() | |
1623 | 1632 |
1624 class sshrepository: | 1633 class sshrepository: |
1625 def __init__(self, ui, path): | 1634 def __init__(self, ui, path): |
1626 self.url = path | 1635 self.url = path |
1627 self.ui = ui | 1636 self.ui = ui |
1663 | 1672 |
1664 def call(self, cmd, **args): | 1673 def call(self, cmd, **args): |
1665 r = self.do_cmd(cmd, **args) | 1674 r = self.do_cmd(cmd, **args) |
1666 l = int(r.readline()) | 1675 l = int(r.readline()) |
1667 return r.read(l) | 1676 return r.read(l) |
1677 | |
1678 def lock(self): | |
1679 self.call("lock") | |
1680 return remotelock(self) | |
1681 | |
1682 def unlock(self): | |
1683 self.call("unlock") | |
1668 | 1684 |
1669 def heads(self): | 1685 def heads(self): |
1670 d = self.call("heads") | 1686 d = self.call("heads") |
1671 try: | 1687 try: |
1672 return map(bin, d[:-1].split(" ")) | 1688 return map(bin, d[:-1].split(" ")) |