hgext/fsmonitor/__init__.py
changeset 30666 6ada1658fc6b
parent 30332 318a24b52eeb
child 31846 1064a296a2a7
equal deleted inserted replaced
30665:01721d382c16 30666:6ada1658fc6b
    92 from __future__ import absolute_import
    92 from __future__ import absolute_import
    93 
    93 
    94 import hashlib
    94 import hashlib
    95 import os
    95 import os
    96 import stat
    96 import stat
    97 import sys
       
    98 
    97 
    99 from mercurial.i18n import _
    98 from mercurial.i18n import _
   100 from mercurial import (
    99 from mercurial import (
   101     context,
   100     context,
       
   101     encoding,
   102     extensions,
   102     extensions,
   103     localrepo,
   103     localrepo,
   104     merge,
   104     merge,
   105     pathutil,
   105     pathutil,
       
   106     pycompat,
   106     scmutil,
   107     scmutil,
   107     util,
   108     util,
   108 )
   109 )
   109 from mercurial import match as matchmod
   110 from mercurial import match as matchmod
   110 
   111 
   290     # for file paths which require normalization and we encounter a case
   291     # for file paths which require normalization and we encounter a case
   291     # collision, we store our own foldmap
   292     # collision, we store our own foldmap
   292     if normalize:
   293     if normalize:
   293         foldmap = dict((normcase(k), k) for k in results)
   294         foldmap = dict((normcase(k), k) for k in results)
   294 
   295 
   295     switch_slashes = os.sep == '\\'
   296     switch_slashes = pycompat.ossep == '\\'
   296     # The order of the results is, strictly speaking, undefined.
   297     # The order of the results is, strictly speaking, undefined.
   297     # For case changes on a case insensitive filesystem we may receive
   298     # For case changes on a case insensitive filesystem we may receive
   298     # two entries, one with exists=True and another with exists=False.
   299     # two entries, one with exists=True and another with exists=False.
   299     # The exists=True entries in the same response should be interpreted
   300     # The exists=True entries in the same response should be interpreted
   300     # as being happens-after the exists=False entries due to the way that
   301     # as being happens-after the exists=False entries due to the way that
   390     listclean = clean
   391     listclean = clean
   391     listunknown = unknown
   392     listunknown = unknown
   392 
   393 
   393     def _cmpsets(l1, l2):
   394     def _cmpsets(l1, l2):
   394         try:
   395         try:
   395             if 'FSMONITOR_LOG_FILE' in os.environ:
   396             if 'FSMONITOR_LOG_FILE' in encoding.environ:
   396                 fn = os.environ['FSMONITOR_LOG_FILE']
   397                 fn = encoding.environ['FSMONITOR_LOG_FILE']
   397                 f = open(fn, 'wb')
   398                 f = open(fn, 'wb')
   398             else:
   399             else:
   399                 fn = 'fsmonitorfail.log'
   400                 fn = 'fsmonitorfail.log'
   400                 f = self.opener(fn, 'wb')
   401                 f = self.opener(fn, 'wb')
   401         except (IOError, OSError):
   402         except (IOError, OSError):
   432     # in the middle of a transaction; we must not update our state in that
   433     # in the middle of a transaction; we must not update our state in that
   433     # case, or we risk forgetting about changes in the working copy.
   434     # case, or we risk forgetting about changes in the working copy.
   434     updatestate = (parentworking and match.always() and
   435     updatestate = (parentworking and match.always() and
   435                    not isinstance(ctx2, (context.workingcommitctx,
   436                    not isinstance(ctx2, (context.workingcommitctx,
   436                                          context.memctx)) and
   437                                          context.memctx)) and
   437                    'HG_PENDING' not in os.environ)
   438                    'HG_PENDING' not in encoding.environ)
   438 
   439 
   439     try:
   440     try:
   440         if self._fsmonitorstate.walk_on_invalidate:
   441         if self._fsmonitorstate.walk_on_invalidate:
   441             # Use a short timeout to query the current clock.  If that
   442             # Use a short timeout to query the current clock.  If that
   442             # takes too long then we assume that the service will be slow
   443             # takes too long then we assume that the service will be slow
   543         ds._fsmonitorinit(self._fsmonitorstate, self._watchmanclient)
   544         ds._fsmonitorinit(self._fsmonitorstate, self._watchmanclient)
   544     return ds
   545     return ds
   545 
   546 
   546 def extsetup(ui):
   547 def extsetup(ui):
   547     wrapfilecache(localrepo.localrepository, 'dirstate', wrapdirstate)
   548     wrapfilecache(localrepo.localrepository, 'dirstate', wrapdirstate)
   548     if sys.platform == 'darwin':
   549     if pycompat.sysplatform == 'darwin':
   549         # An assist for avoiding the dangling-symlink fsevents bug
   550         # An assist for avoiding the dangling-symlink fsevents bug
   550         extensions.wrapfunction(os, 'symlink', wrapsymlink)
   551         extensions.wrapfunction(os, 'symlink', wrapsymlink)
   551 
   552 
   552     extensions.wrapfunction(merge, 'update', wrapupdate)
   553     extensions.wrapfunction(merge, 'update', wrapupdate)
   553 
   554