1590 yield zd.flush() |
1590 yield zd.flush() |
1591 break |
1591 break |
1592 yield zd.decompress(d) |
1592 yield zd.decompress(d) |
1593 self.ui.note("%d bytes of data transfered\n" % bytes) |
1593 self.ui.note("%d bytes of data transfered\n" % bytes) |
1594 |
1594 |
|
1595 class sshrepository: |
|
1596 def __init__(self, ui, path): |
|
1597 self.url = path |
|
1598 self.ui = ui |
|
1599 |
|
1600 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path) |
|
1601 if not m: |
|
1602 raise RepoError("couldn't parse destination %s\n" % path) |
|
1603 |
|
1604 self.user = m.group(2) |
|
1605 self.host = m.group(3) |
|
1606 self.port = m.group(5) |
|
1607 self.path = m.group(7) |
|
1608 |
|
1609 args = self.user and ("%s@%s" % (self.user, self.host)) or self.host |
|
1610 args = self.port and ("%s -p %s") % (args, self.port) or args |
|
1611 path = self.path or "" |
|
1612 |
|
1613 cmd = "ssh %s 'hg -R %s serve --stdio'" |
|
1614 cmd = cmd % (args, path) |
|
1615 |
|
1616 self.pipeo, self.pipei = os.popen2(cmd) |
|
1617 |
|
1618 def __del__(self): |
|
1619 self.pipeo.close() |
|
1620 self.pipei.close() |
|
1621 |
|
1622 def do_cmd(self, cmd, **args): |
|
1623 self.ui.debug("sending %s command\n" % cmd) |
|
1624 self.pipeo.write("%s\n" % cmd) |
|
1625 for k, v in args.items(): |
|
1626 self.pipeo.write("%s %d\n" % (k, len(v))) |
|
1627 self.pipeo.write(v) |
|
1628 self.pipeo.flush() |
|
1629 |
|
1630 return self.pipei |
|
1631 |
|
1632 def call(self, cmd, **args): |
|
1633 r = self.do_cmd(cmd, **args) |
|
1634 l = int(r.readline()) |
|
1635 return r.read(l) |
|
1636 |
|
1637 def heads(self): |
|
1638 d = self.call("heads") |
|
1639 try: |
|
1640 return map(bin, d[:-1].split(" ")) |
|
1641 except: |
|
1642 self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1643 raise |
|
1644 |
|
1645 def branches(self, nodes): |
|
1646 n = " ".join(map(hex, nodes)) |
|
1647 d = self.call("branches", nodes=n) |
|
1648 try: |
|
1649 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] |
|
1650 return br |
|
1651 except: |
|
1652 self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1653 raise |
|
1654 |
|
1655 def between(self, pairs): |
|
1656 n = "\n".join(["-".join(map(hex, p)) for p in pairs]) |
|
1657 d = self.call("between", pairs=n) |
|
1658 try: |
|
1659 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] |
|
1660 return p |
|
1661 except: |
|
1662 self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1663 raise |
|
1664 |
|
1665 def changegroup(self, nodes): |
|
1666 n = " ".join(map(hex, nodes)) |
|
1667 f = self.do_cmd("changegroup", roots=n) |
|
1668 bytes = 0 |
|
1669 while 1: |
|
1670 l = struct.unpack(">l", f.read(4))[0] |
|
1671 if l == -1: break |
|
1672 d = f.read(l) |
|
1673 bytes += len(d) |
|
1674 yield d |
|
1675 self.ui.note("%d bytes of data transfered\n" % bytes) |
|
1676 |
1595 def repository(ui, path=None, create=0): |
1677 def repository(ui, path=None, create=0): |
1596 if path: |
1678 if path: |
1597 if path.startswith("http://"): |
1679 if path.startswith("http://"): |
1598 return httprepository(ui, path) |
1680 return httprepository(ui, path) |
1599 if path.startswith("hg://"): |
1681 if path.startswith("hg://"): |
1600 return httprepository(ui, path.replace("hg://", "http://")) |
1682 return httprepository(ui, path.replace("hg://", "http://")) |
1601 if path.startswith("old-http://"): |
1683 if path.startswith("old-http://"): |
1602 return localrepository(ui, path.replace("old-http://", "http://")) |
1684 return localrepository(ui, path.replace("old-http://", "http://")) |
|
1685 if path.startswith("ssh://"): |
|
1686 return sshrepository(ui, path) |
1603 |
1687 |
1604 return localrepository(ui, path, create) |
1688 return localrepository(ui, path, create) |