diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -887,8 +887,13 @@ class cachedlocalrepo(object): return tuple(state), maxmtime def copy(self): - """Obtain a copy of this class instance.""" - c = cachedlocalrepo(self._repo) + """Obtain a copy of this class instance. + + A new localrepository instance is obtained. The new instance should be + completely independent of the original. + """ + repo = repository(self._repo.baseui, self._repo.origroot) + c = cachedlocalrepo(repo) c._state = self._state c.mtime = self.mtime return c 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 @@ -235,11 +235,11 @@ class hgweb(object): if self._repos: cached = self._repos.pop() r, created = cached.fetch() - if created: - r = self._webifyrepo(r) else: cached = self._lastrepo.copy() r, created = cached.fetch() + if created: + r = self._webifyrepo(r) self._lastrepo = cached self.mtime = cached.mtime