comparison hgext/fsmonitor/__init__.py @ 33386:5a9b4370bb3b

fsmonitor: centralize setup procedures for dirstate
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Mon, 10 Jul 2017 23:09:52 +0900
parents 8bb4c69c4000
children 68e9762a357b
comparison
equal deleted inserted replaced
33385:8bb4c69c4000 33386:5a9b4370bb3b
534 hashignore = _hashignore(wctx.repo().dirstate._ignore) 534 hashignore = _hashignore(wctx.repo().dirstate._ignore)
535 notefiles = (status.modified + status.added + status.removed + 535 notefiles = (status.modified + status.added + status.removed +
536 status.deleted + status.unknown) 536 status.deleted + status.unknown)
537 wctx.repo()._fsmonitorstate.set(clock, hashignore, notefiles) 537 wctx.repo()._fsmonitorstate.set(clock, hashignore, notefiles)
538 538
539 def makedirstate(cls): 539 def makedirstate(repo, dirstate):
540 class fsmonitordirstate(cls): 540 class fsmonitordirstate(dirstate.__class__):
541 def _fsmonitorinit(self, fsmonitorstate, watchmanclient): 541 def _fsmonitorinit(self, fsmonitorstate, watchmanclient):
542 # _fsmonitordisable is used in paranoid mode 542 # _fsmonitordisable is used in paranoid mode
543 self._fsmonitordisable = False 543 self._fsmonitordisable = False
544 self._fsmonitorstate = fsmonitorstate 544 self._fsmonitorstate = fsmonitorstate
545 self._watchmanclient = watchmanclient 545 self._watchmanclient = watchmanclient
556 556
557 def invalidate(self, *args, **kwargs): 557 def invalidate(self, *args, **kwargs):
558 self._fsmonitorstate.invalidate() 558 self._fsmonitorstate.invalidate()
559 return super(fsmonitordirstate, self).invalidate(*args, **kwargs) 559 return super(fsmonitordirstate, self).invalidate(*args, **kwargs)
560 560
561 return fsmonitordirstate 561 dirstate.__class__ = fsmonitordirstate
562 dirstate._fsmonitorinit(repo._fsmonitorstate, repo._watchmanclient)
562 563
563 def wrapdirstate(orig, self): 564 def wrapdirstate(orig, self):
564 ds = orig(self) 565 ds = orig(self)
565 # only override the dirstate when Watchman is available for the repo 566 # only override the dirstate when Watchman is available for the repo
566 if util.safehasattr(self, '_fsmonitorstate'): 567 if util.safehasattr(self, '_fsmonitorstate'):
567 ds.__class__ = makedirstate(ds.__class__) 568 makedirstate(self, ds)
568 ds._fsmonitorinit(self._fsmonitorstate, self._watchmanclient)
569 return ds 569 return ds
570 570
571 def extsetup(ui): 571 def extsetup(ui):
572 extensions.wrapfilecache( 572 extensions.wrapfilecache(
573 localrepo.localrepository, 'dirstate', wrapdirstate) 573 localrepo.localrepository, 'dirstate', wrapdirstate)
699 repo._watchmanclient = client 699 repo._watchmanclient = client
700 700
701 # at this point since fsmonitorstate wasn't present, repo.dirstate is 701 # at this point since fsmonitorstate wasn't present, repo.dirstate is
702 # not a fsmonitordirstate 702 # not a fsmonitordirstate
703 dirstate = repo.dirstate 703 dirstate = repo.dirstate
704 dirstate.__class__ = makedirstate(dirstate.__class__) 704 makedirstate(repo, dirstate)
705 dirstate._fsmonitorinit(fsmonitorstate, client) 705
706 # invalidate property cache, but keep filecache which contains the 706 # invalidate property cache, but keep filecache which contains the
707 # wrapped dirstate object 707 # wrapped dirstate object
708 del repo.unfiltered().__dict__['dirstate'] 708 del repo.unfiltered().__dict__['dirstate']
709 assert dirstate is repo._filecache['dirstate'].obj 709 assert dirstate is repo._filecache['dirstate'].obj
710 710