[PATCH] Better ctrl+c for hg serve on windows

Andrei Vermel avermel at mail.ru
Thu Jun 21 13:51:14 CDT 2007


Currently ctrl-c doesn't terminate 'hg serve' on windows immediately. Some time ago I stumbled across the patch below by mchaves. It 
works very well for me. I believe it's worth accepting it.

Andrei

# HG changeset patch
# User mchaves
# Date 1182448516 -14400
# Node ID ebb75a660cb7fdfc512beccd62955e911ea6638c
# Parent  68a51e1c007632ade7215e2c079dfc4663482ce6
Better ctrl+c for hg serve on windows

diff -r 68a51e1c0076 -r ebb75a660cb7 mercurial/commands.py
--- a/mercurial/commands.py  Thu Jun 21 21:55:15 2007 +0400
+++ b/mercurial/commands.py  Thu Jun 21 21:55:16 2007 +0400
@@ -2425,6 +2425,7 @@ def serve(ui, repo, **opts):

     class service:
         def init(self):
+            util.async_signal_handler()
             try:
                 self.httpd = hgweb.server.create_server(parentui, repo)
             except socket.error, inst:
diff -r 68a51e1c0076 -r ebb75a660cb7 mercurial/util.py
--- a/mercurial/util.py  Thu Jun 21 21:55:15 2007 +0400
+++ b/mercurial/util.py  Thu Jun 21 21:55:16 2007 +0400
@@ -1535,3 +1535,9 @@ def drop_scheme(scheme, path):
         if path.startswith('//'):
             path = path[2:]
     return path
+
+def async_signal_handler():
+    try:
+        async_signal_handler_win32()
+    except:
+        pass
diff -r 68a51e1c0076 -r ebb75a660cb7 mercurial/util_win32.py
--- a/mercurial/util_win32.py  Thu Jun 21 21:55:15 2007 +0400
+++ b/mercurial/util_win32.py  Thu Jun 21 21:55:16 2007 +0400
@@ -299,3 +299,10 @@ class posixfile_nt(object):
             raise WinIOError(err)

 getuser_fallback = win32api.GetUserName
+
+
+def win32_ctrl_handler(ctrlType):
+    win32process.ExitProcess(1)
+
+def async_signal_handler_win32():
+    win32api.SetConsoleCtrlHandler(win32_ctrl_handler)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ctrlc_serve.diff
Type: application/octet-stream
Size: 1544 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20070621/23d9a39f/attachment-0001.obj 


More information about the Mercurial-devel mailing list