comparison tests/artifacts/scripts/generate-churning-bundle.py @ 52470:83f87912c5e0

test-sparse-revlog: commit the repo content in a single in-mem transaction I don't like to use the internal API like that, but it make the whole generation twice faster on my machine and suitable for always run during tests. However it also mean the `--pure` version of the test will run this with the pure source code and be unbearably slow. However if another flavor generated the file, pure will be able to simply reuse it, so it seems fine.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 04 Dec 2024 05:29:28 +0100
parents 9feb175c028d
children 24c3b3dbab08
comparison
equal deleted inserted replaced
52469:9feb175c028d 52470:83f87912c5e0
12 # 12 #
13 # The repository update a single "large" file with many updates. One fixed part 13 # The repository update a single "large" file with many updates. One fixed part
14 # of the files always get updated while the rest of the lines get updated over 14 # of the files always get updated while the rest of the lines get updated over
15 # time. This update happens over many topological branches, some getting merged 15 # time. This update happens over many topological branches, some getting merged
16 # back. 16 # back.
17 #
18 # Running with `chg` in your path and `CHGHG` set is recommended for speed.
19 17
20 18
21 import hashlib 19 import hashlib
22 import os 20 import os
23 import shutil 21 import shutil
24 import subprocess 22 import subprocess
25 import sys 23 import sys
26 import tempfile 24 import tempfile
25
26 import mercurial.context
27 import mercurial.hg
28 import mercurial.ui
27 29
28 BUNDLE_NAME = 'big-file-churn.hg' 30 BUNDLE_NAME = 'big-file-churn.hg'
29 31
30 # constants for generating the repository 32 # constants for generating the repository
31 NB_CHANGESET = 5000 33 NB_CHANGESET = 5000
216 full_cmd.extend(args) 218 full_cmd.extend(args)
217 env['HGRCPATH'] = '' 219 env['HGRCPATH'] = ''
218 return subprocess.check_call(full_cmd, env=env) 220 return subprocess.check_call(full_cmd, env=env)
219 221
220 222
223 def write_repo(path):
224 """write repository content in memory"""
225 repo = mercurial.hg.repository(
226 mercurial.ui.ui.load(),
227 path=path.encode('utf-8'),
228 )
229 nodemap = {None: repo.nodeconstants.nullid}
230 with repo.lock(), repo.transaction(b'bundle-generation'):
231 for idx, (p1, p2) in GRAPH.items():
232 if sys.stdout.isatty():
233 print("generating commit #%d/%d" % (idx, NB_CHANGESET))
234
235 file_fn = lambda repo, memctx, path: mercurial.context.memfilectx(
236 repo,
237 memctx,
238 path,
239 data=b''.join(CONTENT.pop(idx)()),
240 )
241
242 mc = mercurial.context.memctx(
243 repo,
244 (nodemap[p1], nodemap[p2]),
245 b'commit #%d' % idx if idx else b'initial commit',
246 [FILENAME.encode('ascii')],
247 file_fn,
248 user=b"test",
249 date=(0, 0),
250 )
251 nodemap[idx] = repo.commitctx(mc)
252
253
221 def run(target): 254 def run(target):
222 tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-') 255 tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-')
223 try: 256 try:
224 os.chdir(tmpdir) 257 os.chdir(tmpdir)
225 hg('init') 258 hg(
226 for idx, (p1, p2) in GRAPH.items(): 259 'init',
227 if sys.stdout.isatty(): 260 '--config',
228 print("generating commit #%d/%d" % (idx, NB_CHANGESET)) 261 'format.maxchainlen=%d' % NB_CHANGESET,
229 if p1 is not None and p1 != idx - 1: 262 )
230 hg('update', "%d" % p1) 263 write_repo(tmpdir)
231 if p2 is not None:
232 hg('merge', "%d" % p2)
233 with open(FILENAME, 'wb') as f:
234 # pop the value to let it be garbage collection eventually.
235 for line in CONTENT.pop(idx)():
236 f.write(line)
237 if idx == 0:
238 hg('add', FILENAME)
239 hg('commit', '--addremove', '--message', 'initial commit')
240 else:
241 hg('commit', '--message', 'commit #%d' % idx)
242 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') 264 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1')
243 with open(target, 'rb') as bundle: 265 with open(target, 'rb') as bundle:
244 data = bundle.read() 266 data = bundle.read()
245 digest = hashlib.md5(data).hexdigest() 267 digest = hashlib.md5(data).hexdigest()
246 with open(target + '.md5', 'wb') as md5file: 268 with open(target + '.md5', 'wb') as md5file: