# HG changeset patch # User Samuel Tardieu # Date 1123190487 28800 # Node ID 0108c602feb9dacc00b66647b8871bd9ee991b92 # Parent 0932bc2fb2bea21c935f92388a661b0087dd19f7 Add an option to hg serve to serve file using IPv6 diff -r 0932bc2fb2be -r 0108c602feb9 doc/hg.1.txt --- a/doc/hg.1.txt Tue Aug 02 08:57:32 2005 -0800 +++ b/doc/hg.1.txt Thu Aug 04 13:21:27 2005 -0800 @@ -330,6 +330,7 @@ -p, --port port to use (default: 8000) -n, --name name to show in web pages (default: working dir) -t, --templatedir web templates to use + -6, --ipv6 use IPv6 in addition to IPv4 status [options] [files]:: Show changed files in the working directory. If no names are diff -r 0932bc2fb2be -r 0108c602feb9 mercurial/commands.py --- a/mercurial/commands.py Tue Aug 02 08:57:32 2005 -0800 +++ b/mercurial/commands.py Thu Aug 04 13:21:27 2005 -0800 @@ -1002,7 +1002,7 @@ return default httpd = hgweb.create_server(repo.root, opts["name"], opts["templates"], - opts["address"], opts["port"], + opts["address"], opts["port"], opts["ipv6"], openlog('accesslog', sys.stdout), openlog('errorlog', sys.stderr)) if ui.verbose: @@ -1251,7 +1251,8 @@ ('a', 'address', '', 'interface address'), ('n', 'name', os.getcwd(), 'repository name'), ('', 'stdio', None, 'for remote clients'), - ('t', 'templates', "", 'template map')], + ('t', 'templates', "", 'template map'), + ('6', 'ipv6', None, 'use IPv6 in addition to IPv4')], "hg serve [OPTION]..."), "^status": (status, [('I', 'include', [], 'include path in search'), diff -r 0932bc2fb2be -r 0108c602feb9 mercurial/hgweb.py --- a/mercurial/hgweb.py Tue Aug 02 08:57:32 2005 -0800 +++ b/mercurial/hgweb.py Thu Aug 04 13:21:27 2005 -0800 @@ -6,7 +6,7 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os, cgi, time, re, difflib, sys, zlib +import os, cgi, time, re, difflib, socket, sys, zlib from mercurial.hg import * from mercurial.ui import * @@ -699,11 +699,14 @@ else: write(self.t("error")) -def create_server(path, name, templates, address, port, +def create_server(path, name, templates, address, port, use_ipv6 = False, accesslog = sys.stdout, errorlog = sys.stderr): import BaseHTTPServer + class IPv6HTTPServer(BaseHTTPServer.HTTPServer): + address_family = socket.AF_INET6 + class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): def log_error(self, format, *args): errorlog.write("%s - - [%s] %s\n" % (self.address_string(), @@ -774,10 +777,13 @@ sys.argv, sys.stdin, sys.stdout, sys.stderr = save hg = hgweb(path, name, templates) - return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) + if use_ipv6: + return IPv6HTTPServer((address, port), hgwebhandler) + else: + return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) -def server(path, name, templates, address, port, +def server(path, name, templates, address, port, use_ipv6 = False, accesslog = sys.stdout, errorlog = sys.stderr): - httpd = create_server(path, name, templates, address, port, + httpd = create_server(path, name, templates, address, port, use_ipv6, accesslog, errorlog) httpd.serve_forever()