598 def __init__(self, repo, node, distance, partial): |
598 def __init__(self, repo, node, distance, partial): |
599 self.repo = repo |
599 self.repo = repo |
600 self.node = node |
600 self.node = node |
601 self.distance = distance |
601 self.distance = distance |
602 self.partial = partial |
602 self.partial = partial |
|
603 self._lock = None |
603 |
604 |
604 def __enter__(self): |
605 def __enter__(self): |
|
606 # We explicitly need to take a lock here, before we proceed to update |
|
607 # watchman about the update operation, so that we don't race with |
|
608 # some other actor. merge.update is going to take the wlock almost |
|
609 # immediately anyway, so this is effectively extending the lock |
|
610 # around a couple of short sanity checks. |
|
611 self._lock = self.repo.wlock() |
605 self._state('state-enter') |
612 self._state('state-enter') |
606 return self |
613 return self |
607 |
614 |
608 def __exit__(self, type_, value, tb): |
615 def __exit__(self, type_, value, tb): |
609 status = 'ok' if type_ is None else 'failed' |
616 try: |
610 self._state('state-leave', status=status) |
617 status = 'ok' if type_ is None else 'failed' |
|
618 self._state('state-leave', status=status) |
|
619 finally: |
|
620 if self._lock: |
|
621 self._lock.release() |
611 |
622 |
612 def _state(self, cmd, status='ok'): |
623 def _state(self, cmd, status='ok'): |
613 if not util.safehasattr(self.repo, '_watchmanclient'): |
624 if not util.safehasattr(self.repo, '_watchmanclient'): |
614 return |
625 return |
615 try: |
626 try: |