[PATCH 2 of 2 V3] serve: make the URL the same for `hg serve` and `hg serve -S`

Matt Harbison mharbison72 at gmail.com
Sun Mar 26 23:04:31 EDT 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1488146777 18000
#      Sun Feb 26 17:06:17 2017 -0500
# Node ID d584ca4bc33bd2ebeaf9a7bd86440b3cdcecc138
# Parent  0ff9bef3e0f67422cf29c200fa4a671d861d060b
serve: make the URL the same for `hg serve` and `hg serve -S`

It's perfectly workable to serve up the parent repo without the -S for push and
pull, as long as there are no subrepo changes in play.  Therefore, having a
different URL for the main repo based on the presence of this option seems like
it would get annoying.

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -335,7 +335,7 @@
         req.url = req.env['SCRIPT_NAME']
         if not req.url.endswith('/'):
             req.url += '/'
-        if 'REPO_NAME' in req.env:
+        if req.env.get('REPO_NAME'):
             req.url += req.env['REPO_NAME'] + '/'
 
         if 'PATH_INFO' in req.env:
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -257,7 +257,7 @@
 
             repos = dict(self.repos)
 
-            if not virtual or (virtual == 'index' and virtual not in repos):
+            if (not virtual or virtual == 'index') and virtual not in repos:
                 req.respond(HTTP_OK, ctype)
                 return self.makeindex(req, tmpl)
 
@@ -269,8 +269,15 @@
                     req.respond(HTTP_OK, ctype)
                     return self.makeindex(req, tmpl, subdir)
 
-            virtualrepo = virtual
-            while virtualrepo:
+            def _virtualdirs():
+                yield virtual
+
+                for p in util.finddirs(virtual):
+                    yield p
+
+                yield ''
+
+            for virtualrepo in _virtualdirs():
                 real = repos.get(virtualrepo)
                 if real:
                     req.env['REPO_NAME'] = virtualrepo
@@ -284,11 +291,6 @@
                     except error.RepoError as inst:
                         raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
 
-                up = virtualrepo.rfind('/')
-                if up < 0:
-                    break
-                virtualrepo = virtualrepo[:up]
-
             # browse subdirectories
             subdir = virtual + '/'
             if [r for r in repos if r.startswith(subdir)]:
diff --git a/mercurial/server.py b/mercurial/server.py
--- a/mercurial/server.py
+++ b/mercurial/server.py
@@ -147,8 +147,7 @@
         # message as long as webconf is None.
         if repo:
             webconf = dict()
-            cmdutil.addwebdirpath(repo, repo.wvfs.basename(repo.root) + '/',
-                                  webconf)
+            cmdutil.addwebdirpath(repo, "", webconf)
     else:
         servui = ui
 
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -75,29 +75,29 @@
 
 #if serve
   $ hg serve -R main --debug -S -p $HGPORT -d --pid-file=hg1.pid -E error.log -A access.log
-  adding main/ = $TESTTMP/main (glob)
-  adding sub1/ = $TESTTMP/main/sub1 (glob)
-  adding sub2/ = $TESTTMP/main/sub1/sub2 (glob)
+  adding  = $TESTTMP/main (glob)
+  adding ../sub1/ = $TESTTMP/main/sub1 (glob)
+  adding ../sub2/ = $TESTTMP/main/sub1/sub2 (glob)
   listening at http://*:$HGPORT/ (bound to *:$HGPORT) (glob)
-  adding main/ = $TESTTMP/main (glob)
-  adding sub1/ = $TESTTMP/main/sub1 (glob)
-  adding sub2/ = $TESTTMP/main/sub1/sub2 (glob)
+  adding  = $TESTTMP/main (glob)
+  adding ../sub1/ = $TESTTMP/main/sub1 (glob)
+  adding ../sub2/ = $TESTTMP/main/sub1/sub2 (glob)
   $ cat hg1.pid >> $DAEMON_PIDS
 
-  $ hg clone http://localhost:$HGPORT/main httpclone --config progress.disable=True
+  $ hg clone http://localhost:$HGPORT httpclone --config progress.disable=True
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 3 changes to 3 files
   updating to branch default
-  cloning subrepo sub1 from http://localhost:$HGPORT/sub1
+  cloning subrepo sub1 from http://localhost:$HGPORT/../sub1
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 3 changes to 3 files
-  cloning subrepo sub1/sub2 from http://localhost:$HGPORT/sub2 (glob)
+  cloning subrepo sub1/sub2 from http://localhost:$HGPORT/../sub2 (glob)
   requesting all changes
   adding changesets
   adding manifests
@@ -106,15 +106,15 @@
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ cat access.log
-  * "GET /main?cmd=capabilities HTTP/1.1" 200 - (glob)
-  * "GET /main?cmd=batch HTTP/1.1" 200 - * (glob)
-  * "GET /main?cmd=getbundle HTTP/1.1" 200 - * (glob)
-  * "GET /sub1?cmd=capabilities HTTP/1.1" 200 - (glob)
-  * "GET /sub1?cmd=batch HTTP/1.1" 200 - * (glob)
-  * "GET /sub1?cmd=getbundle HTTP/1.1" 200 - * (glob)
-  * "GET /sub2?cmd=capabilities HTTP/1.1" 200 - (glob)
-  * "GET /sub2?cmd=batch HTTP/1.1" 200 - * (glob)
-  * "GET /sub2?cmd=getbundle HTTP/1.1" 200 - * (glob)
+  * "GET /?cmd=capabilities HTTP/1.1" 200 - (glob)
+  * "GET /?cmd=batch HTTP/1.1" 200 - * (glob)
+  * "GET /?cmd=getbundle HTTP/1.1" 200 - * (glob)
+  * "GET /../sub1?cmd=capabilities HTTP/1.1" 200 - (glob)
+  * "GET /../sub1?cmd=batch HTTP/1.1" 200 - * (glob)
+  * "GET /../sub1?cmd=getbundle HTTP/1.1" 200 - * (glob)
+  * "GET /../sub2?cmd=capabilities HTTP/1.1" 200 - (glob)
+  * "GET /../sub2?cmd=batch HTTP/1.1" 200 - * (glob)
+  * "GET /../sub2?cmd=getbundle HTTP/1.1" 200 - * (glob)
 
   $ killdaemons.py
   $ rm hg1.pid error.log access.log
diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t
--- a/tests/test-subrepo-recursion.t
+++ b/tests/test-subrepo-recursion.t
@@ -254,29 +254,29 @@
 #if serve
   $ cd ..
   $ hg serve -R repo --debug -S -p $HGPORT -d --pid-file=hg1.pid -E error.log -A access.log
-  adding repo/ = $TESTTMP/repo (glob)
-  adding repo/foo/ = $TESTTMP/repo/foo (glob)
-  adding repo/foo/bar/ = $TESTTMP/repo/foo/bar (glob)
+  adding  = $TESTTMP/repo (glob)
+  adding foo/ = $TESTTMP/repo/foo (glob)
+  adding foo/bar/ = $TESTTMP/repo/foo/bar (glob)
   listening at http://*:$HGPORT/ (bound to *:$HGPORT) (glob)
-  adding repo/ = $TESTTMP/repo (glob)
-  adding repo/foo/ = $TESTTMP/repo/foo (glob)
-  adding repo/foo/bar/ = $TESTTMP/repo/foo/bar (glob)
+  adding  = $TESTTMP/repo (glob)
+  adding foo/ = $TESTTMP/repo/foo (glob)
+  adding foo/bar/ = $TESTTMP/repo/foo/bar (glob)
   $ cat hg1.pid >> $DAEMON_PIDS
 
-  $ hg clone http://localhost:$HGPORT/repo clone  --config progress.disable=True
+  $ hg clone http://localhost:$HGPORT clone  --config progress.disable=True
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
   added 3 changesets with 5 changes to 3 files
   updating to branch default
-  cloning subrepo foo from http://localhost:$HGPORT/repo/foo
+  cloning subrepo foo from http://localhost:$HGPORT/foo
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
   added 4 changesets with 7 changes to 3 files
-  cloning subrepo foo/bar from http://localhost:$HGPORT/repo/foo/bar (glob)
+  cloning subrepo foo/bar from http://localhost:$HGPORT/foo/bar (glob)
   requesting all changes
   adding changesets
   adding manifests
@@ -290,15 +290,15 @@
   z3
 
   $ cat access.log
-  * "GET /repo?cmd=capabilities HTTP/1.1" 200 - (glob)
-  * "GET /repo?cmd=batch HTTP/1.1" 200 - * (glob)
-  * "GET /repo?cmd=getbundle HTTP/1.1" 200 - * (glob)
-  * "GET /repo/foo?cmd=capabilities HTTP/1.1" 200 - (glob)
-  * "GET /repo/foo?cmd=batch HTTP/1.1" 200 - * (glob)
-  * "GET /repo/foo?cmd=getbundle HTTP/1.1" 200 - * (glob)
-  * "GET /repo/foo/bar?cmd=capabilities HTTP/1.1" 200 - (glob)
-  * "GET /repo/foo/bar?cmd=batch HTTP/1.1" 200 - * (glob)
-  * "GET /repo/foo/bar?cmd=getbundle HTTP/1.1" 200 - * (glob)
+  * "GET /?cmd=capabilities HTTP/1.1" 200 - (glob)
+  * "GET /?cmd=batch HTTP/1.1" 200 - * (glob)
+  * "GET /?cmd=getbundle HTTP/1.1" 200 - * (glob)
+  * "GET /foo?cmd=capabilities HTTP/1.1" 200 - (glob)
+  * "GET /foo?cmd=batch HTTP/1.1" 200 - * (glob)
+  * "GET /foo?cmd=getbundle HTTP/1.1" 200 - * (glob)
+  * "GET /foo/bar?cmd=capabilities HTTP/1.1" 200 - (glob)
+  * "GET /foo/bar?cmd=batch HTTP/1.1" 200 - * (glob)
+  * "GET /foo/bar?cmd=getbundle HTTP/1.1" 200 - * (glob)
 
   $ killdaemons.py
   $ rm hg1.pid error.log access.log


More information about the Mercurial-devel mailing list