Steve Losh avatar Steve Losh committed e34fd8b

Lots.

Comments (0)

Files changed (3)

 #!/usr/bin/env bash
 
+set -e
+
 DIR="`pwd`"
 CMD=""
 
 for ARG in "$@"
 do
-    CMD="$CMD"$'\n'"$ARG"
+    CMD="$CMD"$'\r\n'"$ARG"
 done
 
-PAYLOAD="$DIR"$'\n'"$CMD"$'\n'"HGDAEMONARGSDONE"$'\n'
+PAYLOAD="$DIR"$'\r\n'"$CMD"$'\r\n'"HGDAEMONARGSDONE"$'\r\n'
 
-echo "$PAYLOAD" | netcat localhost 8029
+echo "$PAYLOAD" | netcat localhost 8029 || { echo "abort: hgd server not running!" >&2; exit 1; }
 
 exit
-from diesel import Application, Service, until, send
+import sys
+from diesel import Application, Service, until, send, sleep
+from mimic import mercurial
 
-import os
-import sys
-from cStringIO import StringIO
 
-# MERCURIAL DISPATCH MIMICING -----------------------------------------------------
+class DieselBuffer(object):
+    def __init__(self, flush=False):
+        def _nop():
+            return
+        def _flush():
+            sleep(0.000001)
+        self.dflush = _flush if flush else _nop
 
-libdir = '@LIBDIR@'
+    def write(self, s):
+        # TODO: Figure out how to flush Diesel's buffer properly.
+        send(s)
+        self.dflush()
 
-if libdir != '@' 'LIBDIR' '@':
-    if not os.path.isabs(libdir):
-        libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
-                              libdir)
-        libdir = os.path.abspath(libdir)
-    sys.path.insert(0, libdir)
-
-# enable importing on demand to reduce startup time
-try:
-    from mercurial import demandimport; demandimport.enable()
-except ImportError:
-    import sys
-    sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
-                     ' '.join(sys.path))
-    sys.stderr.write("(check your install and PYTHONPATH)\n")
-    sys.exit(-1)
-
-import mercurial.util
-import mercurial.dispatch
-from mercurial import commands
-
-for fp in (sys.stdin, sys.stdout, sys.stderr):
-    mercurial.util.set_binary(fp)
-
-
-# FIX MERCURIAL'S BROKEN ALIAS ADDING ---------------------------------------------
-
-def _patched_addaliases(ui, cmdtable):
-    # aliases are processed after extensions have been loaded, so they
-    # may use extension commands. Aliases can also use other alias definitions,
-    # but only if they have been defined prior to the current definition.
-    for alias, definition in ui.configitems('alias'):
-        aliasdef = mercurial.dispatch.cmdalias(alias, definition, cmdtable)
-        if not aliasdef.cmd in cmdtable:
-            cmdtable[aliasdef.cmd] = (aliasdef, aliasdef.opts, aliasdef.help)
-        if aliasdef.norepo:
-            commands.norepo += ' %s' % alias
-mercurial.dispatch.addaliases = _patched_addaliases
-
-
-# REAL HGD CODE STARTS HERE -------------------------------------------------------
+    def flush(self):
+        sleep(0.000001)
 
 def _run(cwd, cmd):
-    sys.stdout = out = StringIO()
-    sys.stderr = out
+    flush = cmd[0] in ['push', 'pull']
+    sys.stderr = sys.stdout = DieselBuffer(flush=flush)
 
-    mercurial.dispatch.dispatch(['--cwd', cwd, '--color', 'always'] + cmd)
-
-    sys.stdout = sys.__stdout__
-    sys.stderr = sys.__stderr__
-
-    return out.getvalue()
+    try:
+        mercurial.dispatch.dispatch(['--cwd', cwd, '--color', 'always'] + cmd)
+    finally:
+        sys.stdout = sys.__stdout__
+        sys.stderr = sys.__stderr__
 
 def handle_command(remote_addr):
-    cwd = until('\n').strip()
-    cmd = until('HGDAEMONARGSDONE\n').strip().splitlines()[:-1]
+    cwd = until('\r\n').strip()
+    cmd = until('HGDAEMONARGSDONE\r\n').strip().splitlines()[:-1]
 
-    send(_run(cwd, cmd))
+    _run(cwd, cmd)
+
 
 app = Application()
 app.add_service(Service(handle_command, port=8029))
 app.run()
-
+import os
+import sys
+
+libdir = '@LIBDIR@'
+
+if libdir != '@' 'LIBDIR' '@':
+    if not os.path.isabs(libdir):
+        libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                              libdir)
+        libdir = os.path.abspath(libdir)
+    sys.path.insert(0, libdir)
+
+# enable importing on demand to reduce startup time
+try:
+    from mercurial import demandimport; demandimport.enable()
+except ImportError:
+    import sys
+    sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
+                     ' '.join(sys.path))
+    sys.stderr.write("(check your install and PYTHONPATH)\n")
+    sys.exit(-1)
+
+import mercurial.util
+import mercurial.dispatch
+from mercurial import commands
+
+for fp in (sys.stdin, sys.stdout, sys.stderr):
+    mercurial.util.set_binary(fp)
+
+
+# FIX MERCURIAL'S BROKEN ALIAS ADDING ---------------------------------------------
+
+def _patched_addaliases(ui, cmdtable):
+    # aliases are processed after extensions have been loaded, so they
+    # may use extension commands. Aliases can also use other alias definitions,
+    # but only if they have been defined prior to the current definition.
+    for alias, definition in ui.configitems('alias'):
+        aliasdef = mercurial.dispatch.cmdalias(alias, definition, cmdtable)
+        if not aliasdef.cmd in cmdtable:
+            cmdtable[aliasdef.cmd] = (aliasdef, aliasdef.opts, aliasdef.help)
+        if aliasdef.norepo:
+            commands.norepo += ' %s' % alias
+mercurial.dispatch.addaliases = _patched_addaliases
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.