[PATCH 5 of 7] fsmonitor: avoid instantiation of dirstate in reposetup

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Jul 4 11:21:25 EDT 2017


At Tue, 4 Jul 2017 23:09:24 +0900,
Yuya Nishihara wrote:
> 
> On Mon, 03 Jul 2017 02:53:19 +0900, FUJIWARA Katsunori wrote:
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> > # Date 1499017960 -32400
> > #      Mon Jul 03 02:52:40 2017 +0900
> > # Node ID 9fd405b51136176f2498561bbd0a0c485a1f2eac
> > # Parent  ce3d2f9b19ec075671ba185bb77cde064c049b27
> > fsmonitor: avoid instantiation of dirstate in reposetup
> 
> > diff --git a/hgext/fsmonitor/__init__.py b/hgext/fsmonitor/__init__.py
> > --- a/hgext/fsmonitor/__init__.py
> > +++ b/hgext/fsmonitor/__init__.py
> > @@ -677,10 +677,8 @@ def reposetup(ui, repo):
> >                        'extension and has been disabled.\n') % ext)
> >              return
> >  
> > -    if util.safehasattr(repo, 'dirstate'):
> > -        # We don't work with subrepos either. Note that we can get passed in
> > -        # e.g. a statichttprepo, which throws on trying to access the substate.
> > -        # XXX This sucks.
> > +    if repo.local():
> > +        # We don't work with subrepos either.
> >          try:
> >              # if repo[None].substate can cause a dirstate parse, which is too
> >              # slow. Instead, look for a file called hgsubstate,
> 
> So this no longer "sucks", maybe there's no need to catch AttributeError?

Oops, you are right. I'll revise it in V2.

> > @@ -702,15 +700,17 @@ def reposetup(ui, repo):
> >          repo._fsmonitorstate = fsmonitorstate
> >          repo._watchmanclient = client
> >  
> > -        # at this point since fsmonitorstate wasn't present, repo.dirstate is
> > -        # not a fsmonitordirstate
> > -        dirstate = repo.dirstate
> > -        dirstate.__class__ = makedirstate(dirstate.__class__)
> > -        dirstate._fsmonitorinit(fsmonitorstate, client)
> > -        # invalidate property cache, but keep filecache which contains the
> > -        # wrapped dirstate object
> > -        del repo.unfiltered().__dict__['dirstate']
> > -        assert dirstate is repo._filecache['dirstate'].obj
> > +        # Completely discard dirstate, in order to ensure that
> > +        # dirstate is instantiated via wrapdirstate() after this
> > +        # reposetup(). Otherwise, walk(), rebuild() and invalidate()
> > +        # of repo.dirstate already instantiated at this point don't
> > +        # work as fsmonitordirstate, because it isn't makedirstate()-ed.
> > +        if 'dirstate' in repo._filecache:
> > +            del repo._filecache['dirstate']
> > +            try:
> > +                delattr(repo.unfiltered(), 'dirstate')
> > +            except AttributeError:
> > +                pass
> 
> Perhaps this disagree with bf3af0eced44. CC-ed Jun.

Oh, I overlooked that, sorry.

If chg prefills repo's dirstate filecache before reposetup(), it
causes issue with an extension, of which wrapper for repo.dirstate
works as expected only after own reposetup() (e.g. journal).

Should I fix journal extension as similarly as bf3af0eced44 ?

-- 
----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy at lares.dti.ne.jp


More information about the Mercurial-devel mailing list