[PATCH] fixed problem with prefix options missing a leading forward slash

Michele Cella michele.cella at gmail.com
Sun Jan 13 23:47:59 UTC 2008


# HG changeset patch
# User Michele Cella <michele.cella at gmail.com>
# Date 1200268041 -3600
# Node ID 696e020d6893ab5907e7bcb0e054dd9abe64d21d
# Parent  02884e56c2177af3d79db8eb21a345cc3ac368e9
fixed problem with prefix options missing a leading forward slash
show the prefix path when running with verbose output
added proper tests to test-serve
added prefix documentation to the hgrc man page

diff -r 02884e56c217 -r 696e020d6893 doc/hgrc.5.txt
--- a/doc/hgrc.5.txt	Wed Jan 09 22:41:30 2008 +0900
+++ b/doc/hgrc.5.txt	Mon Jan 14 00:47:21 2008 +0100
@@ -553,6 +553,8 @@ web::
     Maximum number of files to list per changeset. Default is 10.
   port;;
     Port to listen on. Default is 8000.
+  prefix;;
+    Prefix path to serve from. Default is '' (server root).
   push_ssl;;
     Whether to require that inbound pushes be transported over SSL to
     prevent password sniffing.  Default is true.
diff -r 02884e56c217 -r 696e020d6893 mercurial/commands.py
--- a/mercurial/commands.py	Wed Jan 09 22:41:30 2008 +0900
+++ b/mercurial/commands.py	Mon Jan 14 00:47:21 2008 +0100
@@ -2415,11 +2415,17 @@ def serve(ui, repo, **opts):
 
             if not ui.verbose: return
 
+            if self.httpd.prefix:
+                prefix = self.httpd.prefix.strip('/') + '/'
+            else:
+                prefix = ''
+
             if self.httpd.port != 80:
-                ui.status(_('listening at http://%s:%d/\n') %
-                          (self.httpd.addr, self.httpd.port))
+                ui.status(_('listening at http://%s:%d/%s\n') %
+                          (self.httpd.addr, self.httpd.port, prefix))
             else:
-                ui.status(_('listening at http://%s/\n') % self.httpd.addr)
+                ui.status(_('listening at http://%s/%s\n') % 
+                          (self.httpd.addr, prefix))
 
         def run(self):
             self.httpd.serve_forever()
diff -r 02884e56c217 -r 696e020d6893 mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py	Wed Jan 09 22:41:30 2008 +0900
+++ b/mercurial/hgweb/server.py	Mon Jan 14 00:47:21 2008 +0100
@@ -206,7 +206,9 @@ def create_server(ui, repo):
         myui = repo.ui
     address = myui.config("web", "address", "")
     port = int(myui.config("web", "port", 8000))
-    prefix = myui.config("web", "prefix", "").rstrip("/")
+    prefix = myui.config("web", "prefix", "")
+    if prefix:
+        prefix = "/" + prefix.strip("/")
     use_ipv6 = myui.configbool("web", "ipv6")
     webdir_conf = myui.config("web", "webdir_conf")
     ssl_cert = myui.config("web", "certificate")
diff -r 02884e56c217 -r 696e020d6893 tests/run-tests.py
--- a/tests/run-tests.py	Wed Jan 09 22:41:30 2008 +0900
+++ b/tests/run-tests.py	Mon Jan 14 00:47:21 2008 +0100
@@ -429,6 +429,9 @@ os.environ["HGPORT"] = str(options.port)
 os.environ["HGPORT"] = str(options.port)
 os.environ["HGPORT1"] = str(options.port + 1)
 os.environ["HGPORT2"] = str(options.port + 2)
+os.environ["HGPORT3"] = str(options.port + 3)
+os.environ["HGPORT4"] = str(options.port + 4)
+os.environ["HGPORT5"] = str(options.port + 5)
 
 if options.with_hg:
     INST = options.with_hg
diff -r 02884e56c217 -r 696e020d6893 tests/test-serve
--- a/tests/test-serve	Wed Jan 09 22:41:30 2008 +0900
+++ b/tests/test-serve	Mon Jan 14 00:47:21 2008 +0100
@@ -16,3 +16,19 @@ echo % With -v
 echo % With -v
 hg serve -a localhost -p $HGPORT1 -d --pid-file=hg.pid -v | sed -e 's,:[0-9][0-9]*/,/,'
 cat hg.pid >> "$DAEMON_PIDS"
+
+echo % With --prefix foo
+hg serve -a localhost -p $HGPORT2 -d --pid-file=hg.pid -v --prefix foo | sed -e 's,:[0-9][0-9]*/,/,'
+cat hg.pid >> "$DAEMON_PIDS"
+
+echo % With --prefix /foo
+hg serve -a localhost -p $HGPORT3 -d --pid-file=hg.pid -v --prefix /foo | sed -e 's,:[0-9][0-9]*/,/,'
+cat hg.pid >> "$DAEMON_PIDS"
+
+echo % With --prefix foo/
+hg serve -a localhost -p $HGPORT4 -d --pid-file=hg.pid -v --prefix foo/ | sed -e 's,:[0-9][0-9]*/,/,'
+cat hg.pid >> "$DAEMON_PIDS"
+
+echo % With --prefix /foo/
+hg serve -a localhost -p $HGPORT5 -d --pid-file=hg.pid -v --prefix /foo/ | sed -e 's,:[0-9][0-9]*/,/,'
+cat hg.pid >> "$DAEMON_PIDS"
diff -r 02884e56c217 -r 696e020d6893 tests/test-serve.out
--- a/tests/test-serve.out	Wed Jan 09 22:41:30 2008 +0900
+++ b/tests/test-serve.out	Mon Jan 14 00:47:21 2008 +0100
@@ -2,3 +2,11 @@ access log created - .hg/hgrc respected
 access log created - .hg/hgrc respected
 % With -v
 listening at http://localhost/
+% With --prefix foo
+listening at http://localhost/foo/
+% With --prefix /foo
+listening at http://localhost/foo/
+% With --prefix foo/
+listening at http://localhost/foo/
+% With --prefix /foo/
+listening at http://localhost/foo/



More information about the Mercurial-devel mailing list