stopgap hg push support
authormpm@selenic.com
Sun, 12 Jun 2005 19:35:41 -0800
changeset 319 9ab17e83bce3
parent 318 2819f63b16bf
child 320 292e10b5831a
stopgap hg push support -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 stopgap hg push support This does hg push by running hg serve and tunnelling it over ssh to a client at the destination doing hg pull. manifest hash: 552607f1e8bea238b4c585209af93f0594121dd1 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCrP8NywK+sNU5EO8RAmGJAKCJ9kQSz6Bs/4cYCvKU7TpDXPHSbgCdEE1X FfZe2y2xtgSeHQa/uZLqEBQ= =KlPp -----END PGP SIGNATURE-----
mercurial/commands.py
--- a/mercurial/commands.py	Sun Jun 12 10:20:07 2005 -0800
+++ b/mercurial/commands.py	Sun Jun 12 19:35:41 2005 -0800
@@ -8,7 +8,7 @@
 import os, re, sys, signal
 import fancyopts, ui, hg
 from demandload import *
-demandload(globals(), "mdiff time hgweb traceback")
+demandload(globals(), "mdiff time hgweb traceback random signal")
 
 class UnknownCommand(Exception): pass
 
@@ -412,6 +412,41 @@
     cg = repo.getchangegroup(other)
     repo.addchangegroup(cg)
 
+def push(ui, repo, dest):
+    """push changes to the specified destination"""
+    paths = {}
+    for name, path in ui.configitems("paths"):
+        paths[name] = path
+
+    if dest in paths: dest = paths[dest]
+    
+    if not dest.startswith("ssh://"):
+        ui.warn("abort: can only push to ssh:// destinations currently\n")
+        return 1
+
+    m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', dest)
+    if not m:
+        ui.warn("abort: couldn't parse destination %s\n" % dest)
+        return 1
+
+    user, host, port, path = map(m.group, (2, 3, 5, 7))
+    host = user and ("%s@%s" % (user, host)) or host
+    port = port and (" -p %s") % port or ""
+    path = path or ""
+
+    sport = random.randrange(30000, 60000)
+    cmd = "ssh %s%s -R %d:localhost:%d 'cd %s; hg pull http://localhost:%d/'"
+    cmd = cmd % (host, port, sport+1, sport, path, sport+1)
+
+    child = os.fork()
+    if not child:
+        sys.stdout = file("/dev/null", "w")
+        sys.stderr = sys.stdout
+        hgweb.server(repo.root, "pull", "", "localhost", sport)
+    else:
+        r = os.system(cmd)
+        os.kill(child, signal.SIGTERM)
+
 def rawcommit(ui, repo, files, **rc):
     "raw commit interface"
 
@@ -549,6 +584,7 @@
                       ('q', 'quiet', "", 'silence diff')],
                      "hg import [options] patches"),
     "pull|merge": (pull, [], 'hg pull [source]'),
+    "push": (push, [], 'hg push <destination>'),
     "rawcommit": (rawcommit,
                   [('p', 'parent', [], 'parent'),
                    ('d', 'date', "", 'data'),