comparison mercurial/sparse.py @ 33317:df1287268cc0

sparse: move config signature logic into core This is a pretty straightforward port. It will be cleaned up in a subsequent commit.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 06 Jul 2017 16:11:56 -0700
parents 3e1accab7447
children 526255fe7899
comparison
equal deleted inserted replaced
33316:310f7bcab50b 33317:df1287268cc0
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from __future__ import absolute_import 8 from __future__ import absolute_import
9
10 import hashlib
9 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 (
13 error, 15 error,
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)