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
@@ -61,6 +61,7 @@ class hgweb(object):
                 u = ui.ui()
             r = hg.repository(u, repo)
         else:
+            # we trust caller to give us a private copy
             r = repo
 
         r = self._getview(r)
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
@@ -214,7 +214,8 @@ class hgwebdir(object):
                     if real:
                         req.env['REPO_NAME'] = virtualrepo
                         try:
-                            repo = hg.repository(self.ui, real)
+                            # ensure caller gets private copy of ui
+                            repo = hg.repository(self.ui.copy(), real)
                             return hgweb(repo).run_wsgi(req)
                         except IOError, inst:
                             msg = inst.strerror