##// END OF EJS Templates
sparse: move config signature logic into core...
Gregory Szorc -
r33317:df128726 default
parent child Browse files
Show More
@@ -75,7 +75,6 b' certain files::'
75 from __future__ import absolute_import
75 from __future__ import absolute_import
76
76
77 import collections
77 import collections
78 import hashlib
79 import os
78 import os
80
79
81 from mercurial.i18n import _
80 from mercurial.i18n import _
@@ -405,38 +404,6 b' def _setupdirstate(ui):'
405
404
406 def _wraprepo(ui, repo):
405 def _wraprepo(ui, repo):
407 class SparseRepo(repo.__class__):
406 class SparseRepo(repo.__class__):
408 def _sparsechecksum(self, path):
409 data = self.vfs.read(path)
410 return hashlib.sha1(data).hexdigest()
411
412 def _sparsesignature(self, includetemp=True):
413 """Returns the signature string representing the contents of the
414 current project sparse configuration. This can be used to cache the
415 sparse matcher for a given set of revs."""
416 signaturecache = self._sparsesignaturecache
417 signature = signaturecache.get('signature')
418 if includetemp:
419 tempsignature = signaturecache.get('tempsignature')
420 else:
421 tempsignature = 0
422
423 if signature is None or (includetemp and tempsignature is None):
424 signature = 0
425 try:
426 signature = self._sparsechecksum('sparse')
427 except (OSError, IOError):
428 pass
429 signaturecache['signature'] = signature
430
431 tempsignature = 0
432 if includetemp:
433 try:
434 tempsignature = self._sparsechecksum('tempsparse')
435 except (OSError, IOError):
436 pass
437 signaturecache['tempsignature'] = tempsignature
438 return '%s %s' % (str(signature), str(tempsignature))
439
440 def sparsematch(self, *revs, **kwargs):
407 def sparsematch(self, *revs, **kwargs):
441 """Returns the sparse match function for the given revs.
408 """Returns the sparse match function for the given revs.
442
409
@@ -451,7 +418,7 b' def _wraprepo(ui, repo):'
451 self.dirstate.parents() if node != nullid]
418 self.dirstate.parents() if node != nullid]
452
419
453 includetemp = kwargs.get('includetemp', True)
420 includetemp = kwargs.get('includetemp', True)
454 signature = self._sparsesignature(includetemp=includetemp)
421 signature = sparse.configsignature(self, includetemp=includetemp)
455
422
456 key = '%s %s' % (str(signature), ' '.join([str(r) for r in revs]))
423 key = '%s %s' % (str(signature), ' '.join([str(r) for r in revs]))
457
424
@@ -7,6 +7,8 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import hashlib
11
10 from .i18n import _
12 from .i18n import _
11 from .node import nullid
13 from .node import nullid
12 from . import (
14 from . import (
@@ -130,6 +132,42 b' def activeprofiles(repo):'
130 def invalidatesignaturecache(repo):
132 def invalidatesignaturecache(repo):
131 repo._sparsesignaturecache.clear()
133 repo._sparsesignaturecache.clear()
132
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):
140 """Obtain the signature string for the current sparse configuration.
141
142 This is used to construct a cache key for matchers.
143 """
144 cache = repo._sparsesignaturecache
145
146 signature = cache.get('signature')
147
148 if includetemp:
149 tempsignature = cache.get('tempsignature')
150 else:
151 tempsignature = 0
152
153 if signature is None or (includetemp and tempsignature is None):
154 signature = 0
155 try:
156 signature = _checksum(repo, 'sparse')
157 except (OSError, IOError):
158 pass
159 cache['signature'] = signature
160
161 tempsignature = 0
162 if includetemp:
163 try:
164 tempsignature = _checksum(repo, 'tempsparse')
165 except (OSError, IOError):
166 pass
167 cache['tempsignature'] = tempsignature
168
169 return '%s %s' % (str(signature), str(tempsignature))
170
133 def writeconfig(repo, includes, excludes, profiles):
171 def writeconfig(repo, includes, excludes, profiles):
134 """Write the sparse config file given a sparse configuration."""
172 """Write the sparse config file given a sparse configuration."""
135 with repo.vfs('sparse', 'wb') as fh:
173 with repo.vfs('sparse', 'wb') as fh:
General Comments 0
You need to be logged in to leave comments. Login now