128 return profiles |
130 return profiles |
129 |
131 |
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: |
136 for p in sorted(profiles): |
174 for p in sorted(profiles): |
137 fh.write('%%include %s\n' % p) |
175 fh.write('%%include %s\n' % p) |