mercurial/sparse.py
changeset 33318 526255fe7899
parent 33317 df1287268cc0
child 33320 153456f02426
equal deleted inserted replaced
33317:df1287268cc0 33318:526255fe7899
   130     return profiles
   130     return profiles
   131 
   131 
   132 def invalidatesignaturecache(repo):
   132 def invalidatesignaturecache(repo):
   133     repo._sparsesignaturecache.clear()
   133     repo._sparsesignaturecache.clear()
   134 
   134 
   135 def _checksum(repo, path):
       
   136     data = repo.vfs.read(path)
       
   137     return hashlib.sha1(data).hexdigest()
       
   138 
       
   139 def configsignature(repo, includetemp=True):
   135 def configsignature(repo, includetemp=True):
   140     """Obtain the signature string for the current sparse configuration.
   136     """Obtain the signature string for the current sparse configuration.
   141 
   137 
   142     This is used to construct a cache key for matchers.
   138     This is used to construct a cache key for matchers.
   143     """
   139     """
   146     signature = cache.get('signature')
   142     signature = cache.get('signature')
   147 
   143 
   148     if includetemp:
   144     if includetemp:
   149         tempsignature = cache.get('tempsignature')
   145         tempsignature = cache.get('tempsignature')
   150     else:
   146     else:
   151         tempsignature = 0
   147         tempsignature = '0'
   152 
   148 
   153     if signature is None or (includetemp and tempsignature is None):
   149     if signature is None or (includetemp and tempsignature is None):
   154         signature = 0
   150         signature = hashlib.sha1(repo.vfs.tryread('sparse')).hexdigest()
   155         try:
       
   156             signature = _checksum(repo, 'sparse')
       
   157         except (OSError, IOError):
       
   158             pass
       
   159         cache['signature'] = signature
   151         cache['signature'] = signature
   160 
   152 
   161         tempsignature = 0
       
   162         if includetemp:
   153         if includetemp:
   163             try:
   154             raw = repo.vfs.tryread('tempsparse')
   164                 tempsignature = _checksum(repo, 'tempsparse')
   155             tempsignature = hashlib.sha1(raw).hexdigest()
   165             except (OSError, IOError):
       
   166                 pass
       
   167             cache['tempsignature'] = tempsignature
   156             cache['tempsignature'] = tempsignature
   168 
   157 
   169     return '%s %s' % (str(signature), str(tempsignature))
   158     return '%s %s' % (signature, tempsignature)
   170 
   159 
   171 def writeconfig(repo, includes, excludes, profiles):
   160 def writeconfig(repo, includes, excludes, profiles):
   172     """Write the sparse config file given a sparse configuration."""
   161     """Write the sparse config file given a sparse configuration."""
   173     with repo.vfs('sparse', 'wb') as fh:
   162     with repo.vfs('sparse', 'wb') as fh:
   174         for p in sorted(profiles):
   163         for p in sorted(profiles):