# HG changeset patch # User Gregory Szorc # Date 2015-09-12 18:31:56 # Node ID 2b1434e5eaa05752f8773f354a1a2db6a0f5f427 # Parent f39953663cc9f4a9cfc82d627256ee90fa657815 hg: always create new localrepository instance cachedlocalrepo.copy() didn't actually create new localrepository instances. This meant that the new thread isolation code in hgweb wasn't actually using separate localrepository instances, even though it was properly using separate cachedlocalrepo instances. Because the behavior of the API changed, the single caller in hgweb had to be refactored to always call _webifyrepo() or it may not have used the proper filter. I confirmed via print() debugging that id(repo) is in fact different on each thread. This was not the case before. For reasons I can't yet explain, this does not fix issue4756. I suspect there is shared cache somewhere that isn't thread safe. 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