##// END OF EJS Templates
persistent-nodemap: add a way to make the picked uid predictable...
marmoute -
r48091:9a3aa547 default
parent child Browse files
Show More
@@ -10,13 +10,16 b' from __future__ import absolute_import'
10
10
11 import errno
11 import errno
12 import os
12 import os
13 import random
13 import re
14 import re
14 import struct
15 import struct
15
16
16 from ..node import hex
17 from ..node import hex
17
18
18 from .. import (
19 from .. import (
20 encoding,
19 error,
21 error,
22 pycompat,
20 util,
23 util,
21 )
24 )
22
25
@@ -288,6 +291,45 b' def _make_uid():'
288 return hex(os.urandom(ID_SIZE))
291 return hex(os.urandom(ID_SIZE))
289
292
290
293
294 # some special test logic to avoid anoying random output in the test
295 stable_docket_file = encoding.environ.get(b'HGTEST_DOCKETIDFILE')
296
297 if stable_docket_file:
298
299 def _make_uid():
300 try:
301 with open(stable_docket_file, mode='rb') as f:
302 seed = f.read().strip()
303 except IOError as inst:
304 if inst.errno != errno.ENOENT:
305 raise
306 seed = b'4' # chosen by a fair dice roll. garanteed to be random
307 if pycompat.ispy3:
308 iter_seed = iter(seed)
309 else:
310 iter_seed = (ord(c) for c in seed)
311 # some basic circular sum hashing on 64 bits
312 int_seed = 0
313 low_mask = int('1' * 35, 2)
314 for i in iter_seed:
315 high_part = int_seed >> 35
316 low_part = (int_seed & low_mask) << 28
317 int_seed = high_part + low_part + i
318 r = random.Random()
319 if pycompat.ispy3:
320 r.seed(int_seed, version=1)
321 else:
322 r.seed(int_seed)
323 # once we drop python 3.8 support we can simply use r.randbytes
324 raw = r.getrandbits(ID_SIZE * 8)
325 assert ID_SIZE == 8
326 p = struct.pack('>Q', raw)
327 new = hex(p)
328 with open(stable_docket_file, 'wb') as f:
329 f.write(new)
330 return new
331
332
291 class NodeMapDocket(object):
333 class NodeMapDocket(object):
292 """metadata associated with persistent nodemap data
334 """metadata associated with persistent nodemap data
293
335
@@ -1386,6 +1386,8 b' class Test(unittest.TestCase):'
1386 env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or ''
1386 env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or ''
1387 env['HGEMITWARNINGS'] = '1'
1387 env['HGEMITWARNINGS'] = '1'
1388 env['TESTTMP'] = _bytes2sys(self._testtmp)
1388 env['TESTTMP'] = _bytes2sys(self._testtmp)
1389 docket_id_file = os.path.join(_bytes2sys(self._testtmp), 'DOCKETID')
1390 env['HGTEST_DOCKETIDFILE'] = docket_id_file
1389 env['TESTNAME'] = self.name
1391 env['TESTNAME'] = self.name
1390 env['HOME'] = _bytes2sys(self._testtmp)
1392 env['HOME'] = _bytes2sys(self._testtmp)
1391 if os.name == 'nt':
1393 if os.name == 'nt':
General Comments 0
You need to be logged in to leave comments. Login now