[PATCH] serve: automatically include local subrepos

Mike Williams mrw at eandem.co.uk
Mon Feb 21 17:02:05 CST 2011


# HG changeset patch
# User Mike Williams <mrw at eandem.co.uk>
# Date 1298326556 0
# Branch stable
# Node ID 4efda2d5cec947ba63086fa64355bb7a14f39df2
# Parent  b3f9af7c22c5241be2eea24140cc6a3c834f9b59
serve: automatically include local subrepos

Mercurial wont locally serve subrepos without a web configuration file.  This
duplicates information already held in the .hgsub file.

This change checks for local subrepos when sharing a single repo.

diff -r b3f9af7c22c5 -r 4efda2d5cec9 mercurial/hgweb/__init__.py
--- a/mercurial/hgweb/__init__.py	Mon Feb 21 00:37:55 2011 +0100
+++ b/mercurial/hgweb/__init__.py	Mon Feb 21 22:15:56 2011 +0000
@@ -7,6 +7,7 @@
 # GNU General Public License version 2 or any later version.
 
 import os
+from mercurial import hg, repo, subrepo, localrepo
 import hgweb_mod, hgwebdir_mod
 
 def hgweb(config, name=None, baseui=None):
@@ -20,8 +21,27 @@
     - list of virtual:real tuples (multi-repo view)
     '''
 
-    if ((isinstance(config, str) and not os.path.isdir(config)) or
-        isinstance(config, dict) or isinstance(config, list)):
+    if isinstance(config, str) and os.path.isdir(config):
+        config = hg.repository(baseui, config)
+
+    if (isinstance(config, repo.repository) and
+        '.hgsub' in config.dirstate):
+        def srpaths(repo, ctx, ui, vpath):
+            paths = [(vpath, repo.root)]
+            if '.hgsub' in repo.dirstate:
+                for state in subrepo.state(ctx, ui).values():
+                    if state[2] != 'hg':
+                       continue
+                    sr = hg.repository(ui, repo.root + '/' + state[0])
+                    if isinstance(sr, localrepo.localrepository):
+                        paths.extend(srpaths(sr, sr[state[1]],
+                                             ui, vpath + '/' + state[0]))
+            return paths
+        config = srpaths(config, config[''], baseui,
+                         os.path.basename(config.root))
+
+    if (isinstance(config, str) or isinstance(config, dict) or
+        isinstance(config, list)):
         # create a multi-dir interface
         return hgwebdir_mod.hgwebdir(config, baseui=baseui)
     return hgweb_mod.hgweb(config, name=name, baseui=baseui)


More information about the Mercurial-devel mailing list