[PATCH] hg: always create new localrepository instance
Augie Fackler
raf at durin42.com
Sun Sep 13 21:36:16 CDT 2015
On Sat, Sep 12, 2015 at 11:33:54AM -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1442082716 25200
> # Sat Sep 12 11:31:56 2015 -0700
> # Node ID ca4473ede18b892c9b15779829461735a3be8c49
> # Parent efebefe162e98aa79438daaea9aaee47c7de33bb
> hg: always create new localrepository instance
queued, many thanks for tackling this refactoring
>
> 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
> @@ -886,9 +886,14 @@ 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
> @@ -234,13 +234,13 @@ 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
> try:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list