##// END OF EJS Templates
serve: allow --port=0 to specify "server chooses the port number"
Bryan O'Sullivan -
r10629:d3f27d15 default
parent child Browse files
Show More
@@ -2868,6 +2868,10 b' def serve(ui, repo, **opts):'
2868 By default, the server logs accesses to stdout and errors to
2868 By default, the server logs accesses to stdout and errors to
2869 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
2869 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
2870 files.
2870 files.
2871
2872 To have the server choose a free port number to listen on, specify
2873 a port number of 0; in this case, the server will print the port
2874 number it uses.
2871 """
2875 """
2872
2876
2873 if opts["stdio"]:
2877 if opts["stdio"]:
@@ -2881,10 +2885,13 b' def serve(ui, repo, **opts):'
2881 optlist = ("name templates style address port prefix ipv6"
2885 optlist = ("name templates style address port prefix ipv6"
2882 " accesslog errorlog webdir_conf certificate encoding")
2886 " accesslog errorlog webdir_conf certificate encoding")
2883 for o in optlist.split():
2887 for o in optlist.split():
2884 if opts.get(o, None):
2888 try: val = opts[o]
2885 baseui.setconfig("web", o, str(opts[o]))
2889 except KeyError: continue
2886 if (repo is not None) and (repo.ui != baseui):
2890 else:
2887 repo.ui.setconfig("web", o, str(opts[o]))
2891 if val == '': continue
2892 baseui.setconfig("web", o, val)
2893 if repo and repo.ui != baseui:
2894 repo.ui.setconfig("web", o, val)
2888
2895
2889 if repo is None and not ui.config("web", "webdir_conf"):
2896 if repo is None and not ui.config("web", "webdir_conf"):
2890 raise error.RepoError(_("There is no Mercurial repository here"
2897 raise error.RepoError(_("There is no Mercurial repository here"
@@ -2895,7 +2902,7 b' def serve(ui, repo, **opts):'
2895 util.set_signal_handler()
2902 util.set_signal_handler()
2896 self.httpd = server.create_server(baseui, repo)
2903 self.httpd = server.create_server(baseui, repo)
2897
2904
2898 if not ui.verbose:
2905 if opts['port'] and not ui.verbose:
2899 return
2906 return
2900
2907
2901 if self.httpd.prefix:
2908 if self.httpd.prefix:
@@ -2916,8 +2923,12 b' def serve(ui, repo, **opts):'
2916 fqaddr = self.httpd.fqaddr
2923 fqaddr = self.httpd.fqaddr
2917 if ':' in fqaddr:
2924 if ':' in fqaddr:
2918 fqaddr = '[%s]' % fqaddr
2925 fqaddr = '[%s]' % fqaddr
2919 ui.status(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
2926 if opts['port']:
2920 (fqaddr, port, prefix, bindaddr, self.httpd.port))
2927 write = ui.status
2928 else:
2929 write = ui.write
2930 write(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
2931 (fqaddr, port, prefix, bindaddr, self.httpd.port))
2921
2932
2922 def run(self):
2933 def run(self):
2923 self.httpd.serve_forever()
2934 self.httpd.serve_forever()
@@ -3771,7 +3782,7 b' table = {'
3771 ('d', 'daemon', None, _('run server in background')),
3782 ('d', 'daemon', None, _('run server in background')),
3772 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
3783 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
3773 ('E', 'errorlog', '', _('name of error log file to write to')),
3784 ('E', 'errorlog', '', _('name of error log file to write to')),
3774 ('p', 'port', 0, _('port to listen on (default: 8000)')),
3785 ('p', 'port', 8000, _('port to listen on (default: 8000)')),
3775 ('a', 'address', '',
3786 ('a', 'address', '',
3776 _('address to listen on (default: all interfaces)')),
3787 _('address to listen on (default: all interfaces)')),
3777 ('', 'prefix', '',
3788 ('', 'prefix', '',
General Comments 0
You need to be logged in to leave comments. Login now