##// END OF EJS Templates
fsmonitor: don't attempt state-leave if we didn't state-enter...
Wez Furlong -
r32335:35432917 default
parent child Browse files
Show More
@@ -601,6 +601,7 b' class state_update(object):'
601 self.distance = distance
601 self.distance = distance
602 self.partial = partial
602 self.partial = partial
603 self._lock = None
603 self._lock = None
604 self.need_leave = False
604
605
605 def __enter__(self):
606 def __enter__(self):
606 # We explicitly need to take a lock here, before we proceed to update
607 # We explicitly need to take a lock here, before we proceed to update
@@ -609,20 +610,21 b' class state_update(object):'
609 # immediately anyway, so this is effectively extending the lock
610 # immediately anyway, so this is effectively extending the lock
610 # around a couple of short sanity checks.
611 # around a couple of short sanity checks.
611 self._lock = self.repo.wlock()
612 self._lock = self.repo.wlock()
612 self._state('state-enter')
613 self.need_leave = self._state('state-enter')
613 return self
614 return self
614
615
615 def __exit__(self, type_, value, tb):
616 def __exit__(self, type_, value, tb):
616 try:
617 try:
617 status = 'ok' if type_ is None else 'failed'
618 if self.need_leave:
618 self._state('state-leave', status=status)
619 status = 'ok' if type_ is None else 'failed'
620 self._state('state-leave', status=status)
619 finally:
621 finally:
620 if self._lock:
622 if self._lock:
621 self._lock.release()
623 self._lock.release()
622
624
623 def _state(self, cmd, status='ok'):
625 def _state(self, cmd, status='ok'):
624 if not util.safehasattr(self.repo, '_watchmanclient'):
626 if not util.safehasattr(self.repo, '_watchmanclient'):
625 return
627 return False
626 try:
628 try:
627 commithash = self.repo[self.node].hex()
629 commithash = self.repo[self.node].hex()
628 self.repo._watchmanclient.command(cmd, {
630 self.repo._watchmanclient.command(cmd, {
@@ -637,10 +639,12 b' class state_update(object):'
637 # whether the working copy parent is changing
639 # whether the working copy parent is changing
638 'partial': self.partial,
640 'partial': self.partial,
639 }})
641 }})
642 return True
640 except Exception as e:
643 except Exception as e:
641 # Swallow any errors; fire and forget
644 # Swallow any errors; fire and forget
642 self.repo.ui.log(
645 self.repo.ui.log(
643 'watchman', 'Exception %s while running %s\n', e, cmd)
646 'watchman', 'Exception %s while running %s\n', e, cmd)
647 return False
644
648
645 # Bracket working copy updates with calls to the watchman state-enter
649 # Bracket working copy updates with calls to the watchman state-enter
646 # and state-leave commands. This allows clients to perform more intelligent
650 # and state-leave commands. This allows clients to perform more intelligent
General Comments 0
You need to be logged in to leave comments. Login now