Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 10629:d3f27d15c9cb
serve: allow --port=0 to specify "server chooses the port number"
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Wed, 10 Mar 2010 10:51:37 -0800 |
parents | da7662ea741f |
children | 9947e6b008bb |
comparison
equal
deleted
inserted
replaced
10628:6227c8d669d5 | 10629:d3f27d15c9cb |
---|---|
2866 Start a local HTTP repository browser and pull server. | 2866 Start a local HTTP repository browser and pull server. |
2867 | 2867 |
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"]: |
2874 if repo is None: | 2878 if repo is None: |
2875 raise error.RepoError(_("There is no Mercurial repository here" | 2879 raise error.RepoError(_("There is no Mercurial repository here" |
2879 | 2883 |
2880 baseui = repo and repo.baseui or ui | 2884 baseui = repo and repo.baseui or ui |
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" |
2891 " (.hg not found)")) | 2898 " (.hg not found)")) |
2892 | 2899 |
2893 class service(object): | 2900 class service(object): |
2894 def init(self): | 2901 def init(self): |
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: |
2902 prefix = self.httpd.prefix.strip('/') + '/' | 2909 prefix = self.httpd.prefix.strip('/') + '/' |
2903 else: | 2910 else: |
2914 bindaddr = '[%s]' % bindaddr | 2921 bindaddr = '[%s]' % bindaddr |
2915 | 2922 |
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() |
2924 | 2935 |
2925 service = service() | 2936 service = service() |
3769 (serve, | 3780 (serve, |
3770 [('A', 'accesslog', '', _('name of access log file to write to')), | 3781 [('A', 'accesslog', '', _('name of access log file to write to')), |
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', '', |
3778 _('prefix path to serve from (default: server root)')), | 3789 _('prefix path to serve from (default: server root)')), |
3779 ('n', 'name', '', | 3790 ('n', 'name', '', |