Show More
@@ -14,6 +14,10 | |||||
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 | # --lazy will skip generating the file if one exist with the right content | |||
|
19 | # already. | |||
|
20 | # --validate make sure the generated bundle has the expected content. | |||
17 |
|
21 | |||
18 |
|
22 | |||
19 | import hashlib |
|
23 | import hashlib | |
@@ -251,7 +255,33 def write_repo(path): | |||||
251 | nodemap[idx] = repo.commitctx(mc) |
|
255 | nodemap[idx] = repo.commitctx(mc) | |
252 |
|
256 | |||
253 |
|
257 | |||
254 |
def |
|
258 | def compute_md5(target): | |
|
259 | with open(target, 'rb') as bundle: | |||
|
260 | data = bundle.read() | |||
|
261 | return hashlib.md5(data).hexdigest() | |||
|
262 | ||||
|
263 | ||||
|
264 | def write_md5(target, md5): | |||
|
265 | with open(target + '.md5', 'wb') as md5file: | |||
|
266 | md5file.write(md5.encode('ascii') + b'\n') | |||
|
267 | ||||
|
268 | ||||
|
269 | def read_md5(target): | |||
|
270 | with open(target + '.md5', 'rb') as md5file: | |||
|
271 | return md5file.read().strip().decode('ascii') | |||
|
272 | ||||
|
273 | ||||
|
274 | def up_to_date_target(target): | |||
|
275 | """return true if the file already exist at the right""" | |||
|
276 | try: | |||
|
277 | found = compute_md5(target) | |||
|
278 | expected = read_md5(target) | |||
|
279 | except OSError: | |||
|
280 | return False | |||
|
281 | return found == expected | |||
|
282 | ||||
|
283 | ||||
|
284 | def run(target, validate=False): | |||
255 | tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-') |
|
285 | tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-') | |
256 | try: |
|
286 | try: | |
257 | os.chdir(tmpdir) |
|
287 | os.chdir(tmpdir) | |
@@ -262,14 +292,17 def run(target): | |||||
262 | ) |
|
292 | ) | |
263 | write_repo(tmpdir) |
|
293 | write_repo(tmpdir) | |
264 | hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') |
|
294 | hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') | |
265 | with open(target, 'rb') as bundle: |
|
295 | digest = compute_md5(target) | |
266 | data = bundle.read() |
|
296 | if not validate: | |
267 | digest = hashlib.md5(data).hexdigest() |
|
297 | write_md5(target, digest) | |
268 | with open(target + '.md5', 'wb') as md5file: |
|
298 | else: | |
269 | md5file.write(digest.encode('ascii') + b'\n') |
|
299 | expected = read_md5(target) | |
270 | if sys.stdout.isatty(): |
|
300 | if expected != digest: | |
271 | print('bundle generated at "%s" md5: %s' % (target, digest)) |
|
301 | msg = "bundle generated does not match the expected content\n" | |
272 |
|
302 | msg += " expected: %s\n" % expected | ||
|
303 | msg += " got: %s" % digest | |||
|
304 | print(msg, file=sys.stderr) | |||
|
305 | return 1 | |||
273 | finally: |
|
306 | finally: | |
274 | shutil.rmtree(tmpdir) |
|
307 | shutil.rmtree(tmpdir) | |
275 | return 0 |
|
308 | return 0 | |
@@ -278,4 +311,8 def run(target): | |||||
278 | if __name__ == '__main__': |
|
311 | if __name__ == '__main__': | |
279 | orig = os.path.realpath(os.path.dirname(sys.argv[0])) |
|
312 | orig = os.path.realpath(os.path.dirname(sys.argv[0])) | |
280 | target = os.path.join(orig, os.pardir, 'cache', BUNDLE_NAME) |
|
313 | target = os.path.join(orig, os.pardir, 'cache', BUNDLE_NAME) | |
281 | sys.exit(run(target)) |
|
314 | lazy = '--lazy' in sys.argv[1:] | |
|
315 | validate = '--validate' in sys.argv[1:] | |||
|
316 | if lazy and up_to_date_target(target): | |||
|
317 | sys.exit(0) | |||
|
318 | sys.exit(run(target, validate=validate)) |
@@ -11,28 +11,32 repeatedly while some of it changes rare | |||||
11 |
|
11 | |||
12 | $ bundlepath="$TESTDIR/artifacts/cache/big-file-churn.hg" |
|
12 | $ bundlepath="$TESTDIR/artifacts/cache/big-file-churn.hg" | |
13 |
|
13 | |||
|
14 | #if pure | |||
14 | $ expectedhash=`cat "$bundlepath".md5` |
|
15 | $ expectedhash=`cat "$bundlepath".md5` | |
15 |
|
||||
16 | #if slow |
|
|||
17 |
|
||||
18 | $ if [ ! -f "$bundlepath" ]; then |
|
|||
19 | > "$TESTDIR"/artifacts/scripts/generate-churning-bundle.py > /dev/null |
|
|||
20 | > fi |
|
|||
21 |
|
||||
22 | #else |
|
|||
23 |
|
||||
24 |
$ |
|
16 | $ if [ ! -f "$bundlepath" ]; then | |
25 |
> echo |
|
17 | > echo 'skipped: missing artifact, run "'"$TESTDIR"'/artifacts/scripts/generate-churning-bundle.py"' | |
26 |
> exit |
|
18 | > exit 80 | |
27 | > fi |
|
19 | > fi | |
28 |
|
||||
29 | #endif |
|
|||
30 |
|
||||
31 |
$ currenthash=`f -M |
|
20 | $ currenthash=`f -M "$bundlepath" | cut -d = -f 2` | |
32 | $ if [ "$currenthash" != "$expectedhash" ]; then |
|
21 | $ if [ "$currenthash" != "$expectedhash" ]; then | |
33 | > echo 'skipped: outdated artifact, md5 "'"$currenthash"'" expected "'"$expectedhash"'" run "'"$TESTDIR"'/artifacts/scripts/generate-churning-bundle.py"' |
|
22 | > echo 'skipped: outdated artifact, md5 "'"$currenthash"'" expected "'"$expectedhash"'" run "'"$TESTDIR"'/artifacts/scripts/generate-churning-bundle.py"' | |
34 | > exit 80 |
|
23 | > exit 80 | |
35 | > fi |
|
24 | > fi | |
|
25 | #else | |||
|
26 | ||||
|
27 | #if slow | |||
|
28 | $ LAZY_GEN="" | |||
|
29 | ||||
|
30 | #else | |||
|
31 | $ LAZY_GEN="--lazy" | |||
|
32 | #endif | |||
|
33 | ||||
|
34 | #endif | |||
|
35 | ||||
|
36 | If the validation fails, either something is broken or the expected md5 need updating. | |||
|
37 | To update the md5, invoke the script without --validate | |||
|
38 | ||||
|
39 | $ "$TESTDIR"/artifacts/scripts/generate-churning-bundle.py --validate $LAZY_GEN > /dev/null | |||
36 |
|
40 | |||
37 | $ cat >> $HGRCPATH << EOF |
|
41 | $ cat >> $HGRCPATH << EOF | |
38 | > [format] |
|
42 | > [format] |
General Comments 0
You need to be logged in to leave comments.
Login now