##// END OF EJS Templates
hgweb: internalize some socket details
Matt Mackall -
r3628:dc3504af default
parent child Browse files
Show More
@@ -11,7 +11,7 b' from i18n import gettext as _'
11 demandload(globals(), "os re sys signal shutil imp urllib pdb shlex")
11 demandload(globals(), "os re sys signal shutil imp urllib pdb shlex")
12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
13 demandload(globals(), "difflib patch tempfile time")
13 demandload(globals(), "difflib patch tempfile time")
14 demandload(globals(), "traceback errno socket version atexit sets bz2")
14 demandload(globals(), "traceback errno version atexit sets bz2")
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
16
16
17 class UnknownCommand(Exception):
17 class UnknownCommand(Exception):
@@ -2531,24 +2531,14 b' def serve(ui, repo, **opts):'
2531 os.read(rfd, 1)
2531 os.read(rfd, 1)
2532 os._exit(0)
2532 os._exit(0)
2533
2533
2534 try:
2534 httpd = hgweb.server.create_server(ui, repo)
2535 httpd = hgweb.server.create_server(ui, repo)
2536 except socket.error, inst:
2537 raise util.Abort(_('cannot start server: %s') % inst.args[1])
2538
2535
2539 if ui.verbose:
2536 if ui.verbose:
2540 addr, port = httpd.socket.getsockname()
2537 if httpd.port != 80:
2541 if addr == '0.0.0.0':
2538 ui.status(_('listening at http://%s:%d/\n') %
2542 addr = socket.gethostname()
2539 (httpd.addr, httpd.port))
2543 else:
2540 else:
2544 try:
2541 ui.status(_('listening at http://%s/\n') % httpd.addr)
2545 addr = socket.gethostbyaddr(addr)[0]
2546 except socket.error:
2547 pass
2548 if port != 80:
2549 ui.status(_('listening at http://%s:%d/\n') % (addr, port))
2550 else:
2551 ui.status(_('listening at http://%s/\n') % addr)
2552
2542
2553 if opts['pid_file']:
2543 if opts['pid_file']:
2554 fp = open(opts['pid_file'], 'w')
2544 fp = open(opts['pid_file'], 'w')
@@ -200,6 +200,16 b' def create_server(ui, repo):'
200 self.reqmaker = wsgiapplication(self.make_handler)
200 self.reqmaker = wsgiapplication(self.make_handler)
201 self.daemon_threads = True
201 self.daemon_threads = True
202
202
203 addr, port = self.socket.getsockname()
204 if addr == '0.0.0.0':
205 addr = socket.gethostname()
206 else:
207 try:
208 addr = socket.gethostbyaddr(addr)[0]
209 except socket.error:
210 pass
211 self.addr, self.port = addr, port
212
203 def make_handler(self):
213 def make_handler(self):
204 if self.webdir_conf:
214 if self.webdir_conf:
205 hgwebobj = self.webdirmaker(self.webdir_conf)
215 hgwebobj = self.webdirmaker(self.webdir_conf)
@@ -219,7 +229,10 b' def create_server(ui, repo):'
219 raise hg.RepoError(_('IPv6 not available on this system'))
229 raise hg.RepoError(_('IPv6 not available on this system'))
220 super(IPv6HTTPServer, self).__init__(*args, **kwargs)
230 super(IPv6HTTPServer, self).__init__(*args, **kwargs)
221
231
222 if use_ipv6:
232 try:
223 return IPv6HTTPServer((address, port), _hgwebhandler)
233 if use_ipv6:
224 else:
234 return IPv6HTTPServer((address, port), _hgwebhandler)
225 return MercurialHTTPServer((address, port), _hgwebhandler)
235 else:
236 return MercurialHTTPServer((address, port), _hgwebhandler)
237 except socket.error, inst:
238 raise util.Abort(_('cannot start server: %s') % inst.args[1])
General Comments 0
You need to be logged in to leave comments. Login now